2024-09-14 18:33:54 +08:00
|
|
|
|
namespace DCFApixels.DragonECS.Unity.Internal
|
|
|
|
|
|
{
|
|
|
|
|
|
using System;
|
|
|
|
|
|
|
|
|
|
|
|
[AttributeUsage(AttributeTargets.Field, Inherited = false, AllowMultiple = true)]
|
|
|
|
|
|
internal sealed class ArrayElementAttribute : Attribute { }
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#if UNITY_EDITOR
|
|
|
|
|
|
namespace DCFApixels.DragonECS.Unity.Editors
|
|
|
|
|
|
{
|
|
|
|
|
|
using DCFApixels.DragonECS.Unity.Internal;
|
|
|
|
|
|
using global::Unity.Collections.LowLevel.Unsafe;
|
|
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using System.Reflection;
|
|
|
|
|
|
using UnityEditor;
|
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
using UnityObject = UnityEngine.Object;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
internal abstract class ExtendedEditor : Editor
|
|
|
|
|
|
{
|
|
|
|
|
|
private bool _isStaticInit = false;
|
|
|
|
|
|
private bool _isInit = false;
|
|
|
|
|
|
|
2024-09-14 23:30:11 +08:00
|
|
|
|
protected float OneLineHeight
|
2024-09-14 18:33:54 +08:00
|
|
|
|
{
|
|
|
|
|
|
get => EditorGUIUtility.singleLineHeight;
|
|
|
|
|
|
}
|
|
|
|
|
|
protected float Spacing
|
|
|
|
|
|
{
|
|
|
|
|
|
get => EditorGUIUtility.standardVerticalSpacing;
|
|
|
|
|
|
}
|
2024-09-14 23:30:11 +08:00
|
|
|
|
protected bool IsShowInterfaces
|
|
|
|
|
|
{
|
2024-09-21 14:39:09 +08:00
|
|
|
|
get { return UserSettingsPrefs.instance.IsShowInterfaces; }
|
|
|
|
|
|
set { UserSettingsPrefs.instance.IsShowInterfaces = value; }
|
2024-09-14 23:30:11 +08:00
|
|
|
|
}
|
|
|
|
|
|
protected bool IsShowHidden
|
|
|
|
|
|
{
|
2024-09-21 14:39:09 +08:00
|
|
|
|
get { return UserSettingsPrefs.instance.IsShowHidden; }
|
|
|
|
|
|
set { UserSettingsPrefs.instance.IsShowHidden = value; }
|
2024-09-14 23:30:11 +08:00
|
|
|
|
}
|
2024-09-27 22:04:00 +08:00
|
|
|
|
private static ComponentColorMode ComponentColorMode
|
|
|
|
|
|
{
|
|
|
|
|
|
get { return UserSettingsPrefs.instance.ComponentColorMode; }
|
|
|
|
|
|
set { UserSettingsPrefs.instance.ComponentColorMode = value; }
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-09-14 23:30:11 +08:00
|
|
|
|
protected bool IsMultipleTargets => targets.Length > 1;
|
2024-09-14 18:33:54 +08:00
|
|
|
|
|
|
|
|
|
|
protected virtual bool IsStaticInit { get { return _isStaticInit; } }
|
|
|
|
|
|
protected virtual bool IsInit { get { return _isInit; } }
|
|
|
|
|
|
protected void StaticInit()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (IsStaticInit) { return; }
|
|
|
|
|
|
_isStaticInit = true;
|
|
|
|
|
|
OnStaticInit();
|
|
|
|
|
|
}
|
|
|
|
|
|
protected void Init()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (IsInit) { return; }
|
|
|
|
|
|
_isInit = true;
|
|
|
|
|
|
OnInit();
|
|
|
|
|
|
}
|
|
|
|
|
|
protected virtual void OnStaticInit() { }
|
|
|
|
|
|
protected virtual void OnInit() { }
|
|
|
|
|
|
|
|
|
|
|
|
public sealed override void OnInspectorGUI()
|
|
|
|
|
|
{
|
2024-09-14 23:30:11 +08:00
|
|
|
|
using (EcsGUI.CheckChanged(serializedObject))
|
2024-09-14 18:33:54 +08:00
|
|
|
|
{
|
|
|
|
|
|
StaticInit();
|
|
|
|
|
|
Init();
|
|
|
|
|
|
DrawCustom();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected abstract void DrawCustom();
|
|
|
|
|
|
protected void DrawDefault()
|
|
|
|
|
|
{
|
|
|
|
|
|
base.OnInspectorGUI();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected SerializedProperty FindProperty(string name)
|
|
|
|
|
|
{
|
|
|
|
|
|
return serializedObject.FindProperty(name);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2024-09-14 23:30:11 +08:00
|
|
|
|
internal abstract class ExtendedEditor<T> : ExtendedEditor
|
2024-09-14 18:33:54 +08:00
|
|
|
|
{
|
|
|
|
|
|
public T Target
|
|
|
|
|
|
{
|
|
|
|
|
|
get
|
|
|
|
|
|
{
|
|
|
|
|
|
var obj = target;
|
|
|
|
|
|
return UnsafeUtility.As<UnityObject, T>(ref obj);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
public T[] Targets
|
|
|
|
|
|
{
|
|
|
|
|
|
get
|
|
|
|
|
|
{
|
|
|
|
|
|
var obj = targets;
|
|
|
|
|
|
return UnsafeUtility.As<UnityObject[], T[]>(ref obj);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
internal abstract class ExtendedPropertyDrawer : PropertyDrawer
|
|
|
|
|
|
{
|
|
|
|
|
|
private bool _isStaticInit = false;
|
|
|
|
|
|
private bool _isInit = false;
|
|
|
|
|
|
|
|
|
|
|
|
private IEnumerable<Attribute> _attributes = null;
|
|
|
|
|
|
|
|
|
|
|
|
private bool? _isArrayElement = null;
|
|
|
|
|
|
protected bool IsArrayElement
|
|
|
|
|
|
{
|
|
|
|
|
|
get
|
|
|
|
|
|
{
|
|
|
|
|
|
if (_isArrayElement == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
_isArrayElement = Attributes.Any(o => o is ArrayElementAttribute);
|
|
|
|
|
|
}
|
|
|
|
|
|
return _isArrayElement.Value;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-09-16 19:31:01 +08:00
|
|
|
|
protected IEnumerable<Attribute> Attributes
|
2024-09-14 18:33:54 +08:00
|
|
|
|
{
|
|
|
|
|
|
get
|
|
|
|
|
|
{
|
|
|
|
|
|
if (_attributes == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
_attributes = fieldInfo.GetCustomAttributes();
|
|
|
|
|
|
}
|
|
|
|
|
|
return _attributes;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
protected float OneLineHeight
|
|
|
|
|
|
{
|
|
|
|
|
|
get => EditorGUIUtility.singleLineHeight;
|
|
|
|
|
|
}
|
|
|
|
|
|
protected float Spacing
|
|
|
|
|
|
{
|
|
|
|
|
|
get => EditorGUIUtility.standardVerticalSpacing;
|
|
|
|
|
|
}
|
2024-09-14 23:30:11 +08:00
|
|
|
|
protected bool IsShowInterfaces
|
|
|
|
|
|
{
|
2024-09-21 14:39:09 +08:00
|
|
|
|
get { return UserSettingsPrefs.instance.IsShowInterfaces; }
|
|
|
|
|
|
set { UserSettingsPrefs.instance.IsShowInterfaces = value; }
|
2024-09-14 23:30:11 +08:00
|
|
|
|
}
|
|
|
|
|
|
protected bool IsShowHidden
|
|
|
|
|
|
{
|
2024-09-21 14:39:09 +08:00
|
|
|
|
get { return UserSettingsPrefs.instance.IsShowHidden; }
|
|
|
|
|
|
set { UserSettingsPrefs.instance.IsShowHidden = value; }
|
2024-09-14 23:30:11 +08:00
|
|
|
|
}
|
2024-09-27 22:04:00 +08:00
|
|
|
|
private static ComponentColorMode ComponentColorMode
|
|
|
|
|
|
{
|
|
|
|
|
|
get { return UserSettingsPrefs.instance.ComponentColorMode; }
|
|
|
|
|
|
set { UserSettingsPrefs.instance.ComponentColorMode = value; }
|
|
|
|
|
|
}
|
2024-09-14 18:33:54 +08:00
|
|
|
|
protected virtual bool IsStaticInit { get { return _isStaticInit; } }
|
|
|
|
|
|
protected virtual bool IsInit { get { return _isInit; } }
|
|
|
|
|
|
protected void StaticInit()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (IsStaticInit) { return; }
|
|
|
|
|
|
_isStaticInit = true;
|
|
|
|
|
|
OnStaticInit();
|
|
|
|
|
|
}
|
|
|
|
|
|
protected void Init()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (IsInit) { return; }
|
|
|
|
|
|
_isInit = true;
|
|
|
|
|
|
OnInit();
|
|
|
|
|
|
}
|
|
|
|
|
|
protected virtual void OnStaticInit() { }
|
|
|
|
|
|
protected virtual void OnInit() { }
|
|
|
|
|
|
|
|
|
|
|
|
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
|
|
|
|
|
|
{
|
2024-09-14 23:30:11 +08:00
|
|
|
|
using (EcsGUI.CheckChanged(property.serializedObject))
|
2024-09-14 18:33:54 +08:00
|
|
|
|
{
|
|
|
|
|
|
StaticInit();
|
|
|
|
|
|
Init();
|
|
|
|
|
|
DrawCustom(position, property, label);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
protected abstract void DrawCustom(Rect position, SerializedProperty property, GUIContent label);
|
|
|
|
|
|
}
|
|
|
|
|
|
internal abstract class ExtendedPropertyDrawer<TAttribute> : ExtendedPropertyDrawer
|
|
|
|
|
|
{
|
|
|
|
|
|
protected TAttribute Attribute
|
|
|
|
|
|
{
|
|
|
|
|
|
get
|
|
|
|
|
|
{
|
|
|
|
|
|
var obj = attribute;
|
|
|
|
|
|
return UnsafeUtility.As<PropertyAttribute, TAttribute>(ref obj);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
#endif
|