Compare commits

..

No commits in common. "84401b875d10a74db6b7331730f07e93af73eadb" and "c08be8e8837885de1ad9084cf429da20ebebb1d2" have entirely different histories.

2 changed files with 67 additions and 97 deletions

View File

@ -15,20 +15,6 @@ 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;
@ -73,9 +59,13 @@ namespace DCFApixels.DragonECS.Unity.Editors
} }
Rect dropRect = position;
dropRect.yMax = position.yMin + EditorGUIUtility.singleLineHeight;
if (!containsMouse || !GUI.enabled) var eventType = Event.current.type;
int controlID = GUIUtility.GetControlID(s_ObjectFieldHash, FocusType.Keyboard, position);
if (!dropRect.Contains(Event.current.mousePosition) || !GUI.enabled)
{ {
return; return;
} }
@ -84,77 +74,75 @@ namespace DCFApixels.DragonECS.Unity.Editors
DragAndDrop.visualMode = DragAndDropVisualMode.Generic; DragAndDrop.visualMode = DragAndDropVisualMode.Generic;
} }
if (eventType == EventType.DragPerform || eventType == EventType.DragUpdated) if (eventType == EventType.DragPerform)
{ {
if (eventType == EventType.DragPerform) entlong ent = default;
bool isValide = false;
var dragged = DragAndDrop.objectReferences[0];
if (dragged is GameObject go)
{ {
entlong ent = default; if (go.TryGetComponent(out EcsEntityConnect connect))
bool isValide = false;
var dragged = DragAndDrop.objectReferences[0];
if (dragged is GameObject go)
{ {
if (go.TryGetComponent(out EcsEntityConnect connect)) ent = connect.Entity;
{ isValide = true;
ent = connect.Entity; }
isValide = true; else if (go.TryGetComponent(out EntityMonitor monitor))
} {
else if (go.TryGetComponent(out EntityMonitor monitor)) ent = monitor.Entity;
{ isValide = true;
ent = monitor.Entity;
isValide = true;
}
else
{
foreach (var beh in go.GetComponents<MonoBehaviour>())
{
if (TryFindEntlong(beh, out ent))
{
isValide = true;
break;
}
}
}
} }
else else
{ {
if (dragged is EcsEntityConnect connect) foreach (var beh in go.GetComponents<MonoBehaviour>())
{ {
ent = connect.Entity; if(TryFindEntlong(beh, out ent))
isValide = true;
}
else if (dragged is EntityMonitor monitor)
{
ent = monitor.Entity;
isValide = true;
}
else
{
if (TryFindEntlong(dragged, out ent))
{ {
isValide = true; isValide = true;
break;
} }
} }
} }
if (isValide)
{
long entityLong = *(long*)&ent;
fulleProperty.longValue = entityLong;
}
EcsGUI.Changed = true;
DragAndDrop.AcceptDrag();
DragAndDrop.activeControlID = 0;
} }
else else
{ {
DragAndDrop.activeControlID = controlID; 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
{
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,14 +82,7 @@ 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 = IsUnitySerializable = IsUnityObjectType || (!type.IsGenericType && type.IsSerializable);
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; }
@ -115,7 +108,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 IsPassToUnitySerialize; public readonly bool IsPassToSerialize;
public readonly RuntimeComponentReflectionCache ValueTypeReflectionCache; public readonly RuntimeComponentReflectionCache ValueTypeReflectionCache;
public FieldInfoData(FieldInfo fieldInfo) public FieldInfoData(FieldInfo fieldInfo)
{ {
@ -123,7 +116,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);
IsPassToUnitySerialize = IsPassToSerialize =
(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;
@ -134,7 +127,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);
IsPassToUnitySerialize = isPassToSerialize; IsPassToSerialize = isPassToSerialize;
ValueTypeReflectionCache = FieldType.IsValueType ? GetRuntimeComponentReflectionCache(FieldType) : null; ValueTypeReflectionCache = FieldType.IsValueType ? GetRuntimeComponentReflectionCache(FieldType) : null;
} }
public RuntimeComponentReflectionCache GetReflectionCache(Type type) public RuntimeComponentReflectionCache GetReflectionCache(Type type)
@ -381,20 +374,16 @@ namespace DCFApixels.DragonECS.Unity.Editors.X
{ {
using (EcsGUI.UpIndentLevel()) using (EcsGUI.UpIndentLevel())
{ {
if (cache != null) for (int j = 0, jMax = cache.Fields.Length; j < jMax; j++)
{ {
for (int j = 0, jMax = cache.Fields.Length; j < jMax; j++) var field = cache.Fields[j];
if (DrawRuntimeData(ref field, UnityEditorUtility.GetLabel(field.UnityFormatName), expandMatrix, field.FieldInfo.GetValue(data), out object fieldData))
{ {
var field = cache.Fields[j]; field.FieldInfo.SetValue(data, fieldData);
if (DrawRuntimeData(ref field, UnityEditorUtility.GetLabel(field.UnityFormatName), expandMatrix, field.FieldInfo.GetValue(data), out object fieldData)) outData = data;
{ changed = true;
field.FieldInfo.SetValue(data, fieldData);
outData = data;
changed = true;
}
} }
} }
} }
} }
} }
@ -439,14 +428,7 @@ namespace DCFApixels.DragonECS.Unity.Editors.X
wrapper.IsExpanded = isExpanded; wrapper.IsExpanded = isExpanded;
try try
{ {
if (fieldInfoData.IsPassToUnitySerialize) EditorGUILayout.PropertyField(wrapper.Property, label, true);
{
EditorGUILayout.PropertyField(wrapper.Property, label, true);
}
else
{
EditorGUILayout.LabelField(label, " ");
}
} }
catch (ArgumentException) catch (ArgumentException)
{ {