public static void DrawComponentBox(MonoEntity entity, int index, SerializedProperty prop)
 {
     if (index >= entity.ComponentsCount)
     {
         return;
     }
     EntityGUI.Vertical(EntityGUI.GetColorStyle(entity.ComponentsCount, index), () =>
     {
         DrawProperty(entity, index, prop);
     });
     if (remove)
     {
         Remove(entity, index);
     }
 }
        private static void DrawTypeFieldRunTime(object component, FieldInfo field)
        {
            var fieldValue = field.GetValue(component);
            var fieldType  = field.FieldType;

            if (fieldType == typeof(UnityEngine.Object) || fieldType.IsSubclassOf(typeof(UnityEngine.Object)))
            {
                EntityGUI.Horizontal(() =>
                {
                    fieldValue = EditorGUILayout.ObjectField($"    {field.Name}", fieldValue as UnityEngine.Object, fieldType, true);
                    component.GetType().GetField(field.Name).SetValue(component, fieldValue);
                });
                return;
            }

            EntityGUI.Horizontal(() => SetFieldValue(fieldValue, field.Name, component));
        }
        private static void DrawProperty(MonoEntity entity, int index, SerializedProperty prop)
        {
            var component = entity.Components[index];

            if (component == null)
            {
                entity.Components = entity.Components.Where(x => x != null).ToList();
                return;
            }

            EntityGUI.Horizontal(() =>
            {
                EditorGUILayout.LabelField(component.GetType().Name, EditorStyles.boldLabel);
                RemoveBtn();
            });

            EditorGUI.indentLevel++;
            DrawProperties(prop, true);
            EditorGUI.indentLevel--;
        }
        private static void DrawEditorMode(MonoEntity entity, int index)
        {
            var component = entity.Components[index];

            if (component == null)
            {
                entity.Components = entity.Components.Where(x => x != null).ToList();
                return;
            }

            var type   = component.GetType();
            var fields = type.GetFields(BindingFlags.Instance | BindingFlags.Public);

            EntityGUI.Horizontal(() =>
            {
                EditorGUILayout.LabelField($"{type.Name}", EditorStyles.boldLabel);
                RemoveBtn();
            });

            foreach (var field in fields)
            {
                DrawTypeField(component, field);
            }
        }
예제 #5
0
        public override void OnInspectorGUI()
        {
            //DrawDefaultInspector();
            entity = (MonoEntity)target;
            if (!entity.runTime)
            {
                EditorGUI.BeginChangeCheck();
            }

            worldProviderProperty.objectReferenceValue = EditorGUILayout.ObjectField("World provider", worldProviderProperty.objectReferenceValue, typeof(EcsWorldProvider), false);

            if (entity.runTime)
            {
                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.Space();
                if (GUILayout.Button(new GUIContent("Kill Entity"), GUILayout.Width(154), GUILayout.Height(24)))
                {
                    entity.entity.Destroy();
                }
                EditorGUILayout.Space();
                EditorGUILayout.EndHorizontal();
            }
            else
            {
                EditorGUILayout.BeginHorizontal();
                entity.destroyComponent = EditorGUILayout.Toggle("Destroy MonoBeh", entity.destroyComponent);
                entity.destroyObject    = EditorGUILayout.Toggle("Destroy GO", entity.destroyObject);
                EditorGUILayout.EndHorizontal();
            }

            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("Run Time", entity.runTime ? "✔" : "✘", EditorStyles.largeLabel);
            EditorGUILayout.LabelField($"ID:{entity.entity.GetInternalId().ToString()}");
            EditorGUILayout.EndHorizontal();
            EntityGUI.Vertical(GUI.skin.box, () =>
            {
                if (entity.runTime)
                {
                    if (!entity.entity.IsAlive())
                    {
                        EditorGUILayout.LabelField("ENTITY DEAD", EditorStyles.whiteLargeLabel);
                        return;
                    }
                }
                EntityGUI.Horizontal(() =>
                {
                    EditorGUILayout.LabelField($"ECS Components [{entity.ComponentsCount.ToString()}]", EditorStyles.boldLabel);
                    if (GUILayout.Button(new GUIContent("Clear", "Remove All Components")))
                    {
                        RemoveAll();
                    }
                });

                EntityGUI.Horizontal(() =>
                {
                    EditorGUILayout.LabelField("Add Component");
                    if (GUILayout.Button(new GUIContent("▼"), GUILayout.Width(21), GUILayout.Height(21)))
                    {
                        flowed = !flowed;
                    }
                });

                if (ComponentTypesList.Count > 1)
                {
                    entity.lastIndex = EditorGUILayout.Popup(entity.lastIndex, ComponentTypesList.GetAllInArray());
                }
                else
                {
                    ComponentTypesList.Init();
                }

                if (entity.lastIndex != 0)
                {
                    AddComponent(entity.lastIndex);
                }

                EditorGUILayout.BeginVertical(GUI.skin.box);
                if (!flowed)
                {
                    DrawComponents();
                }
                EditorGUILayout.EndVertical();
            });

            if (entity.runTime)
            {
                return;
            }
            if (EditorGUI.EndChangeCheck())
            {
                EditorUtility.SetDirty(target);
                serializedObject.ApplyModifiedProperties();
            }
        }
예제 #6
0
 private void Awake()
 {
     EntityGUI.Init();
     ComponentTypesList.Init();
 }