Skip to content

Commit

Permalink
Minor cosmetic update
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanMurzak committed Jul 29, 2024
1 parent fa3102a commit fe1518c
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 46 deletions.
51 changes: 51 additions & 0 deletions Assets/_PackageRoot/Scripts/Binders/BaseColorBinder.Validate.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
using UnityEngine;

namespace Unity.Theme.Binders
{
public abstract partial class BaseColorBinder : MonoBehaviour
{
protected virtual void OnValidate()
{
if (string.IsNullOrEmpty(data.colorGuid))
{
if (Theme.Instance?.debugLevel <= DebugLevel.Error)
Debug.LogError($"Color GUID is <b><color=red>null</color></b> at <b>{GameObjectPath()}</b>", gameObject);
return;
}
if (!data.IsConnected)
{
if (Theme.Instance?.debugLevel <= DebugLevel.Error)
Debug.LogError($"Color with GUID='{data.colorGuid}' not found in database at <b>{GameObjectPath()}</b>", gameObject);
return;
}
#if UNITY_EDITOR
TrySetColor(Theme.Instance.CurrentTheme);
#endif
}

// UTILS ---------------------------------------------------------------------------//
protected string GameObjectPath() => GameObjectPath(transform); //
protected static string GameObjectPath(Transform trans, string path = "") //
{ //
if (string.IsNullOrEmpty(path)) //
path = trans.name; //
else //
path = $"{trans.name}/{path}"; //
//
if (trans.parent == null) //
{ //
var isPrefab = string.IsNullOrEmpty(trans.gameObject.scene.name); //
if (isPrefab) //
path = $"<color=cyan>Prefabs</color>/{path}"; //
else //
path = $"<color=cyan>{trans.gameObject.scene.name}</color>/{path}"; //
return path; //
} //
else //
{ //
return GameObjectPath(trans.parent, path); //
} //
} //
// =================================================================================//
}
}

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

45 changes: 1 addition & 44 deletions Assets/_PackageRoot/Scripts/Binders/BaseColorBinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ protected virtual void Awake()
if (!data.IsConnected)
{
if (Theme.Instance?.debugLevel <= DebugLevel.Error)
Debug.LogError($"Color not found in database at <b>{GameObjectPath()}</b> Guid={data.colorGuid}", gameObject);
Debug.LogError($"Color with GUID='{data.colorGuid}' not found in database at <b>{GameObjectPath()}</b>", gameObject);
}
}
protected virtual void Start()
Expand Down Expand Up @@ -89,24 +89,6 @@ protected virtual Color GetTargetColor(ColorData colorData)
protected abstract void SetColor(Color color);
protected abstract Color? GetColor();

protected virtual void OnValidate()
{
if (string.IsNullOrEmpty(data.colorGuid))
{
if (Theme.Instance?.debugLevel <= DebugLevel.Error)
Debug.LogError($"Color GUID is <b><color=red>null</color></b> at <b>{GameObjectPath()}</b>", gameObject);
return;
}
if (!data.IsConnected)
{
if (Theme.Instance?.debugLevel <= DebugLevel.Error)
Debug.LogError($"Color with GUID='{data.colorGuid}' not found in database at <b>{GameObjectPath()}</b>", gameObject);
return;
}
#if UNITY_EDITOR
TrySetColor(Theme.Instance.CurrentTheme);
#endif
}
private void SetDirty(Object obj)
{
#if UNITY_EDITOR
Expand All @@ -115,30 +97,5 @@ private void SetDirty(Object obj)
#endif
}
private void OnThemeColorChanged(ThemeData themeData, ColorData colorData) => TrySetColor(Theme.Instance.CurrentTheme);

// UTILS ---------------------------------------------------------------------------//
protected string GameObjectPath() => GameObjectPath(transform); //
protected static string GameObjectPath(Transform trans, string path = "") //
{ //
if (string.IsNullOrEmpty(path)) //
path = trans.name; //
else //
path = $"{trans.name}/{path}"; //
//
if (trans.parent == null) //
{ //
var isPrefab = string.IsNullOrEmpty(trans.gameObject.scene.name); //
if (isPrefab) //
path = $"<color=cyan>Prefabs</color>/{path}"; //
else //
path = $"<color=cyan>{trans.gameObject.scene.name}</color>/{path}"; //
return path; //
} //
else //
{ //
return GameObjectPath(trans.parent, path); //
} //
} //
// =================================================================================//
}
}
2 changes: 1 addition & 1 deletion Assets/_PackageRoot/Scripts/Config/Theme.Singleton.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public static Theme Instance
instance ??= GetOrCreateInstance();

if (instance == null)
Debug.LogError("Theme instance is null");
Debug.LogWarning("Theme instance is null");

return instance;
}
Expand Down
2 changes: 1 addition & 1 deletion Assets/_PackageRoot/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"name": "Ivan Murzak",
"url": "https://github.com/IvanMurzak"
},
"version": "2.1.5",
"version": "2.1.6",
"unity": "2019.2",
"description": "Create palettes of colors and components for change specific color on a specific visual element. Very useful to UI.",
"keywords": [
Expand Down

0 comments on commit fe1518c

Please sign in to comment.