예제 #1
0
        //bool bUnfolded = false;
        /// <summary>
        /// Draws the component.
        /// </summary>
        /// <param name="com">COM.</param>
        void DrawComponent(IZComponent com)
        {
            int iconSize = (int)EditorGUIUtility.singleLineHeight;
            //draw component member
            Rect rect        = EditorGUILayout.BeginVertical(entityStyle);
            Type ty          = com.GetType();
            var  memberInfos = ty.GetPublicMemberInfos();

            bool bUnfolded = poolConfig.unfoldMap.IsUnfold(curEntity.Name + ty.Name);

            //SerializedProperty unfoledObj = serializedObject.FindProperty ("unfoldMap");

            //draw component file info
            EditorGUILayout.BeginHorizontal();
            {
                if (memberInfos.Count == 0)
                {
                    EditorGUILayout.LabelField("    " + ty.Name, EditorStyles.boldLabel);
                }
                else
                {
                    bool bNewUnfold = EditorLayout.Foldout(bUnfolded, ty.Name, iconSize + 10);
                    //EditorGUILayout.LabelField(ty.Name, EditorStyles.boldLabel);
                    if (bNewUnfold != bUnfolded)
                    {
                        poolConfig.unfoldMap.SetUnfold(curEntity.Name + ty.Name, bNewUnfold);

//						unfoldObj.Update();
//						unfoldObj.ApplyModifiedProperties ();
                    }
                }
                if (EditorLayout.MiniButton("-"))
                {
                    //entity.RemoveComponent(index);
                    curEntity.DelComponent(com);
                }
            }
            EditorGUILayout.EndHorizontal();

            //Draw the icon
            if (ComponentsPool <IZComponent> .IsSystem(com))
            {
                GUI.DrawTexture(new Rect(rect.x + 1, rect.y + 1,
                                         iconSize - 2, iconSize - 2), IconHelper.SystemsHierarchyIcon);
            }
            else
            {
                GUI.DrawTexture(new Rect(rect.x + 1, rect.y + 1,
                                         iconSize - 2, iconSize - 2), IconHelper.EntityHierarchyIcon);
            }


            if (bUnfolded)
            {
                InspectorDrawer.DrawObjectMember(com);
            }

            EditorGUILayout.EndVertical();
        }
예제 #2
0
        public static void DrawMultipleEntities(IContext context, IEntity[] entities)
        {
            EditorGUILayout.Space();
            EditorGUILayout.BeginHorizontal();
            {
                var entity = entities[0];
                var index  = drawAddComponentMenu(context, entity);
                if (index >= 0)
                {
                    var componentType = entity.contextInfo.componentTypes[index];
                    foreach (var e in entities)
                    {
                        var component = e.CreateComponent(index, componentType);
                        e.AddComponent(index, component);
                    }
                }
            }
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.Space();

            var bgColor = GUI.backgroundColor;

            GUI.backgroundColor = Color.red;

            if (GUILayout.Button("Destroy selected entities"))
            {
                foreach (var e in entities)
                {
                    e.Destroy();
                }
            }

            GUI.backgroundColor = bgColor;

            EditorGUILayout.Space();

            foreach (var e in entities)
            {
                EditorGUILayout.BeginHorizontal();
                {
                    EditorGUILayout.LabelField(e.ToString());

                    bgColor             = GUI.backgroundColor;
                    GUI.backgroundColor = Color.red;

                    if (EditorLayout.MiniButton("Destroy Entity"))
                    {
                        e.Destroy();
                    }

                    GUI.backgroundColor = bgColor;
                }
                EditorGUILayout.EndHorizontal();
            }
        }
예제 #3
0
        IList drawAddElement(IList list, string memberName, Type elementType)
        {
            EditorGUILayout.BeginHorizontal();
            {
                EditorGUILayout.LabelField(memberName, "empty");
                if (EditorLayout.MiniButton("add " + elementType.ToCompilableString().ShortTypeName()))
                {
                    object defaultValue;
                    if (EntityDrawer.CreateDefault(elementType, out defaultValue))
                    {
                        list.Add(defaultValue);
                    }
                }
            }
            EditorGUILayout.EndHorizontal();

            return(list);
        }
예제 #4
0
        Array drawAddElement(Array array, string memberName, Type elementType)
        {
            EditorGUILayout.BeginHorizontal();
            {
                EditorGUILayout.LabelField(memberName, "empty");
                if (EditorLayout.MiniButton("add " + elementType.ToCompilableString().ShortTypeName()))
                {
                    object defaultValue;
                    if (EntityDrawer.CreateDefault(elementType, out defaultValue))
                    {
                        var newArray = Array.CreateInstance(elementType, 1);
                        newArray.SetValue(defaultValue, 0);
                        array = newArray;
                    }
                }
            }
            EditorGUILayout.EndHorizontal();

            return(array);
        }
예제 #5
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);

            var safeAerc = entity.aerc as SafeAERC;

            if (safeAerc != null)
            {
                EditorLayout.BeginVerticalBox();
                {
                    foreach (var owner in safeAerc.owners.OrderBy(o => o.GetType().Name))
                    {
                        EditorGUILayout.BeginHorizontal();
                        {
                            EditorGUILayout.LabelField(owner.ToString());
                            if (EditorLayout.MiniButton("Release"))
                            {
                                entity.Release(owner);
                            }

                            EditorGUILayout.EndHorizontal();
                        }
                    }
                }
                EditorLayout.EndVerticalBox();
            }
        }
        void drawTypeDrawerFolder()
        {
            EditorGUILayout.BeginHorizontal();
            {
                var path = EditorLayout.ObjectFieldOpenFolderPanel(
                    "Type Drawers",
                    _visualDebuggingConfig.typeDrawerFolderPath,
                    _visualDebuggingConfig.typeDrawerFolderPath
                    );
                if (!string.IsNullOrEmpty(path))
                {
                    _visualDebuggingConfig.typeDrawerFolderPath = path;
                }

                if (EditorLayout.MiniButton("New"))
                {
                    EntityDrawer.GenerateITypeDrawer("MyType");
                }
            }
            EditorGUILayout.EndHorizontal();
        }
        public override void OnInspectorGUI()
        {
            var binaryBlueprint = ((BinaryBlueprint)target);

            EditorGUI.BeginChangeCheck();
            {
                EditorGUILayout.LabelField("Blueprint", EditorStyles.boldLabel);
                binaryBlueprint.name = EditorGUILayout.TextField("Name", binaryBlueprint.name);

                if (_context != null)
                {
                    EditorGUILayout.BeginHorizontal();
                    {
                        _contextIndex = EditorGUILayout.Popup(_contextIndex, _allContextNames);

                        if (EditorLayout.MiniButton("Switch Context"))
                        {
                            switchToContext();
                        }
                    }
                    EditorGUILayout.EndHorizontal();

                    EntityDrawer.DrawComponents(_entity);
                }
                else
                {
                    EditorGUILayout.LabelField("No contexts found!");
                }
            }
            var changed = EditorGUI.EndChangeCheck();

            if (changed)
            {
                binaryBlueprint.Serialize(_entity);
                AssetDatabase.RenameAsset(AssetDatabase.GetAssetPath(target), binaryBlueprint.name);
                EditorUtility.SetDirty(target);
            }
        }
예제 #8
0
 static void drawUnsupportedType(Type memberType, string memberName, object value)
 {
     EditorGUILayout.BeginHorizontal();
     {
         EditorGUILayout.LabelField(memberName, value.ToString());
         if (EditorLayout.MiniButton("Missing ITypeDrawer"))
         {
             var typeName = memberType.ToCompilableString();
             if (EditorUtility.DisplayDialog(
                     "No ITypeDrawer found",
                     "There's no ITypeDrawer implementation to handle the type '" + typeName + "'.\n" +
                     "Providing an ITypeDrawer enables you draw instances for that type.\n\n" +
                     "Do you want to generate an ITypeDrawer implementation for '" + typeName + "'?\n",
                     "Generate",
                     "Cancel"
                     ))
             {
                 GenerateITypeDrawer(typeName);
             }
         }
     }
     EditorGUILayout.EndHorizontal();
 }
예제 #9
0
        public static bool DrawObjectMember(Type memberType, string memberName, object value, object target, Action <object, object> setValue)
        {
            if (value == null)
            {
                EditorGUI.BeginChangeCheck();
                {
                    var isUnityObject = memberType == typeof(UnityEngine.Object) || memberType.IsSubclassOf(typeof(UnityEngine.Object));
                    EditorGUILayout.BeginHorizontal();
                    {
                        if (isUnityObject)
                        {
                            setValue(target, EditorGUILayout.ObjectField(memberName, (UnityEngine.Object)value, memberType, true));
                        }
                        else
                        {
                            EditorGUILayout.LabelField(memberName, "null");
                        }

                        if (EditorLayout.MiniButton("new " + memberType.ToCompilableString().ShortTypeName()))
                        {
                            object defaultValue;
                            if (CreateDefault(memberType, out defaultValue))
                            {
                                setValue(target, defaultValue);
                            }
                        }
                    }
                    EditorGUILayout.EndHorizontal();
                }

                return(EditorGUI.EndChangeCheck());
            }

            if (!memberType.IsValueType)
            {
                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.BeginVertical();
            }

            EditorGUI.BeginChangeCheck();
            {
                var typeDrawer = getTypeDrawer(memberType);
                if (typeDrawer != null)
                {
                    var newValue = typeDrawer.DrawAndGetNewValue(memberType, memberName, value, target);
                    setValue(target, newValue);
                }
                else
                {
                    var targetType = target.GetType();
                    var shouldDraw = !targetType.ImplementsInterface <IComponent>() || !Attribute.IsDefined(targetType, typeof(DontDrawComponentAttribute));
                    if (shouldDraw)
                    {
                        EditorGUILayout.LabelField(memberName, value.ToString());

                        var indent = EditorGUI.indentLevel;
                        EditorGUI.indentLevel += 1;

                        EditorGUILayout.BeginVertical();
                        {
                            foreach (var info in memberType.GetPublicMemberInfos())
                            {
                                var mValue = info.GetValue(value);
                                var mType  = mValue == null ? info.type : mValue.GetType();
                                DrawObjectMember(mType, info.name, mValue, value, info.SetValue);
                                if (memberType.IsValueType)
                                {
                                    setValue(target, value);
                                }
                            }
                        }
                        EditorGUILayout.EndVertical();

                        EditorGUI.indentLevel = indent;
                    }
                    else
                    {
                        drawUnsupportedType(memberType, memberName, value);
                    }
                }

                if (!memberType.IsValueType)
                {
                    EditorGUILayout.EndVertical();
                    if (EditorLayout.MiniButton("×"))
                    {
                        setValue(target, null);
                    }
                    EditorGUILayout.EndHorizontal();
                }
            }

            return(EditorGUI.EndChangeCheck());
        }
예제 #10
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 (EditorLayout.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] = EditorLayout.Foldout(unfoldedComponents[index], componentName, foldoutStyle);
                            if (unfoldedComponents[index])
                            {
                                componentMemberSearch[index] = memberInfos.Count > 5
                                    ? EditorLayout.SearchTextField(componentMemberSearch[index])
                                    : string.Empty;
                            }
                        }
                        if (EditorLayout.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 (EditorLayout.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);
                        }
                    }
                }
                EditorLayout.EndVerticalBox();
            }
        }
예제 #11
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 (EditorLayout.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] = EditorLayout.SearchTextField(_keySearchTexts[targetType]);
                }

                EditorGUILayout.Space();

                var keys = new ArrayList(dictionary.Keys);
                for (int i = 0; i < keys.Count; i++)
                {
                    var key = keys[i];
                    if (EditorLayout.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);
        }
예제 #12
0
        public object DrawAndGetNewValue(Type memberType, string memberName, object value, object target)
        {
            var elementType   = memberType.GetGenericArguments()[0];
            var itemsToRemove = new ArrayList();
            var itemsToAdd    = new ArrayList();
            var isEmpty       = !((IEnumerable)value).GetEnumerator().MoveNext();

            EditorGUILayout.BeginHorizontal();
            {
                if (isEmpty)
                {
                    EditorGUILayout.LabelField(memberName, "empty");
                }
                else
                {
                    EditorGUILayout.LabelField(memberName);
                }

                if (EditorLayout.MiniButton("new " + elementType.ToCompilableString().ShortTypeName()))
                {
                    object defaultValue;
                    if (EntityDrawer.CreateDefault(elementType, out defaultValue))
                    {
                        itemsToAdd.Add(defaultValue);
                    }
                }
            }
            EditorGUILayout.EndHorizontal();

            if (!isEmpty)
            {
                EditorGUILayout.Space();
                var indent = EditorGUI.indentLevel;
                EditorGUI.indentLevel = indent + 1;
                foreach (var item in (IEnumerable)value)
                {
                    EditorGUILayout.BeginHorizontal();
                    {
                        EntityDrawer.DrawObjectMember(elementType, string.Empty, item,
                                                      target, (newComponent, newValue) => {
                            itemsToRemove.Add(item);
                            itemsToAdd.Add(newValue);
                        });

                        if (EditorLayout.MiniButton("-"))
                        {
                            itemsToRemove.Add(item);
                        }
                    }
                    EditorGUILayout.EndHorizontal();
                }

                EditorGUI.indentLevel = indent;
            }

            foreach (var item in itemsToRemove)
            {
                memberType.GetMethod("Remove").Invoke(value, new[] { item });
            }

            foreach (var item in itemsToAdd)
            {
                memberType.GetMethod("Add").Invoke(value, new[] { item });
            }

            return(value);
        }