Skip to content

Commit

Permalink
Merge pull request #16 from VirtueSky/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
VirtueSky authored Sep 5, 2024
2 parents 6b38e3c + 0d3e35f commit 0650592
Show file tree
Hide file tree
Showing 16 changed files with 669 additions and 5 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
### 1: Download the repo and drop it into folder `Assets`
### 2: Add the line below to `Packages/manifest.json`

for version `3.0.0`
for version `3.0.1`
```csharp
"com.virtuesky.sunflower":"https://github.com/VirtueSky/sunflower.git#3.0.0",
"com.virtuesky.sunflower":"https://github.com/VirtueSky/sunflower.git#3.0.1",
```

## Includes modules
Expand Down
2 changes: 1 addition & 1 deletion VirtueSky/ControlPanel/ConstantPackage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{
public class ConstantPackage
{
public const string VersionSunflower = "3.0.0";
public const string VersionSunflower = "3.0.1";
public const string PackageNameInAppPurchase = "com.unity.purchasing";
public const string MaxVersionInAppPurchase = "4.12.2";
public const string PackageNameNewtonsoftJson = "com.unity.nuget.newtonsoft-json";
Expand Down
3 changes: 2 additions & 1 deletion VirtueSky/Hierarchy/Editor/HierarchyEditor.asmdef
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"Virtuesky.Sunflower.DataStorage.Editor",
"VirtueSky.Sunflower.Inspector",
"HierarchyNullable",
"HierarchyRuntime"
"HierarchyRuntime",
"Virtuesky.Sunflower.UtilsEdtitor"
],
"includePlatforms": [
"Editor"
Expand Down
8 changes: 8 additions & 0 deletions VirtueSky/Hierarchy/FolderHierarchy.meta

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

36 changes: 36 additions & 0 deletions VirtueSky/Hierarchy/FolderHierarchy/HeaderHierarchy.cs
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 VirtueSky/Hierarchy/FolderHierarchy/HeaderHierarchy.cs.meta

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

142 changes: 142 additions & 0 deletions VirtueSky/Hierarchy/FolderHierarchy/HeaderHierarchyIcon.cs
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 VirtueSky/Hierarchy/FolderHierarchy/HeaderHierarchyIcon.cs.meta

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

17 changes: 17 additions & 0 deletions VirtueSky/Hierarchy/FolderHierarchy/HierarchyHeader.asmdef
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
}

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

Loading

0 comments on commit 0650592

Please sign in to comment.