Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
piti6 committed Feb 18, 2021
0 parents commit 6858891
Show file tree
Hide file tree
Showing 86 changed files with 2,353 additions and 0 deletions.
8 changes: 8 additions & 0 deletions Sample.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Sample/Sample.skn

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions Sample/Sample.skn.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file added Sample/UCL2_0.zip
Binary file not shown.
7 changes: 7 additions & 0 deletions Sample/UCL2_0.zip.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Scripts.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Scripts/InternalBridge.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Scripts/InternalBridge/Data.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Scripts/InternalBridge/Data/BackgroundType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace UniSkin
{
internal enum BackgroundType
{
Texture,
Color
}
}
11 changes: 11 additions & 0 deletions Scripts/InternalBridge/Data/BackgroundType.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

51 changes: 51 additions & 0 deletions Scripts/InternalBridge/Data/CachedSkin.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
using UnityEditor;
using UnityEngine;

namespace UniSkin
{
[FilePath("cachedSkin", FilePathAttribute.Location.PreferencesFolder)]
internal class CachedSkin : ScriptableSingleton<CachedSkin>
{
public static Skin Skin
{
get
{
if (instance._skin is null)
{
Update(Skin.Default);
Save();
}

return instance._skin;
}
}

[SerializeField]
private Skin _skin;

private static bool _dirty = false;

public static bool Update(Skin skin)
{
if (instance._skin == skin)
{
return false;
}
else
{
instance._skin = skin;
_dirty = true;

return true;
}
}

public static void Save()
{
if (!_dirty) return;

instance.Save(saveAsText: true);
_dirty = false;
}
}
}
11 changes: 11 additions & 0 deletions Scripts/InternalBridge/Data/CachedSkin.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 35 additions & 0 deletions Scripts/InternalBridge/Data/ElementStyle.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;

namespace UniSkin
{
[Serializable]
internal class ElementStyle
{
public string Name => _name;
public int FontSize => _fontSize;
public FontStyle FontStyle => _fontStyle;
public IReadOnlyDictionary<StyleStateType, StyleState> StyleStates => _styleStateDictionary ?? (_styleStateDictionary = _styleStates.ToDictionary(x => x.StateType));

private IReadOnlyDictionary<StyleStateType, StyleState> _styleStateDictionary;

[SerializeField]
private string _name;
[SerializeField]
private int _fontSize;
[SerializeField]
private FontStyle _fontStyle;
[SerializeField]
private StyleState[] _styleStates;

public ElementStyle(string name, int fontSize, FontStyle fontStyle, StyleState[] styleStates)
{
_name = name;
_fontSize = fontSize;
_fontStyle = fontStyle;
_styleStates = styleStates;
}
}
}
11 changes: 11 additions & 0 deletions Scripts/InternalBridge/Data/ElementStyle.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Scripts/InternalBridge/Data/Mutable.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 35 additions & 0 deletions Scripts/InternalBridge/Data/Mutable/MutableElementStyle.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using System.Collections.Generic;
using System.Linq;
using UnityEngine;

namespace UniSkin
{
internal class MutableElementStyle
{
public string Name { get; set; }
public int FontSize { get; set; }
public FontStyle FontStyle { get; set; }
public Dictionary<StyleStateType, MutableStyleState> StyleStates { get; set; }

public MutableElementStyle()
{
StyleStates = new Dictionary<StyleStateType, MutableStyleState>();
}

public MutableElementStyle(ElementStyle elementStyle) : this(elementStyle.Name, elementStyle.FontSize, elementStyle.FontStyle, elementStyle.StyleStates.Values.ToArray())
{ }

public MutableElementStyle(string name, int fontSize, FontStyle fontStyle, StyleState[] styleStates)
{
Name = name;
FontSize = fontSize;
FontStyle = fontStyle;
StyleStates = styleStates.ToDictionary(x => x.StateType, x => new MutableStyleState(x));
}

public ElementStyle ToImmutable()
{
return new ElementStyle(Name, FontSize, FontStyle, StyleStates.Values.Select(x => x.ToImmutable()).ToArray());
}
}
}
11 changes: 11 additions & 0 deletions Scripts/InternalBridge/Data/Mutable/MutableElementStyle.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

56 changes: 56 additions & 0 deletions Scripts/InternalBridge/Data/Mutable/MutableSkin.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
using System.Collections.Generic;
using System.Linq;

namespace UniSkin
{
internal class MutableSkin
{
public string Id { get; }
public string Name { get; set; }
public Dictionary<string, SerializableTexture2D> Textures { get; set; }
public Dictionary<string, MutableWindowStyle> WindowStyles { get; set; }

public MutableSkin(Skin skin) : this(skin.Id, skin.Name, skin.Textures.Values.ToArray(), skin.WindowStyles.Values.ToArray())
{ }

public MutableSkin(string id, string name, SerializableTexture2D[] textures, WindowStyle[] windowStyles)
{
Id = id;
Name = name;
Textures = textures.ToDictionary(x => x.Id);
WindowStyles = windowStyles.ToDictionary(x => x.Name, x => new MutableWindowStyle(x));
}

public override bool Equals(object obj)
{
return obj is MutableSkin skin &&
Name == skin.Name &&
Textures.SequenceEqual(skin.Textures) &&
WindowStyles.SequenceEqual(skin.WindowStyles);
}

public override int GetHashCode()
{
int hashCode = -624386006;
hashCode = hashCode * -1521134295 + EqualityComparer<string>.Default.GetHashCode(Name);
hashCode = hashCode * -1521134295 + EqualityComparer<Dictionary<string, SerializableTexture2D>>.Default.GetHashCode(Textures);
hashCode = hashCode * -1521134295 + EqualityComparer<Dictionary<string, MutableWindowStyle>>.Default.GetHashCode(WindowStyles);
return hashCode;
}

public static bool operator ==(MutableSkin left, MutableSkin right)
{
return left.Equals(right);
}

public static bool operator !=(MutableSkin left, MutableSkin right)
{
return !(left == right);
}

public Skin ToImmutable(bool grantNewId)
{
return new Skin(grantNewId ? System.Guid.NewGuid().ToString() : Id, Name, Textures.Values.ToArray(), WindowStyles.Values.Select(x => x.ToImmutable()).ToArray());
}
}
}
11 changes: 11 additions & 0 deletions Scripts/InternalBridge/Data/Mutable/MutableSkin.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 30 additions & 0 deletions Scripts/InternalBridge/Data/Mutable/MutableStyleState.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using UnityEngine;

namespace UniSkin
{
internal class MutableStyleState
{
public StyleStateType StateType { get; }
public BackgroundType BackgroundType { get; set; }
public string BackgroundTextureId { get; set; }
public Color BackgroundColor { get; set; }
public Color TextColor { get; set; }

public MutableStyleState(StyleState styleState) : this(styleState.StateType, styleState.BackgroundType, styleState.BackgroundTextureId, styleState.BackgroundColor, styleState.TextColor)
{ }

public MutableStyleState(StyleStateType stateType, BackgroundType backgroundType, string backgroundTextureId, Color backgroundColor, Color textColor)
{
StateType = stateType;
BackgroundType = backgroundType;
BackgroundTextureId = backgroundTextureId;
BackgroundColor = backgroundColor;
TextColor = textColor;
}

public StyleState ToImmutable()
{
return new StyleState(StateType, BackgroundType, BackgroundTextureId, BackgroundColor, TextColor);
}
}
}
11 changes: 11 additions & 0 deletions Scripts/InternalBridge/Data/Mutable/MutableStyleState.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 29 additions & 0 deletions Scripts/InternalBridge/Data/Mutable/MutableWindowStyle.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using System.Collections.Generic;
using System.Linq;

namespace UniSkin
{
internal class MutableWindowStyle
{
public string Name { get; set; }
public string CustomBackgroundId { get; set; }
public string CustomBackgroundId2 { get; set; }
public Dictionary<string, MutableElementStyle> ElementStyles { get; set; }

public MutableWindowStyle(WindowStyle windowStyle) : this(windowStyle.Name, windowStyle.CustomBackgroundTextureId, windowStyle.CustomBackgroundTextureId2, windowStyle.ElementStyles.Values.ToArray())
{ }

public MutableWindowStyle(string name, string customBackgroundId, string customBackgroundId2, ElementStyle[] elementStyles)
{
Name = name;
CustomBackgroundId = customBackgroundId;
CustomBackgroundId2 = customBackgroundId2;
ElementStyles = elementStyles.ToDictionary(x => x.Name, x => new MutableElementStyle(x));
}

public WindowStyle ToImmutable()
{
return new WindowStyle(Name, CustomBackgroundId, CustomBackgroundId2, ElementStyles.Values.Select(x => x.ToImmutable()).ToArray());
}
}
}
11 changes: 11 additions & 0 deletions Scripts/InternalBridge/Data/Mutable/MutableWindowStyle.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 6858891

Please sign in to comment.