Ejemplo n.º 1
0
        public static void DrawMultipleEntities(IContext context, IEntity[] entities)
        {
            EditorGUILayout.Space();
            EditorGUILayout.BeginHorizontal();
            {
                var entity = entities[0];
                var index  = drawAddComponentMenu(context);
                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 (EntitasEditorLayout.MiniButton("Destroy Entity"))
                    {
                        e.Destroy();
                    }

                    GUI.backgroundColor = bgColor;
                }
                EditorGUILayout.EndHorizontal();
            }
        }
Ejemplo n.º 2
0
        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();
            }
        }
Ejemplo n.º 3
0
        IList drawAddElement(IList list, string memberName, Type elementType)
        {
            EditorGUILayout.BeginHorizontal();
            {
                EditorGUILayout.LabelField(memberName, "empty");
                if (EntitasEditorLayout.MiniButton("add " + elementType.ToCompilableString().ShortTypeName()))
                {
                    object defaultValue;
                    if (EntityDrawer.CreateDefault(elementType, out defaultValue))
                    {
                        list.Add(defaultValue);
                    }
                }
            }
            EditorGUILayout.EndHorizontal();

            return(list);
        }
Ejemplo n.º 4
0
        Array drawAddElement(Array array, string memberName, Type elementType)
        {
            EditorGUILayout.BeginHorizontal();
            {
                EditorGUILayout.LabelField(memberName, "empty");
                if (EntitasEditorLayout.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);
        }
Ejemplo n.º 5
0
        protected override void drawContent(Preferences preferences)
        {
            EditorGUILayout.BeginHorizontal();
            {
                EditorGUILayout.LabelField("Auto Import Plugins");
                if (EntitasEditorLayout.MiniButton("Auto Import"))
                {
                    autoImport();
                }
            }
            EditorGUILayout.EndHorizontal();

            _codeGeneratorConfig.dataProviders  = drawMaskField("Data Providers", _availableDataProviderTypes, _availableDataProviderNames, _codeGeneratorConfig.dataProviders);
            _codeGeneratorConfig.codeGenerators = drawMaskField("Code Generators", _availableGeneratorTypes, _availableGeneratorNames, _codeGeneratorConfig.codeGenerators);
            _codeGeneratorConfig.postProcessors = drawMaskField("Post Processors", _availablePostProcessorTypes, _availablePostProcessorNames, _codeGeneratorConfig.postProcessors);

            EditorGUILayout.Space();
            drawConfigurables();

            drawGenerateButton();
        }
Ejemplo n.º 6
0
        public static void DrawEntity(IContext context, IEntity entity)
        {
            var bgColor = GUI.backgroundColor;

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

            DrawComponents(context, entity);

            EditorGUILayout.Space();

            EditorGUILayout.IntField("CreationIndex", entity.creationIndex);
            EditorGUILayout.LabelField("Retained by (" + entity.retainCount + ")", EditorStyles.boldLabel);

            var safeAerc = entity.aerc as SafeAERC;

            if (safeAerc != null)
            {
                EntitasEditorLayout.BeginVerticalBox();
                {
                    foreach (var owner in safeAerc.owners.OrderBy(o => o.GetType().Name))
                    {
                        EditorGUILayout.BeginHorizontal();
                        {
                            EditorGUILayout.LabelField(owner.ToString());
                            if (EntitasEditorLayout.MiniButton("Release"))
                            {
                                entity.Release(owner);
                            }
                            EditorGUILayout.EndHorizontal();
                        }
                    }
                }
                EntitasEditorLayout.EndVerticalBox();
            }
        }
Ejemplo n.º 7
0
        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 (EntitasEditorLayout.MiniButton("Switch Context"))
                        {
                            switchToContext();
                        }
                    }
                    EditorGUILayout.EndHorizontal();

                    EntityDrawer.DrawComponents(_context, _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);
            }
        }
Ejemplo n.º 8
0
 static void drawUnsupportedType(Type memberType, string memberName, object value)
 {
     EditorGUILayout.BeginHorizontal();
     {
         EditorGUILayout.LabelField(memberName, value.ToString());
         if (EntitasEditorLayout.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();
 }
Ejemplo n.º 9
0
        public static void DrawEntity(IContext context, IEntity entity)
        {
            var bgColor = GUI.backgroundColor;

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

            DrawComponents(context, entity);

            EditorGUILayout.Space();

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

            #if !ENTITAS_FAST_AND_UNSAFE
            EntitasEditorLayout.BeginVerticalBox();
            {
                foreach (var owner in entity.owners.OrderBy(o => o.GetType().Name))
                {
                    EditorGUILayout.BeginHorizontal();
                    {
                        EditorGUILayout.LabelField(owner.ToString());
                        if (EntitasEditorLayout.MiniButton("Release"))
                        {
                            entity.Release(owner);
                        }
                        EditorGUILayout.EndHorizontal();
                    }
                }
            }
            EntitasEditorLayout.EndVerticalBox();
            #endif
        }
Ejemplo n.º 10
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 (EntitasEditorLayout.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 (EntitasEditorLayout.MiniButton("×"))
                    {
                        setValue(target, null);
                    }
                    EditorGUILayout.EndHorizontal();
                }
            }

            return(EditorGUI.EndChangeCheck());
        }
Ejemplo n.º 11
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();
            }
        }
Ejemplo n.º 12
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);
        }
Ejemplo n.º 13
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 (EntitasEditorLayout.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 (EntitasEditorLayout.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);
        }
Ejemplo n.º 14
0
        public static bool DrawComponentMember(Type memberType, string memberName, object value, IComponent component, Action <IComponent, object> setValue)
        {
            if (value == null)
            {
                EditorGUI.BeginChangeCheck();
                {
                    var isUnityObject = memberType == typeof(UnityEngine.Object) || memberType.IsSubclassOf(typeof(UnityEngine.Object));
                    EditorGUILayout.BeginHorizontal();
                    {
                        if (isUnityObject)
                        {
                            setValue(component, EditorGUILayout.ObjectField(memberName, (UnityEngine.Object)value, memberType, true));
                        }
                        else
                        {
                            EditorGUILayout.LabelField(memberName, "null");
                        }

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

                return(EditorGUI.EndChangeCheck());
            }

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

            EditorGUI.BeginChangeCheck();
            {
                var typeDrawer = getTypeDrawer(memberType);
                if (typeDrawer != null)
                {
                    setValue(component, typeDrawer.DrawAndGetNewValue(memberType, memberName, value, component));
                }
                else
                {
                    drawUnsupportedType(memberType, memberName, value);
                    EditorGUILayout.BeginVertical();
                    {
                        EditorGUILayout.Space();
                        var infos = memberType.GetPublicMemberInfos();
                        for (int i = 0; i < infos.Count; i++)
                        {
                            var info = infos[i];
                            EditorGUILayout.LabelField(info.name, info.GetValue(value).ToString());
                        }
                    }
                    EditorGUILayout.EndVertical();
                }

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

            return(EditorGUI.EndChangeCheck());
        }