Compare commits

..

3 Commits

Author SHA1 Message Date
DCFApixels
84401b875d Update RuntimeComponentsDrawer.cs 2025-04-21 00:10:57 +08:00
DCFApixels
fdbdb94b0c Update EntlongDrawer.cs 2025-04-20 20:40:46 +08:00
DCFApixels
a8f08f2137 Update EntlongDrawer.cs 2025-04-20 20:23:43 +08:00
2 changed files with 101 additions and 71 deletions

View File

@ -15,6 +15,20 @@ namespace DCFApixels.DragonECS.Unity.Editors
{ {
Rect labelRect, hyperlinkButtonRect; Rect labelRect, hyperlinkButtonRect;
(labelRect, position) = position.HorizontalSliceLeft(EditorGUIUtility.labelWidth * 0.65f); (labelRect, position) = position.HorizontalSliceLeft(EditorGUIUtility.labelWidth * 0.65f);
var eventType = Event.current.type;
Rect dropRect = position;
dropRect.yMax = position.yMin + EditorGUIUtility.singleLineHeight;
int controlID = GUIUtility.GetControlID(s_ObjectFieldHash, FocusType.Keyboard, position);
bool containsMouse = dropRect.Contains(Event.current.mousePosition);
if(containsMouse && eventType == EventType.Repaint && DragAndDrop.activeControlID == controlID)
{
EditorStyles.selectionRect.Draw(dropRect.AddPadding(-1), GUIContent.none, controlID, false, false);
}
(position, hyperlinkButtonRect) = position.HorizontalSliceRight(18f); (position, hyperlinkButtonRect) = position.HorizontalSliceRight(18f);
bool drawFoldout = property.hasMultipleDifferentValues == false; bool drawFoldout = property.hasMultipleDifferentValues == false;
@ -59,13 +73,9 @@ namespace DCFApixels.DragonECS.Unity.Editors
} }
Rect dropRect = position;
dropRect.yMax = position.yMin + EditorGUIUtility.singleLineHeight;
var eventType = Event.current.type; if (!containsMouse || !GUI.enabled)
int controlID = GUIUtility.GetControlID(s_ObjectFieldHash, FocusType.Keyboard, position);
if (!dropRect.Contains(Event.current.mousePosition) || !GUI.enabled)
{ {
return; return;
} }
@ -74,75 +84,77 @@ namespace DCFApixels.DragonECS.Unity.Editors
DragAndDrop.visualMode = DragAndDropVisualMode.Generic; DragAndDrop.visualMode = DragAndDropVisualMode.Generic;
} }
if (eventType == EventType.DragPerform) if (eventType == EventType.DragPerform || eventType == EventType.DragUpdated)
{ {
entlong ent = default; if (eventType == EventType.DragPerform)
bool isValide = false;
var dragged = DragAndDrop.objectReferences[0];
if (dragged is GameObject go)
{ {
if (go.TryGetComponent(out EcsEntityConnect connect)) entlong ent = default;
bool isValide = false;
var dragged = DragAndDrop.objectReferences[0];
if (dragged is GameObject go)
{ {
ent = connect.Entity; if (go.TryGetComponent(out EcsEntityConnect connect))
isValide = true;
}
else if (go.TryGetComponent(out EntityMonitor monitor))
{
ent = monitor.Entity;
isValide = true;
}
else
{
foreach (var beh in go.GetComponents<MonoBehaviour>())
{ {
if(TryFindEntlong(beh, out ent)) ent = connect.Entity;
isValide = true;
}
else if (go.TryGetComponent(out EntityMonitor monitor))
{
ent = monitor.Entity;
isValide = true;
}
else
{
foreach (var beh in go.GetComponents<MonoBehaviour>())
{ {
isValide = true; if (TryFindEntlong(beh, out ent))
break; {
isValide = true;
break;
}
} }
} }
} }
else
{
if (dragged is EcsEntityConnect connect)
{
ent = connect.Entity;
isValide = true;
}
else if (dragged is EntityMonitor monitor)
{
ent = monitor.Entity;
isValide = true;
}
else
{
if (TryFindEntlong(dragged, out ent))
{
isValide = true;
}
}
}
if (isValide)
{
long entityLong = *(long*)&ent;
fulleProperty.longValue = entityLong;
}
EcsGUI.Changed = true;
DragAndDrop.AcceptDrag();
DragAndDrop.activeControlID = 0;
} }
else else
{ {
if (dragged is EcsEntityConnect connect) DragAndDrop.activeControlID = controlID;
{
ent = connect.Entity;
isValide = true;
}
else if (dragged is EntityMonitor monitor)
{
ent = monitor.Entity;
isValide = true;
}
else
{
if (TryFindEntlong(dragged, out ent))
{
isValide = true;
}
}
} }
if (isValide)
{
long entityLong = *(long*)&ent;
fulleProperty.longValue = entityLong;
}
EcsGUI.Changed = true;
DragAndDrop.AcceptDrag();
DragAndDrop.activeControlID = 0;
}
else
{
DragAndDrop.activeControlID = controlID;
} }
//Event.current.Use();
} }
private bool TryFindEntlong(Object uniObj, out entlong ent) private bool TryFindEntlong(Object uniObj, out entlong ent)

View File

@ -82,7 +82,14 @@ namespace DCFApixels.DragonECS.Unity.Editors.X
ResetWrappers(); ResetWrappers();
IsUnmanaged = UnsafeUtility.IsUnmanaged(type); IsUnmanaged = UnsafeUtility.IsUnmanaged(type);
IsUnityObjectType = typeof(UnityObject).IsAssignableFrom(type); IsUnityObjectType = typeof(UnityObject).IsAssignableFrom(type);
IsUnitySerializable = IsUnityObjectType || (!type.IsGenericType && type.IsSerializable); IsUnitySerializable =
IsUnityObjectType ||
//typeof(Array).IsAssignableFrom(type) ||
//(type.IsGenericType && type.GetGenericTypeDefinition() == typeof(List<>)) ||
//type.IsPrimitive ||
//type == typeof(string) ||
//type.IsEnum ||
(!type.IsGenericType && type.IsSerializable && type.HasAttribute<System.SerializableAttribute>());
if (type == typeof(void)) { return; } if (type == typeof(void)) { return; }
@ -108,7 +115,7 @@ namespace DCFApixels.DragonECS.Unity.Editors.X
public readonly Type FieldType; public readonly Type FieldType;
public readonly string UnityFormatName; public readonly string UnityFormatName;
public readonly bool IsUnityObjectField; public readonly bool IsUnityObjectField;
public readonly bool IsPassToSerialize; public readonly bool IsPassToUnitySerialize;
public readonly RuntimeComponentReflectionCache ValueTypeReflectionCache; public readonly RuntimeComponentReflectionCache ValueTypeReflectionCache;
public FieldInfoData(FieldInfo fieldInfo) public FieldInfoData(FieldInfo fieldInfo)
{ {
@ -116,7 +123,7 @@ namespace DCFApixels.DragonECS.Unity.Editors.X
FieldType = fieldInfo.FieldType; FieldType = fieldInfo.FieldType;
IsUnityObjectField = typeof(UnityObject).IsAssignableFrom(fieldInfo.FieldType); IsUnityObjectField = typeof(UnityObject).IsAssignableFrom(fieldInfo.FieldType);
UnityFormatName = UnityEditorUtility.TransformFieldName(fieldInfo.Name); UnityFormatName = UnityEditorUtility.TransformFieldName(fieldInfo.Name);
IsPassToSerialize = IsPassToUnitySerialize =
(fieldInfo.IsPublic || fieldInfo.HasAttribute<SerializeField>() || fieldInfo.HasAttribute<SerializeReference>()) && (fieldInfo.IsPublic || fieldInfo.HasAttribute<SerializeField>() || fieldInfo.HasAttribute<SerializeReference>()) &&
(fieldInfo.IsInitOnly || fieldInfo.HasAttribute<System.NonSerializedAttribute>()) == false; (fieldInfo.IsInitOnly || fieldInfo.HasAttribute<System.NonSerializedAttribute>()) == false;
ValueTypeReflectionCache = FieldType.IsValueType ? GetRuntimeComponentReflectionCache(FieldType) : null; ValueTypeReflectionCache = FieldType.IsValueType ? GetRuntimeComponentReflectionCache(FieldType) : null;
@ -127,7 +134,7 @@ namespace DCFApixels.DragonECS.Unity.Editors.X
FieldType = fieldType; FieldType = fieldType;
UnityFormatName = unityFormatName; UnityFormatName = unityFormatName;
IsUnityObjectField = typeof(UnityObject).IsAssignableFrom(fieldType); IsUnityObjectField = typeof(UnityObject).IsAssignableFrom(fieldType);
IsPassToSerialize = isPassToSerialize; IsPassToUnitySerialize = isPassToSerialize;
ValueTypeReflectionCache = FieldType.IsValueType ? GetRuntimeComponentReflectionCache(FieldType) : null; ValueTypeReflectionCache = FieldType.IsValueType ? GetRuntimeComponentReflectionCache(FieldType) : null;
} }
public RuntimeComponentReflectionCache GetReflectionCache(Type type) public RuntimeComponentReflectionCache GetReflectionCache(Type type)
@ -374,16 +381,20 @@ namespace DCFApixels.DragonECS.Unity.Editors.X
{ {
using (EcsGUI.UpIndentLevel()) using (EcsGUI.UpIndentLevel())
{ {
for (int j = 0, jMax = cache.Fields.Length; j < jMax; j++) if (cache != null)
{ {
var field = cache.Fields[j]; for (int j = 0, jMax = cache.Fields.Length; j < jMax; j++)
if (DrawRuntimeData(ref field, UnityEditorUtility.GetLabel(field.UnityFormatName), expandMatrix, field.FieldInfo.GetValue(data), out object fieldData))
{ {
field.FieldInfo.SetValue(data, fieldData); var field = cache.Fields[j];
outData = data; if (DrawRuntimeData(ref field, UnityEditorUtility.GetLabel(field.UnityFormatName), expandMatrix, field.FieldInfo.GetValue(data), out object fieldData))
changed = true; {
field.FieldInfo.SetValue(data, fieldData);
outData = data;
changed = true;
}
} }
} }
} }
} }
} }
@ -428,7 +439,14 @@ namespace DCFApixels.DragonECS.Unity.Editors.X
wrapper.IsExpanded = isExpanded; wrapper.IsExpanded = isExpanded;
try try
{ {
EditorGUILayout.PropertyField(wrapper.Property, label, true); if (fieldInfoData.IsPassToUnitySerialize)
{
EditorGUILayout.PropertyField(wrapper.Property, label, true);
}
else
{
EditorGUILayout.LabelField(label, " ");
}
} }
catch (ArgumentException) catch (ArgumentException)
{ {