-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from VirtueSky/dev
Dev
- Loading branch information
Showing
16 changed files
with
669 additions
and
5 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
using UnityEngine; | ||
using VirtueSky.Inspector; | ||
|
||
namespace VirtueSky.Hierarchy | ||
{ | ||
[ExecuteInEditMode] | ||
[EditorIcon("icon_hierarchy"), HideMonoScript] | ||
public class HeaderHierarchy : MonoBehaviour | ||
{ | ||
#region Variables | ||
|
||
public enum TextAlignment | ||
{ | ||
Left, | ||
Center | ||
} | ||
|
||
[TitleColor("Text", CustomColor.Gold, CustomColor.Aqua)] [SerializeField] | ||
public bool customText; | ||
|
||
[ShowIf(nameof(customText)), SerializeField] | ||
public Color32 textColor = InspectorUtility.textNormalColor; | ||
|
||
[Space] [SerializeField] public FontStyle textStyle = FontStyle.BoldAndItalic; | ||
|
||
[SerializeField] public TextAlignment textAlignment = TextAlignment.Left; | ||
|
||
[TitleColor("Highlight", CustomColor.Coral, CustomColor.Lime)] [Space, SerializeField] | ||
public bool customHighlight; | ||
|
||
[ShowIf(nameof(customHighlight)), SerializeField] | ||
public Color32 highlightColor = InspectorUtility.cyanColor; | ||
|
||
#endregion | ||
} // class end | ||
} |
11 changes: 11 additions & 0 deletions
11
VirtueSky/Hierarchy/FolderHierarchy/HeaderHierarchy.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
142 changes: 142 additions & 0 deletions
142
VirtueSky/Hierarchy/FolderHierarchy/HeaderHierarchyIcon.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,142 @@ | ||
#if UNITY_EDITOR | ||
using System.Linq; | ||
using UnityEditor; | ||
using UnityEngine; | ||
using VirtueSky.UtilsEditor; | ||
|
||
namespace VirtueSky.Hierarchy | ||
{ | ||
[InitializeOnLoad] | ||
public class HeaderHierarchyIcon | ||
{ | ||
#region Static Variables | ||
|
||
// icons | ||
private static string assetPath = "/VirtueSky/Hierarchy/Icons"; | ||
private static Texture2D icon_HierarchyHighlight; | ||
|
||
#endregion | ||
|
||
//---------------------------------------------------------------------------------------------------- | ||
|
||
#region Contructors | ||
|
||
static HeaderHierarchyIcon() | ||
{ | ||
// subscribe to inspector updates | ||
EditorApplication.hierarchyWindowItemOnGUI += EditorApplication_hierarchyWindowItemOnGUI; | ||
} | ||
|
||
#endregion | ||
|
||
//---------------------------------------------------------------------------------------------------- | ||
|
||
#region Private Functions | ||
|
||
private static void CreateHierarchyIcon_Highlight() | ||
{ | ||
icon_HierarchyHighlight = FileExtension.FindAssetWithPath<Texture2D>("HierarchyHighlight.png", assetPath); | ||
} | ||
|
||
private static void EditorApplication_hierarchyWindowItemOnGUI(int instanceID, Rect position) | ||
{ | ||
// check for valid draw | ||
if (Event.current.type != EventType.Repaint) | ||
{ | ||
return; | ||
} | ||
|
||
GameObject gameObject = EditorUtility.InstanceIDToObject(instanceID) as GameObject; | ||
if (gameObject != null) | ||
{ | ||
HeaderHierarchy component = gameObject.GetComponent<HeaderHierarchy>(); | ||
if (component != null) | ||
{ | ||
// cache values | ||
int hierarchyPixelHeight = 16; | ||
bool isSelected = Selection.instanceIDs.Contains(instanceID); | ||
bool isActive = component.isActiveAndEnabled; | ||
Color32 defaultContentColor = GUI.contentColor; | ||
Color32 textColor; | ||
Color32 backgroundColor; | ||
|
||
if (isActive || isSelected) | ||
{ | ||
// text | ||
if (component.customText) | ||
{ | ||
textColor = component.textColor; | ||
} | ||
else | ||
{ | ||
textColor = InspectorUtility.textNormalColor; | ||
} | ||
} | ||
else | ||
{ | ||
// text | ||
if (component.customText) | ||
{ | ||
textColor = (Color)component.textColor * 0.6f; | ||
} | ||
else | ||
{ | ||
textColor = InspectorUtility.textDisabledColor; | ||
} | ||
} | ||
|
||
// draw background | ||
if (isSelected) | ||
{ | ||
backgroundColor = InspectorUtility.backgroundActiveColor; | ||
} | ||
else | ||
{ | ||
backgroundColor = InspectorUtility.backgroundNormalColorLight; | ||
} | ||
|
||
Rect backgroundPosition = new Rect(position.xMin, position.yMin, position.width + hierarchyPixelHeight, position.height); | ||
EditorGUI.DrawRect(backgroundPosition, backgroundColor); | ||
|
||
// check icon exists | ||
if (!icon_HierarchyHighlight) | ||
{ | ||
CreateHierarchyIcon_Highlight(); | ||
} | ||
|
||
// draw highlight | ||
if (component.customHighlight) | ||
{ | ||
GUI.contentColor = component.highlightColor; | ||
Rect iconPosition = new Rect(position.xMin, position.yMin, icon_HierarchyHighlight.width, icon_HierarchyHighlight.height); | ||
GUIContent iconGUIContent = new GUIContent(icon_HierarchyHighlight); | ||
EditorGUI.LabelField(iconPosition, iconGUIContent); | ||
GUI.contentColor = defaultContentColor; | ||
} | ||
|
||
// draw text | ||
GUIStyle hierarchyText = new GUIStyle() { }; | ||
hierarchyText.normal = new GUIStyleState() { textColor = textColor }; | ||
hierarchyText.fontStyle = component.textStyle; | ||
int offsetX; | ||
if (component.textAlignment == HeaderHierarchy.TextAlignment.Center) | ||
{ | ||
hierarchyText.alignment = TextAnchor.MiddleCenter; | ||
offsetX = 0; | ||
} | ||
else | ||
{ | ||
hierarchyText.alignment = TextAnchor.MiddleLeft; | ||
offsetX = hierarchyPixelHeight + 2; | ||
} | ||
|
||
Rect textOffset = new Rect(position.xMin + offsetX, position.yMin, position.width, position.height); | ||
EditorGUI.LabelField(textOffset, component.name, hierarchyText); | ||
} | ||
} | ||
} | ||
|
||
#endregion | ||
} // class end | ||
} | ||
#endif |
11 changes: 11 additions & 0 deletions
11
VirtueSky/Hierarchy/FolderHierarchy/HeaderHierarchyIcon.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
17 changes: 17 additions & 0 deletions
17
VirtueSky/Hierarchy/FolderHierarchy/HierarchyHeader.asmdef
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,17 @@ | ||
{ | ||
"name": "HierarchyHeader", | ||
"rootNamespace": "", | ||
"references": [ | ||
"GUID:324caed91501a9c47a04ebfd87b68794", | ||
"GUID:c904f6d969e991d459a0843b71c22ec5" | ||
], | ||
"includePlatforms": [], | ||
"excludePlatforms": [], | ||
"allowUnsafeCode": false, | ||
"overrideReferences": false, | ||
"precompiledReferences": [], | ||
"autoReferenced": true, | ||
"defineConstraints": [], | ||
"versionDefines": [], | ||
"noEngineReferences": false | ||
} |
7 changes: 7 additions & 0 deletions
7
VirtueSky/Hierarchy/FolderHierarchy/HierarchyHeader.asmdef.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.