Esempio n. 1
0
        public static void DrawComponents(IEntity entity)
        {
            var unfoldedComponents    = GetUnfoldedComponents(entity);
            var componentMemberSearch = GetComponentMemberSearch(entity);

            EditorGUILayoutTools.BeginVerticalBox();

            EditorGUILayout.BeginHorizontal();
            {
                EditorGUILayout.LabelField("Components (" + entity.GetComponents().Length + ")", EditorStyles.boldLabel);
                if (EditorGUILayoutTools.MiniButtonLeft("▸"))
                {
                    for (var i = 0; i < unfoldedComponents.Length; i++)
                    {
                        unfoldedComponents[i] = false;
                    }
                }

                if (EditorGUILayoutTools.MiniButtonRight("▾"))
                {
                    for (var i = 0; i < unfoldedComponents.Length; i++)
                    {
                        unfoldedComponents[i] = true;
                    }
                }
            }
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.Space();

            var index = DrawAddComponentMenu(entity);

            if (index >= 0)
            {
                var componentType = entity.ContextInfo.componentTypes[index];
                var component     = entity.CreateComponent(index, componentType);
                entity.AddComponent(index, component);
            }

            EditorGUILayout.Space();

            ComponentNameSearchString = EditorGUILayoutTools.SearchTextField(ComponentNameSearchString);

            EditorGUILayout.Space();

            var indices    = entity.GetComponentIndices();
            var components = entity.GetComponents();

            for (var i = 0; i < components.Length; i++)
            {
                DrawComponent(
                    unfoldedComponents,
                    componentMemberSearch,
                    entity,
                    indices[i],
                    components[i]);
            }

            EditorGUILayoutTools.EndVerticalBox();
        }
Esempio n. 2
0
        public static void DrawEntity(IEntity entity)
        {
            var bgColor = GUI.backgroundColor;

            GUI.backgroundColor = Color.red;
            if (GUILayout.Button("Destroy Entity"))
            {
                entity.Destroy();
            }

            GUI.backgroundColor = bgColor;

            DrawComponents(entity);

            EditorGUILayout.Space();

            EditorGUILayout.LabelField("Retained by (" + entity.RetainCount + ")", EditorStyles.boldLabel);

            if (entity.AERC is SafeAERC safeAerc)
            {
                EditorGUILayoutTools.BeginVerticalBox();
                {
                    foreach (var owner in safeAerc.Owners.OrderBy(o => o.GetType().Name))
                    {
                        EditorGUILayout.BeginHorizontal();
                        {
                            EditorGUILayout.LabelField(owner.ToString());
                            if (EditorGUILayoutTools.MiniButton("Release"))
                            {
                                entity.Release(owner);
                            }

                            EditorGUILayout.EndHorizontal();
                        }
                    }
                }
                EditorGUILayoutTools.EndVerticalBox();
            }
        }
Esempio n. 3
0
        public static void DrawComponent(
            bool[] unfoldedComponents,
            string contextName,
            int totalNumberOfComponents,
            int index,
            IComponent component,
            Action <IComponent> removeComponent,
            Action onComponentChanged)
        {
            var componentType = component.GetType();
            var componentName = componentType.Name.RemoveComponentSuffix();
            var boxStyle      = GetColoredBoxStyle(contextName, totalNumberOfComponents, index);

            EditorGUILayout.BeginVertical(boxStyle);

            if (!Attribute.IsDefined(componentType, typeof(DontDrawComponentAttribute)))
            {
                var memberInfos = componentType.GetPublicMemberInfos();
                EditorGUILayout.BeginHorizontal();
                {
                    if (memberInfos.Count == 0)
                    {
                        EditorGUILayout.LabelField(componentName, EditorStyles.boldLabel);
                    }
                    else
                    {
                        unfoldedComponents[index] = EditorGUILayoutTools.Foldout(
                            unfoldedComponents[index],
                            componentName,
                            FoldoutStyle);
                    }

                    if (EditorGUILayoutTools.MiniButton("-"))
                    {
                        removeComponent?.Invoke(component);
                    }
                }
                EditorGUILayout.EndHorizontal();

                if (unfoldedComponents[index])
                {
                    var changed         = false;
                    var componentDrawer = GetComponentDrawer(componentType);
                    if (componentDrawer != null)
                    {
                        EditorGUI.BeginChangeCheck();
                        {
                            componentDrawer.DrawComponent(component);
                        }
                        changed = EditorGUI.EndChangeCheck();
                    }
                    else
                    {
                        foreach (var info in memberInfos)
                        {
                            var memberValue = info.GetValue(component);
                            var memberType  = memberValue == null ? info.type : memberValue.GetType();
                            if (DrawObjectMember(
                                    memberType,
                                    info.name,
                                    memberValue,
                                    component,
                                    info.SetValue))
                            {
                                changed = true;
                            }
                        }
                    }

                    if (changed)
                    {
                        onComponentChanged?.Invoke();
                    }
                }
            }
            else
            {
                EditorGUILayout.LabelField(componentName, "[DontDrawComponent]", EditorStyles.boldLabel);
            }

            EditorGUILayoutTools.EndVerticalBox();
        }
Esempio n. 4
0
        public static void DrawComponent(bool[] unfoldedComponents,
                                         string[] componentMemberSearch,
                                         IEntity entity,
                                         int index,
                                         IComponent component)
        {
            var componentType = component.GetType();
            var componentName = componentType.Name.RemoveComponentSuffix();

            if (EditorGUILayoutTools.MatchesSearchString(componentName.ToLower(), ComponentNameSearchString.ToLower()))
            {
                var boxStyle = GetColoredBoxStyle(entity, index);

                EditorGUILayout.BeginVertical(boxStyle);

                if (!Attribute.IsDefined(componentType, typeof(DontDrawComponentAttribute)))
                {
                    var memberInfos = componentType.GetPublicMemberInfos();
                    EditorGUILayout.BeginHorizontal();
                    {
                        if (memberInfos.Count == 0)
                        {
                            EditorGUILayout.LabelField(componentName, EditorStyles.boldLabel);
                        }
                        else
                        {
                            unfoldedComponents[index] = EditorGUILayoutTools.Foldout(
                                unfoldedComponents[index],
                                componentName,
                                FoldoutStyle);
                            if (unfoldedComponents[index])
                            {
                                componentMemberSearch[index] = memberInfos.Count > 5
                                                                        ? EditorGUILayoutTools.SearchTextField(componentMemberSearch[index])
                                                                        : string.Empty;
                            }
                        }

                        if (EditorGUILayoutTools.MiniButton("-"))
                        {
                            entity.RemoveComponent(index);
                        }
                    }
                    EditorGUILayout.EndHorizontal();

                    if (unfoldedComponents[index])
                    {
                        var newComponent = entity.CreateComponent(index, componentType);
                        component.CopyPublicMemberValues(newComponent);

                        var changed         = false;
                        var componentDrawer = GetComponentDrawer(componentType);
                        if (componentDrawer != null)
                        {
                            EditorGUI.BeginChangeCheck();
                            {
                                componentDrawer.DrawComponent(newComponent);
                            }
                            changed = EditorGUI.EndChangeCheck();
                        }
                        else
                        {
                            foreach (var info in memberInfos)
                            {
                                if (EditorGUILayoutTools.MatchesSearchString(
                                        info.name.ToLower(),
                                        componentMemberSearch[index].ToLower()))
                                {
                                    var memberValue = info.GetValue(newComponent);
                                    var memberType  = memberValue == null ? info.type : memberValue.GetType();
                                    if (DrawObjectMember(
                                            memberType,
                                            info.name,
                                            memberValue,
                                            newComponent,
                                            info.SetValue))
                                    {
                                        changed = true;
                                    }
                                }
                            }
                        }

                        if (changed)
                        {
                            entity.ReplaceComponent(index, newComponent);
                        }
                        else
                        {
                            entity.GetComponentPool(index).Push(newComponent);
                        }
                    }
                }
                else
                {
                    EditorGUILayout.LabelField(componentName, "[DontDrawComponent]", EditorStyles.boldLabel);
                }

                EditorGUILayoutTools.EndVerticalBox();
            }
        }