mirror of
https://github.com/DCFApixels/DragonECS-Unity.git
synced 2025-09-18 01:54:35 +08:00
update
This commit is contained in:
parent
1176853cd5
commit
8bba0a01f8
20
src/Editor/ColorUtility.cs
Normal file
20
src/Editor/ColorUtility.cs
Normal file
@ -0,0 +1,20 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace DCFApixels.DragonECS.Unity.Internal
|
||||
{
|
||||
internal static class ColorUtility
|
||||
{
|
||||
public static Color Desaturate(this Color self, float t)
|
||||
{
|
||||
float r = self.r;
|
||||
float g = self.g;
|
||||
float b = self.b;
|
||||
//float gray = r * 0.299f + g * 0.587f + b * 0.114f;
|
||||
float gray = r * 0.3333333f + g * 0.3333333f + b * 0.3333333f;
|
||||
r = r + (gray - r) * (1 - t);
|
||||
g = g + (gray - g) * (1 - t);
|
||||
b = b + (gray - b) * (1 - t);
|
||||
return new Color(r, g, b);
|
||||
}
|
||||
}
|
||||
}
|
11
src/Editor/ColorUtility.cs.meta
Normal file
11
src/Editor/ColorUtility.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: daa1178cae0d21643b233d22f2c3e867
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -1,4 +1,5 @@
|
||||
#if UNITY_EDITOR
|
||||
using Codice.Utils;
|
||||
using DCFApixels.DragonECS.Unity.Internal;
|
||||
using System;
|
||||
using System.Reflection;
|
||||
@ -105,8 +106,8 @@ namespace DCFApixels.DragonECS.Unity.Editors
|
||||
IsShowRuntimeComponents = EditorGUILayout.Foldout(IsShowRuntimeComponents, "RUNTIME COMPONENTS");
|
||||
if (IsShowRuntimeComponents)
|
||||
{
|
||||
//TODO галочкаслишком чернаяя, невидно
|
||||
IsShowHidden = EditorGUILayout.Toggle("Show Hidden", IsShowHiddens);
|
||||
GUILayout.Box("", EcsEditor.GetStyle(GUI.color, 0.16f), GUILayout.ExpandWidth(true));
|
||||
IsShowHidden = EditorGUI.Toggle(GUILayoutUtility.GetLastRect(), "Show Hidden", IsShowHidden);
|
||||
foreach (var componentTypeID in componentTypeIDs)
|
||||
{
|
||||
var pool = world.GetPool(componentTypeID);
|
||||
@ -124,8 +125,8 @@ namespace DCFApixels.DragonECS.Unity.Editors
|
||||
if (meta.IsHidden == false || IsShowHidden)
|
||||
{
|
||||
object data = pool.GetRaw(entityID);
|
||||
Color panelColor = meta.Color.ToUnityColor();
|
||||
GUILayout.BeginVertical(EcsEditor.GetStyle(panelColor, 0.22f));
|
||||
Color panelColor = meta.Color.ToUnityColor().Desaturate(EscEditorConsts.COMPONENT_DRAWER_DESATURATE);
|
||||
GUILayout.BeginVertical(EcsEditor.GetStyle(panelColor, EscEditorConsts.COMPONENT_DRAWER_ALPHA));
|
||||
EditorGUI.BeginChangeCheck();
|
||||
|
||||
Type componentType = pool.ComponentType;
|
||||
@ -151,7 +152,8 @@ namespace DCFApixels.DragonECS.Unity.Editors
|
||||
|
||||
if (uobj == null && (type.IsGenericType || !type.IsSerializable))
|
||||
{
|
||||
isExpanded = EditorGUILayout.Foldout(isExpanded, label);
|
||||
isExpanded = EditorGUILayout.BeginFoldoutHeaderGroup(isExpanded, label, EditorStyles.foldout);
|
||||
EditorGUILayout.EndFoldoutHeaderGroup();
|
||||
|
||||
if (isExpanded)
|
||||
{
|
||||
|
14
src/Editor/EscEditorConsts.cs
Normal file
14
src/Editor/EscEditorConsts.cs
Normal file
@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DCFApixels.DragonECS.Unity.Editors
|
||||
{
|
||||
internal static class EscEditorConsts
|
||||
{
|
||||
public const float COMPONENT_DRAWER_ALPHA = 0.26f;
|
||||
public const float COMPONENT_DRAWER_DESATURATE = 0.86f;
|
||||
}
|
||||
}
|
11
src/Editor/EscEditorConsts.cs.meta
Normal file
11
src/Editor/EscEditorConsts.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b0bed74c1b3b07d44b9ea1ea917809e4
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -29,6 +29,14 @@ namespace DCFApixels.DragonECS.Unity.Internal
|
||||
return (l, r);
|
||||
}
|
||||
|
||||
public static (Rect, Rect) VerticalSliceTop(Rect rect, float height)
|
||||
{
|
||||
Rect t = rect;
|
||||
Rect b = rect;
|
||||
t.yMax = t.yMin + height;
|
||||
b.yMin += height;
|
||||
return (t, b);
|
||||
}
|
||||
public static (Rect, Rect) VerticalSliceBottom(Rect rect, float height)
|
||||
{
|
||||
Rect t = rect;
|
||||
@ -37,5 +45,19 @@ namespace DCFApixels.DragonECS.Unity.Internal
|
||||
b.yMin = b.yMax - height;
|
||||
return (t, b);
|
||||
}
|
||||
|
||||
public static Rect AddPadding(Rect rect, float verticalHorizontal)
|
||||
{
|
||||
return AddPadding(rect, verticalHorizontal, verticalHorizontal);
|
||||
}
|
||||
|
||||
public static Rect AddPadding(Rect rect, float vertical, float horizontal)
|
||||
{
|
||||
rect.xMax -= horizontal;
|
||||
rect.xMin += horizontal;
|
||||
rect.yMax -= vertical;
|
||||
rect.yMin += vertical;
|
||||
return rect;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -10,8 +10,8 @@ namespace DCFApixels.DragonECS.Unity.Editors
|
||||
|
||||
public abstract class EntityTemplateEditorBase : Editor
|
||||
{
|
||||
private static readonly Rect RemoveButtonRect = new Rect(0f, 0f, 15f, 15f);
|
||||
private static readonly Rect TooltipIconRect = new Rect(0f, 0f, 15f, 15f);
|
||||
private static readonly Rect RemoveButtonRect = new Rect(0f, 0f, 17f, 19f);
|
||||
private static readonly Rect TooltipIconRect = new Rect(0f, 0f, 21f, 15f);
|
||||
|
||||
private GUIStyle removeButtonStyle;
|
||||
private GenericMenu genericMenu;
|
||||
@ -96,14 +96,15 @@ namespace DCFApixels.DragonECS.Unity.Editors
|
||||
Init();
|
||||
SerializedProperty componentsProp = serializedObject.FindProperty(target.ComponentsPropertyName);
|
||||
if (componentsProp == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
DrawTop(target);
|
||||
GUILayout.BeginVertical(EcsEditor.GetStyle(Color.black, 0.2f));
|
||||
for (int i = 0; i < componentsProp.arraySize; i++)
|
||||
{
|
||||
DrawComponentData(componentsProp.GetArrayElementAtIndex(i), i);
|
||||
GUILayout.Space(EditorGUIUtility.standardVerticalSpacing * 2);
|
||||
}
|
||||
GUILayout.EndVertical();
|
||||
DrawFooter(target);
|
||||
@ -140,72 +141,70 @@ namespace DCFApixels.DragonECS.Unity.Editors
|
||||
return;
|
||||
}
|
||||
|
||||
Type initializerType;
|
||||
Type componentType;
|
||||
SerializedProperty componentProperty = componentRefProp;
|
||||
ComponentTemplateBase customInitializer = componentProperty.managedReferenceValue as ComponentTemplateBase;
|
||||
if (customInitializer != null)
|
||||
{
|
||||
componentProperty = componentRefProp.FindPropertyRelative("component");
|
||||
initializerType = customInitializer.Type;
|
||||
componentType = customInitializer.GetType().GetField("component", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic).FieldType;
|
||||
}
|
||||
else
|
||||
{
|
||||
initializerType = componentProperty.managedReferenceValue.GetType();
|
||||
componentType = initializerType;
|
||||
componentType = componentProperty.managedReferenceValue.GetType(); ;
|
||||
}
|
||||
|
||||
string name = template.Name;
|
||||
string description = template.Description;
|
||||
Color panelColor = template.Color;
|
||||
|
||||
GUILayout.BeginHorizontal();
|
||||
|
||||
GUILayout.BeginVertical(EcsEditor.GetStyle(panelColor, 0.22f));
|
||||
Color panelColor = template.Color.Desaturate(EscEditorConsts.COMPONENT_DRAWER_DESATURATE);
|
||||
|
||||
EditorGUI.BeginChangeCheck();
|
||||
|
||||
GUIContent label = new GUIContent(name);
|
||||
if (componentType.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic).Length <= 0)
|
||||
bool isEmpty = componentType.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic).Length <= 0;
|
||||
|
||||
float width = EditorGUIUtility.currentViewWidth;
|
||||
float height = isEmpty ? EditorGUIUtility.singleLineHeight : EditorGUI.GetPropertyHeight(componentProperty, label, true);
|
||||
float padding = EditorGUIUtility.standardVerticalSpacing;
|
||||
|
||||
Rect propertyFullRect = GUILayoutUtility.GetRect(width, height + padding * 3f);
|
||||
propertyFullRect = RectUtility.AddPadding(propertyFullRect, padding / 2f);
|
||||
Color alphaPanelColor = panelColor;
|
||||
alphaPanelColor.a = EscEditorConsts.COMPONENT_DRAWER_ALPHA;
|
||||
|
||||
var (propertyRect, controlRect) = RectUtility.HorizontalSliceRight(propertyFullRect, RemoveButtonRect.width);
|
||||
var (removeButtonRect, _) = RectUtility.VerticalSliceTop(controlRect, RemoveButtonRect.height);
|
||||
|
||||
#region Draw Component Block
|
||||
EditorGUI.DrawRect(propertyFullRect, alphaPanelColor);
|
||||
propertyRect = RectUtility.AddPadding(propertyRect, padding);
|
||||
if (isEmpty)
|
||||
{
|
||||
GUILayout.Label(label);
|
||||
GUI.Label(propertyRect, label);
|
||||
}
|
||||
else
|
||||
{
|
||||
EditorGUILayout.PropertyField(componentProperty, label, true);
|
||||
EditorGUI.PropertyField(propertyRect, componentProperty, label, true);
|
||||
}
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
componentProperty.serializedObject.ApplyModifiedProperties();
|
||||
EditorUtility.SetDirty(componentProperty.serializedObject.targetObject);
|
||||
}
|
||||
|
||||
Rect lastrect = GUILayoutUtility.GetLastRect();
|
||||
Rect removeButtonRect = RemoveButtonRect;
|
||||
removeButtonRect.center = new Vector2(lastrect.xMax + removeButtonRect.width, lastrect.yMin + removeButtonRect.height / 2f);
|
||||
|
||||
GUILayout.EndVertical();
|
||||
//Rect lineRect = GUILayoutUtility.GetLastRect();
|
||||
//lineRect.y = lineRect.yMax;
|
||||
//lineRect.height = 3f;
|
||||
//Color rectColor = panelColor;
|
||||
//rectColor.a = 0.34f;
|
||||
//EditorGUI.DrawRect(lineRect, rectColor);
|
||||
GUILayout.Label("", GUILayout.Width(removeButtonRect.width));
|
||||
|
||||
if (GUI.Button(removeButtonRect, "x", removeButtonStyle))
|
||||
if (GUI.Button(removeButtonRect, "x"))
|
||||
{
|
||||
OnRemoveComponentAt(index);
|
||||
}
|
||||
#endregion
|
||||
|
||||
if (!string.IsNullOrEmpty(description))
|
||||
{
|
||||
Rect tooltipIconRect = TooltipIconRect;
|
||||
tooltipIconRect.center = new Vector2(lastrect.xMax - removeButtonRect.width / 2f, lastrect.yMin + removeButtonRect.height / 2f);
|
||||
GUIContent descriptionLabel = new GUIContent(EcsUnityConsts.INFO_MARK, description);
|
||||
tooltipIconRect.center = new Vector2(propertyRect.xMax - removeButtonRect.width / 2f, propertyRect.yMin + removeButtonRect.height / 2f);
|
||||
GUIContent descriptionLabel = new GUIContent("( i )", description);
|
||||
GUI.Label(tooltipIconRect, descriptionLabel, EditorStyles.boldLabel);
|
||||
}
|
||||
GUILayout.EndHorizontal();
|
||||
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
componentProperty.serializedObject.ApplyModifiedProperties();
|
||||
componentProperty.serializedObject.SetIsDifferentCacheDirty();
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawDamagedComponent(SerializedProperty componentRefProp, int index)
|
||||
|
Loading…
Reference in New Issue
Block a user