public override void OnInspectorGUI()
        {
            GUILayout.Space(20);

            GUILayout.BeginVertical(NanoEditorHelper.backStyle());

            GUILayout.Space(5);

            GUILayout.Label(handler.ContextName + " Context", new GUIStyle()
            {
                fontStyle = FontStyle.Bold, alignment = TextAnchor.MiddleCenter
            });

            GUILayout.Space(20);

            if (GUILayout.Button("Create Entity"))
            {
                handler.CreateEntity();
            }

            GUILayout.Space(5);

            GUILayout.EndVertical();

            GUILayout.Space(20);
        }
        public override void OnInspectorGUI()
        {
            serializedObject.Update();
            DrawLogo();
            GUILayout.BeginVertical(NanoEditorHelper.backStyle());

            GUILayout.Space(5);
            GUILayout.Label("(triggers recompilation)", NanoEditorHelper.SettingsTitleStyle);
            GUILayout.Space(5);

            settings.VisualDebugEnabled = GUILayout.Toggle(settings.VisualDebugEnabled, "Visual Debug Enabled");
            settings.ReactivityEnabled  = GUILayout.Toggle(settings.ReactivityEnabled, "Reactivity Enabled");

            GUILayout.EndVertical();
            GUILayout.Space(25);

            EditorGUILayout.PropertyField(serializedObject.FindProperty("GeneratedFolderPath"));
            EditorGUILayout.PropertyField(serializedObject.FindProperty("SourceFolderPath"));
            EditorGUILayout.PropertyField(serializedObject.FindProperty("TriggerGenerationOnSourceChange"));

            GUILayout.Space(25);

            list.DoLayoutList();

            serializedObject.ApplyModifiedProperties();

            if (target != null)
            {
                EditorUtility.SetDirty(target);
            }
        }
Beispiel #3
0
        void UpdateEditor()
        {
            EditorGUILayout.Space();

            if (GUILayout.Button(new GUIContent("Destroy"), GUILayout.Height(20)))
            {
                observer.OnEntityDestroy(entity);
            }

            EditorGUILayout.Space();



#if UNITY_EDITOR && NANOECS_DEBUG
            var componentObservers = new List <ComponentObserver>(entity.ComponentObservers);

            var rawTypes = observer.ComponentsLookup.Keys;

            var usedTypes = rawTypes
                            .Where(type => HasTypes(type, componentObservers))
                            .ToArray();

            var unusedTypes = rawTypes
                              .Where(type => !HasTypes(type, componentObservers))
                              .ToArray();


            filterComponentString = filterComponentsField.OnGUI(EditorGUILayout.GetControlRect(), filterComponentString);

            var filter = filterComponentString == null ? null : filterComponentString.Replace(' ', ',').Split(new char[] { ',', ' ', '.', ';' }).Where(x => x != null).Where(x => x != "");

            var filteredTypes = (filterComponentString == null || filterComponentString == "") ? usedTypes : usedTypes
                                .Where(type =>
            {
                foreach (var f in filter)
                {
                    var lowerType = type.ToLower();
                    var lowerF    = f.ToLower();
                    if (lowerType.Contains(lowerF))
                    {
                        return(true);
                    }
                }
                return(false);
            }).ToArray();

            foreach (var componentObserver in componentObservers)
            {
                var component = componentObserver.Component;
                var type      = component.GetType();
                var name      = type.Name;
                if (!filteredTypes.Contains(name))
                {
                    continue;
                }
                GUILayout.Space(5);

                name = name.Replace("Component", "");

                GUILayout.BeginHorizontal(NanoEditorHelper.backStyle(component.GetHashCode()));

                var fields = type.GetFields(
                    BindingFlags.NonPublic |
                    BindingFlags.Public |
                    BindingFlags.Instance).Where(f => f.FieldType != typeof(Action <ushort>)).ToList();

                bool hasToRemove = false;

                if (fields.Count > 0)
                {
                    GUILayout.Space(15);
                    componentObserver.IsFoldout = EditorGUILayout.Foldout(componentObserver.IsFoldout, name, true);
                }
                else
                {
                    EditorGUILayout.LabelField(name);
                }
                if (GUILayout.Button("✕", GUILayout.Width(19), GUILayout.Height(19)))
                {
                    hasToRemove = true;
                }

                GUILayout.EndHorizontal();

                if (hasToRemove)
                {
                    entity.RemoveComponentOfIndex(observer.ComponentsLookup[component.GetType().ToString()]);
                }

                if (!componentObserver.IsFoldout)
                {
                    continue;
                }

                foreach (var field in fields)
                {
                    GUILayout.BeginHorizontal(NanoEditorHelper.backStyle(component.GetHashCode()));

                    DrawField(component, fields, field);

                    GUILayout.EndHorizontal();
                }
            }

            GUILayout.Space(25);


            if (!observer.DisplayDropDown)
            {
                if (GUILayout.Button(new GUIContent("Add Component"), GUILayout.Height(20)))
                {
                    addComponentsField.SetFocus();
                    observer.DisplayDropDown = true;
                }
            }

            if (observer.DisplayDropDown)
            {
                var r = EditorGUILayout.GetControlRect(); r.height = 20;
                observer.CurrentComponentName = EditorExtend.TextFieldAutoComplete(addComponentsField, r, observer.CurrentComponentName, unusedTypes, (string value) => value.Replace("Component", ""), maxShownCount: 10, levenshteinDistance: 0.5f);
            }

            if (observer.ComponentsLookup.ContainsKey(observer.CurrentComponentName))
            {
                entity.Add <ComponentEcs>(observer.ComponentsLookup[observer.CurrentComponentName]);
                observer.CurrentComponentName = string.Empty;
            }

            Event e = Event.current;
            if (e.type == EventType.Ignore ||
                (e.type == EventType.MouseDown))
            {
                observer.DisplayDropDown = false;
            }
            GUILayout.Space(50);

            if (target != null)
            {
                EditorUtility.SetDirty(target);
            }
#endif
        }