private IList DrawAddElement(IList list, string memberName, Type elementType)
        {
            EditorGUILayout.BeginHorizontal();
            {
                EditorGUILayout.LabelField(memberName, "empty");
                if (EditorGUILayoutTools.MiniButton("add " + elementType.ToCompilableString().ShortTypeName()))
                {
                    if (EntityDrawer.CreateDefault(elementType, out var defaultValue))
                    {
                        list.Add(defaultValue);
                    }
                }
            }
            EditorGUILayout.EndHorizontal();

            return(list);
        }
Exemple #2
0
        /*
         *
         * Rank 1
         *
         */

        private Array DrawRank1(Array array, string memberName, Type elementType, int indent, object target)
        {
            var length = array.GetLength(0);

            if (length == 0)
            {
                array = DrawAddElement(array, memberName, elementType);
            }
            else
            {
                EditorGUILayout.LabelField(memberName);
            }

            EditorGUI.indentLevel = indent + 1;

            Func <Array> editAction = null;

            for (var i = 0; i < length; i++)
            {
                var localIndex = i;
                EditorGUILayout.BeginHorizontal();
                {
                    EntityDrawer.DrawObjectMember(
                        elementType,
                        memberName + "[" + localIndex + "]",
                        array.GetValue(localIndex),
                        target,
                        (newComponent, newValue) => array.SetValue(newValue, localIndex));

                    var action = DrawEditActions(array, elementType, localIndex);
                    if (action != null)
                    {
                        editAction = action;
                    }
                }
                EditorGUILayout.EndHorizontal();
            }

            if (editAction != null)
            {
                array = editAction();
            }

            return(array);
        }
Exemple #3
0
        private Array DrawAddElement(Array array, string memberName, Type elementType)
        {
            EditorGUILayout.BeginHorizontal();
            {
                EditorGUILayout.LabelField(memberName, "empty");
                if (EditorGUILayoutTools.MiniButton("add " + elementType.ToCompilableString().ShortTypeName()))
                {
                    if (EntityDrawer.CreateDefault(elementType, out var defaultValue))
                    {
                        var newArray = Array.CreateInstance(elementType, 1);
                        newArray.SetValue(defaultValue, 0);
                        array = newArray;
                    }
                }
            }
            EditorGUILayout.EndHorizontal();

            return(array);
        }
        public override void OnInspectorGUI()
        {
            if (targets.Length == 1)
            {
                var entityBehaviour = (EntityBehaviour)target;
                EntityDrawer.DrawEntity(entityBehaviour.Entity);
            }
            else
            {
                var entities = targets
                               .Select(t => ((EntityBehaviour)t).Entity)
                               .ToArray();

                EntityDrawer.DrawMultipleEntities(entities);
            }

            if (target != null)
            {
                EditorUtility.SetDirty(target);
            }
        }
Exemple #5
0
        /*
         *
         * Rank 2
         *
         */

        private Array DrawRank2(Array array, string memberName, Type elementType, object target)
        {
            EditorGUILayout.LabelField(memberName);

            for (var i = 0; i < array.GetLength(0); i++)
            {
                var localIndex1 = i;
                for (var j = 0; j < array.GetLength(1); j++)
                {
                    var localIndex2 = j;
                    EntityDrawer.DrawObjectMember(
                        elementType,
                        memberName + "[" + localIndex1 + ", " + localIndex2 + "]",
                        array.GetValue(localIndex1, localIndex2),
                        target,
                        (newComponent, newValue) => array.SetValue(newValue, localIndex1, localIndex2));
                }

                EditorGUILayout.Space();
            }

            return(array);
        }
        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 (EditorGUILayoutTools.MiniButton("new <" + keyTypeName + ", " + valueTypeName + ">"))
                {
                    if (EntityDrawer.CreateDefault(keyType, out var defaultKey))
                    {
                        if (EntityDrawer.CreateDefault(valueType, out var 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] = EditorGUILayoutTools.SearchTextField(_keySearchTexts[targetType]);
                }

                EditorGUILayout.Space();

                var keys = new ArrayList(dictionary.Keys);
                for (var i = 0; i < keys.Count; i++)
                {
                    var key = keys[i];
                    if (EditorGUILayoutTools.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);
        }
        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 (EditorGUILayoutTools.MiniButton("new " + elementType.ToCompilableString().ShortTypeName()))
                {
                    if (EntityDrawer.CreateDefault(elementType, out var 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 (EditorGUILayoutTools.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);
        }