-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fa3102a
commit fe1518c
Showing
5 changed files
with
65 additions
and
46 deletions.
There are no files selected for viewing
51 changes: 51 additions & 0 deletions
51
Assets/_PackageRoot/Scripts/Binders/BaseColorBinder.Validate.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); // | ||
} // | ||
} // | ||
// =================================================================================// | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
Assets/_PackageRoot/Scripts/Binders/BaseColorBinder.Validate.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters