-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
- Loading branch information
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Large diffs are not rendered by default.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
namespace UniSkin | ||
{ | ||
internal enum BackgroundType | ||
{ | ||
Texture, | ||
Color | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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; | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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; | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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()); | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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()); | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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); | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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()); | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.