void DrawComponent(int index, SerializedProperty prop)
        {
            var component     = (SerializableComponent)prop.objectReferenceValue;
            var componentType = component.GetType();
            var componentName = componentType.Name.RemoveComponentSuffix();

            if (EntitasEditorLayout.MatchesSearchString(componentName.ToLower(), componentNameSearchString.ToLower()))
            {
                var boxStyle = styles[index];
                EditorGUILayout.BeginVertical(boxStyle);
                {
                    var memberInfos = componentType.GetPublicMemberInfos();
                    EditorGUILayout.BeginHorizontal();
                    {
                        if (memberInfos.Count == 0)
                        {
                            EditorGUILayout.LabelField(componentName, EditorStyles.boldLabel);
                        }
                        else
                        {
                            var foldoutStyle = new GUIStyle(EditorStyles.foldout);
                            foldoutStyle.fontStyle = FontStyle.Bold;
                            prop.isExpanded        = EditorGUILayout.Foldout(prop.isExpanded, componentName, foldoutStyle);
                        }
                        if (EntitasEditorLayout.MiniButton("-"))
                        {
                            components.Remove(component);
                        }
                    }
                    EditorGUILayout.EndHorizontal();
                    if (prop.isExpanded)
                    {
                        foreach (var info in memberInfos)
                        {
                            var memberValue = info.GetValue(component);
                            if (memberValue != null && memberValue.Equals(null))
                            {
                                info.SetValue(component, null);
                                memberValue = null;
                            }
                            var memberType = memberValue == null ? info.type : memberValue.GetType();
                            EntityDrawer.DrawObjectMember(info, memberValue, component, info.SetValue, _transform);
                        }
                    }
                }
                EntitasEditorLayout.EndVerticalBox();
            }
        }
Esempio n. 2
0
        int drawSystemInfos(DebugSystems systems, SystemInterfaceFlags type)
        {
            SystemInfo[] systemInfos = null;

            switch (type)
            {
            case SystemInterfaceFlags.IInitializeSystem:
                systemInfos = systems.initializeSystemInfos
                              .Where(systemInfo => systemInfo.initializationDuration >= _threshold)
                              .ToArray();
                break;

            case SystemInterfaceFlags.IExecuteSystem:
                systemInfos = systems.executeSystemInfos
                              .Where(systemInfo => systemInfo.averageExecutionDuration >= _threshold)
                              .ToArray();
                break;

            case SystemInterfaceFlags.ICleanupSystem:
                systemInfos = systems.cleanupSystemInfos
                              .Where(systemInfo => systemInfo.cleanupDuration >= _threshold)
                              .ToArray();
                break;

            case SystemInterfaceFlags.ITearDownSystem:
                systemInfos = systems.tearDownSystemInfos
                              .Where(systemInfo => systemInfo.teardownDuration >= _threshold)
                              .ToArray();
                break;
            }

            systemInfos = getSortedSystemInfos(systemInfos, _systemSortMethod);

            var systemsDrawn = 0;

            foreach (var systemInfo in systemInfos)
            {
                var debugSystems = systemInfo.system as DebugSystems;
                if (debugSystems != null)
                {
                    if (!shouldShowSystems(debugSystems, type))
                    {
                        continue;
                    }
                }

                if (EntitasEditorLayout.MatchesSearchString(systemInfo.systemName.ToLower(), _systemNameSearchString.ToLower()))
                {
                    EditorGUILayout.BeginHorizontal();
                    {
                        var indent = EditorGUI.indentLevel;
                        EditorGUI.indentLevel = 0;

                        var wasActive = systemInfo.isActive;
                        if (systemInfo.areAllParentsActive)
                        {
                            systemInfo.isActive = EditorGUILayout.Toggle(systemInfo.isActive, GUILayout.Width(20));
                        }
                        else
                        {
                            EditorGUI.BeginDisabledGroup(true);
                            {
                                EditorGUILayout.Toggle(false, GUILayout.Width(20));
                            }
                        }
                        EditorGUI.EndDisabledGroup();

                        EditorGUI.indentLevel = indent;

                        if (systemInfo.isActive != wasActive)
                        {
                            var reactiveSystem = systemInfo.system as IReactiveSystem;
                            if (reactiveSystem != null)
                            {
                                if (systemInfo.isActive)
                                {
                                    reactiveSystem.Activate();
                                }
                                else
                                {
                                    reactiveSystem.Deactivate();
                                }
                            }
                        }

                        switch (type)
                        {
                        case SystemInterfaceFlags.IInitializeSystem:
                            EditorGUILayout.LabelField(systemInfo.systemName, systemInfo.initializationDuration.ToString(), getSystemStyle(systemInfo, SystemInterfaceFlags.IInitializeSystem));
                            break;

                        case SystemInterfaceFlags.IExecuteSystem:
                            var avgE = string.Format("Ø {0:00.000}", systemInfo.averageExecutionDuration).PadRight(12);
                            var minE = string.Format("▼ {0:00.000}", systemInfo.minExecutionDuration).PadRight(12);
                            var maxE = string.Format("▲ {0:00.000}", systemInfo.maxExecutionDuration);
                            EditorGUILayout.LabelField(systemInfo.systemName, avgE + minE + maxE, getSystemStyle(systemInfo, SystemInterfaceFlags.IExecuteSystem));
                            break;

                        case SystemInterfaceFlags.ICleanupSystem:
                            var avgC = string.Format("Ø {0:00.000}", systemInfo.averageCleanupDuration).PadRight(12);
                            var minC = string.Format("▼ {0:00.000}", systemInfo.minCleanupDuration).PadRight(12);
                            var maxC = string.Format("▲ {0:00.000}", systemInfo.maxCleanupDuration);
                            EditorGUILayout.LabelField(systemInfo.systemName, avgC + minC + maxC, getSystemStyle(systemInfo, SystemInterfaceFlags.ICleanupSystem));
                            break;

                        case SystemInterfaceFlags.ITearDownSystem:
                            EditorGUILayout.LabelField(systemInfo.systemName, systemInfo.teardownDuration.ToString(), getSystemStyle(systemInfo, SystemInterfaceFlags.ITearDownSystem));
                            break;
                        }
                    }
                    EditorGUILayout.EndHorizontal();

                    systemsDrawn += 1;
                }

                var debugSystem = systemInfo.system as DebugSystems;
                if (debugSystem != null)
                {
                    var indent = EditorGUI.indentLevel;
                    EditorGUI.indentLevel += 1;
                    systemsDrawn          += drawSystemInfos(debugSystem, type);
                    EditorGUI.indentLevel  = indent;
                }
            }

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

            if (EntitasEditorLayout.MatchesSearchString(componentName.ToLower(), componentNameSearchString.ToLower()))
            {
                var boxStyle = getColoredBoxStyle(context, index);
                EditorGUILayout.BeginVertical(boxStyle);
                {
                    var memberInfos = componentType.GetPublicMemberInfos();
                    EditorGUILayout.BeginHorizontal();
                    {
                        if (memberInfos.Count == 0)
                        {
                            EditorGUILayout.LabelField(componentName, EditorStyles.boldLabel);
                        }
                        else
                        {
                            unfoldedComponents[index] = EntitasEditorLayout.Foldout(unfoldedComponents[index], componentName, foldoutStyle);
                            if (unfoldedComponents[index])
                            {
                                componentMemberSearch[index] = memberInfos.Count > 5
                                                                          ? EntitasEditorLayout.SearchTextField(componentMemberSearch[index])
                                                                          : string.Empty;
                            }
                        }
                        if (EntitasEditorLayout.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 (EntitasEditorLayout.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);
                        }
                    }
                }
                EntitasEditorLayout.EndVerticalBox();
            }
        }
Esempio n. 4
0
        public static void DrawComponent(bool[] unfoldedComponents, IEntity entity, int index, IComponent component)
        {
            var componentType = component.GetType();

            var componentName = componentType.Name.RemoveComponentSuffix();


            if (EntitasEditorLayout.MatchesSearchString(componentName.ToLower(), _componentNameSearchString.ToLower()))
            {
                var boxStyle = getColoredBoxStyle(entity.totalComponents, index);
                EntitasEditorLayout.BeginVerticalBox(boxStyle);
                {
                    var memberInfos = componentType.GetPublicMemberInfos();
                    EntitasEditorLayout.BeginHorizontal();
                    {
                        if (memberInfos.Count == 0)
                        {
                            EditorGUILayout.LabelField(componentName, EditorStyles.boldLabel);
                        }
                        else
                        {
                            unfoldedComponents[index] = EntitasEditorLayout.Foldout(unfoldedComponents[index], componentName, _foldoutStyle);
                        }
                        if (GUILayout.Button("-", GUILayout.Width(19), GUILayout.Height(14)))
                        {
                            entity.RemoveComponent(index);
                        }
                    }
                    EntitasEditorLayout.EndHorizontal();

                    if (unfoldedComponents[index])
                    {
                        var componentDrawer = getComponentDrawer(componentType);
                        if (componentDrawer != null)
                        {
                            var newComponent = entity.CreateComponent(index, componentType);
                            component.CopyPublicMemberValues(newComponent);
                            EditorGUI.BeginChangeCheck();
                            {
                                componentDrawer.DrawComponent(newComponent);
                            }
                            var changed = EditorGUI.EndChangeCheck();
                            if (changed)
                            {
                                entity.ReplaceComponent(index, newComponent);
                            }
                            else
                            {
                                entity.GetComponentPool(index).Push(newComponent);
                            }
                        }
                        else
                        {
                            foreach (var info in memberInfos)
                            {
                                DrawAndSetElement(info.type, info.name, info.GetValue(component),
                                                  entity, index, component, info.SetValue);
                            }
                        }
                    }
                }
                EntitasEditorLayout.EndVertical();
            }
        }
Esempio n. 5
0
        public object DrawAndGetNewValue(Type memberType, string memberName, object value, object target)
        {
            var dictionary = (IDictionary)value;
            var keyType    = memberType.GetGenericArguments()[0];
            var valueType  = memberType.GetGenericArguments()[1];
            var targetType = target.GetType();

            if (!_keySearchTexts.ContainsKey(targetType))
            {
                _keySearchTexts.Add(targetType, string.Empty);
            }

            EditorGUILayout.BeginHorizontal();
            {
                if (dictionary.Count == 0)
                {
                    EditorGUILayout.LabelField(memberName, "empty");
                    _keySearchTexts[targetType] = string.Empty;
                }
                else
                {
                    EditorGUILayout.LabelField(memberName);
                }

                var keyTypeName   = keyType.ToCompilableString().ShortTypeName();
                var valueTypeName = valueType.ToCompilableString().ShortTypeName();
                if (EntitasEditorLayout.MiniButton("new <" + keyTypeName + ", " + valueTypeName + ">"))
                {
                    object defaultKey;
                    if (EntityDrawer.CreateDefault(keyType, out defaultKey))
                    {
                        object defaultValue;
                        if (EntityDrawer.CreateDefault(valueType, out defaultValue))
                        {
                            dictionary[defaultKey] = defaultValue;
                        }
                    }
                }
            }
            EditorGUILayout.EndHorizontal();

            if (dictionary.Count > 0)
            {
                var indent = EditorGUI.indentLevel;
                EditorGUI.indentLevel = indent + 1;

                if (dictionary.Count > 5)
                {
                    EditorGUILayout.Space();
                    _keySearchTexts[targetType] = EntitasEditorLayout.SearchTextField(_keySearchTexts[targetType]);
                }

                EditorGUILayout.Space();

                var keys = new ArrayList(dictionary.Keys);
                for (int i = 0; i < keys.Count; i++)
                {
                    var key = keys[i];
                    if (EntitasEditorLayout.MatchesSearchString(key.ToString().ToLower(), _keySearchTexts[targetType].ToLower()))
                    {
                        EntityDrawer.DrawObjectMember(keyType, "key", key,
                                                      target, (newComponent, newValue) => {
                            var tmpValue = dictionary[key];
                            dictionary.Remove(key);
                            if (newValue != null)
                            {
                                dictionary[newValue] = tmpValue;
                            }
                        });

                        EntityDrawer.DrawObjectMember(valueType, "value", dictionary[key],
                                                      target, (newComponent, newValue) => dictionary[key] = newValue);

                        EditorGUILayout.Space();
                    }
                }

                EditorGUI.indentLevel = indent;
            }

            return(dictionary);
        }