Exemple #1
0
        /// <summary>
        ///   Gets inspector data such as name and description for the
        ///   specified type.
        /// </summary>
        /// <param name="type">Type to get inspector data for.</param>
        /// <param name="conditionalInspectors">Dictionary to be filled with conditions for inspectors to be shown.</param>
        /// <returns>Inspector data for the specified type.</returns>
        public static InspectorType GetInspectorType(
            Type type,
            ref Dictionary <InspectorPropertyAttribute, InspectorConditionalPropertyAttribute> conditionalInspectors)
        {
            List <InspectorPropertyAttribute> inspectorProperties = InspectorUtils.CollectInspectorProperties(
                type, ref conditionalInspectors);

            var inspectorTypeAttribute = type.GetAttribute <InspectorTypeAttribute>();

            if (inspectorTypeAttribute == null)
            {
                return(null);
            }

            var inspectorTypeData = new InspectorType
            {
                Attribute   = inspectorTypeAttribute,
                Name        = type.Name,
                Description = inspectorTypeAttribute.Description,
                Properties  = inspectorProperties,
                Type        = type,
            };

            return(inspectorTypeData);
        }
    void OnGUI()
    {
        EditorGUILayout.BeginVertical();

        EditorGUILayout.PrefixLabel("Target cubemap");

        m_Cubemap = EditorGUILayout.ObjectField(m_Cubemap, typeof(Cubemap), false) as Cubemap;

        EditorGUILayout.EndVertical();


        GUILayout.BeginVertical();

        InspectorUtils.VizualizeList(ref m_Lights, true);

        if (GUILayout.Button("Bake", GUILayout.MinWidth(120)))
        {
            if (m_Cubemap)
            {
                Process();
            }
        }

        GUILayout.EndVertical();
    }
Exemple #3
0
        private void HandleField(SerializedProperty fieldProperty, Type targetType)
        {
            FieldInfo field = targetType.GetField(fieldProperty.name);

            if (field == null)
            {
                return;
            }
            if (field.FieldType == typeof(Environment))
            {
                if (EditorApplication.isPlaying)
                {
                    GUI.enabled = false;
                }
                EditorGUILayout.PropertyField(fieldProperty, true);
                Environment env = (Environment)field.GetValue(serializedObject.targetObject);

                string mappingConfigName = env == Environment.Cave ? "CaveInputBinding" : "PCInputBinding";
                var    mappingProperty   = serializedObject.FindProperty(mappingConfigName);
                InspectorUtils.DrawField(targetType.GetField(mappingConfigName), mappingProperty, serializedObject.targetObject);
                GUI.enabled = true;
            }
            else if (!typeof(InputBinding).IsAssignableFrom(field.FieldType))
            {
                EditorGUILayout.PropertyField(fieldProperty, true);
            }
        }
Exemple #4
0
    public override void OnInspectorGUI()
    {
        EditorGUILayout.Space();
        currentVision = (VisionType)EditorGUILayout.EnumPopup("View: ", currentVision);
        EditorGUILayout.Space();
        switch (currentVision)
        {
        case VisionType.Standard:
        {
            base.OnInspectorGUI();
            if (GUILayout.Button("Rebuild Grid"))
            {
                builder.Grid.RebuildGridComponent();
            }
            break;
        }

        case VisionType.TowerList:
        {
            InspectorUtils.ShowTowerList(builder.TowersToBuild);
            break;
        }
        }
        EditorGUILayout.Space();
    }
Exemple #5
0
 public void DrawInInspector(SerializedProperty property)
 {
     InspectorUtils.DrawObject(property, () => {
         EditorGUILayout.PropertyField(property.FindPropertyRelative("ButtonType"), false);
         EditorGUILayout.PropertyField(property.FindPropertyRelative(ButtonType == ButtonType.Mouse ? "MouseButton" : "KeyboardButton"), false);
     });
 }
        private void DrawCondition(Rect rect, SerializedProperty element, GUIContent label, int index, bool selected, bool focused)
        {
            Condition condition   = null;
            string    description = string.Empty;

            if (element.objectReferenceValue != null)
            {
                condition   = element.GetAs <Condition>();
                description = condition.GetDescription();
            }

            rect.x     += 10;
            rect.width -= 10;
            var foldoutRect = rect;

            foldoutRect.height = GenericParamUtils.FieldHeight;

            var backgroundRect = rect;

            backgroundRect.x     -= 29;
            backgroundRect.y     -= 1;
            backgroundRect.width += 33;
            backgroundRect.height = 20;

            var oldColor = GUI.color;

            GUI.color = Color.Lerp(new Color(1, 1, 1, 0), Color.white, 0.75f);
            GUI.Box(backgroundRect, GUIContent.none, SpaceEditorStyles.LightBox);
            GUI.color = oldColor;

            element.isExpanded = EditorGUI.Foldout(foldoutRect, element.isExpanded, new GUIContent(description), true);
            if (element.isExpanded)
            {
                rect.y      += GenericParamUtils.FieldHeight + 4;
                rect.height -= GenericParamUtils.FieldHeight + 2;

                if (condition)
                {
                    if (InspectorUtils.DrawDefaultInspector(rect, new SerializedObject(condition)))
                    {
                        if (element.serializedObject != null &&
                            element.serializedObject.targetObject != null)
                        {
                            EditorUtility.SetDirty(element.serializedObject.targetObject);
                        }
                    }
                }

                {
                    /*GUILayout.BeginArea(rect);
                     *
                     * if (InspectorUtils.DrawDefaultInspectorWithoutScriptField(new SerializedObject(condition)))
                     * {
                     *  EditorUtility.SetDirty(CurrentProperty.serializedObject.targetObject);
                     * }
                     *
                     * GUILayout.EndArea();*/
                }
            }
        }
Exemple #7
0
        public void TestDeinitRemovesChildEntity()
        {
            var              entityManager   = this.testGame.EntityManager;
            const string     TestBlueprintId = "TestBlueprint";
            BlueprintManager blueprintManager;

            this.testGame.BlueprintManager = blueprintManager = new BlueprintManager();
            blueprintManager.AddBlueprint(TestBlueprintId, new Blueprint());

            TestInspectorTypeWithEntityProperty testType = new TestInspectorTypeWithEntityProperty();
            var                 testInspectorType        = InspectorType.GetInspectorType(typeof(TestInspectorTypeWithEntityProperty));
            IAttributeTable     configuration            = new AttributeTable();
            EntityConfiguration childConfiguration       = new EntityConfiguration {
                BlueprintId = TestBlueprintId
            };

            configuration.SetValue(TestInspectorTypeWithEntityProperty.AttributeMember1, childConfiguration);

            // Init.
            InspectorUtils.InitFromAttributeTable(entityManager, testInspectorType, testType, configuration);

            // Check that child entity was created.
            Assert.AreNotEqual(0, testType.EntityMember);

            // Deinit.
            InspectorUtils.Deinit(entityManager, testInspectorType, testType);

            // Check that child entity was removed.
            Assert.IsTrue(entityManager.EntityIsBeingRemoved(testType.EntityMember));
        }
        private void DrawType()
        {
            List <ReflectionInfo> cache;

            Cache.TryGetTarget(out cache);

            InspectorUtils.DrawDefaultScriptField(serializedObject);

            EditorGUI.BeginChangeCheck();
            {
                foreach (ReflectionInfo info in cache)
                {
                    var property = serializedObject.FindProperty(info.Info.Name);
                    if (property != null)
                    {
                        DrawField(info, property);
                    }
                    else
                    {
                        DrawProperty(info);
                    }
                }
            }
            if (EditorGUI.EndChangeCheck())
            {
                (target as IBaseObject)?.OnPostValidate();
            }
        }
Exemple #9
0
        public void TestInitFromNullAttributeTable()
        {
            TestInspectorType testInspectorType = new TestInspectorType();

            Assert.DoesNotThrow(
                () => InspectorUtils.InitFromAttributeTable(this.testGame.EntityManager, testInspectorType, null));
        }
Exemple #10
0
 // Use this for initialization
 void Start()
 {
     ins        = Camera.main.GetComponent <Inspector>();
     spawnOBJ   = Camera.main.GetComponent <SpawnObject>();
     insu       = new InspectorUtils();
     keyHandler = Camera.main.GetComponent <KeyHandler>();
 }
        public void TestDeserializationFromAttributeTable()
        {
            IAttributeTable attributeTable       = new AttributeTable();
            AttributeTable  entityAttributeTable = new AttributeTable();
            const string    TestValueString      = "Test";

            entityAttributeTable.SetValue(TestComponent.AttributeTestString, TestValueString);
            EntityConfiguration entityConfiguration = new EntityConfiguration
            {
                BlueprintId   = TestBlueprintId,
                Configuration = entityAttributeTable
            };

            attributeTable.SetValue(TestData.AttributeTestEntity, entityConfiguration);

            TestData testData = InspectorUtils.CreateFromAttributeTable <TestData>(
                this.testGame.EntityManager, InspectorType.GetInspectorType(typeof(TestData)), attributeTable);

            Assert.AreNotEqual(testData.TestEntity, 0);
            Assert.AreNotEqual(testData.TestEntity, -1);

            // Check entity.
            TestComponent testComponent = this.testGame.EntityManager.GetComponent <TestComponent>(testData.TestEntity);

            Assert.NotNull(testComponent);
            Assert.AreEqual(testComponent.TestString, TestValueString);
        }
Exemple #12
0
 public void DrawInInspector(SerializedProperty property)
 {
     InspectorUtils.DrawObject(property, () => {
         EditorGUILayout.PropertyField(property.FindPropertyRelative("ReverseAxisDirection"), false);
         InspectorUtils.DrawField(GetType().GetField("PositiveButton"), property.FindPropertyRelative("PositiveButton"), this);
         InspectorUtils.DrawField(GetType().GetField("NegativeButton"), property.FindPropertyRelative("NegativeButton"), this);
     });
 }
Exemple #13
0
        private float GetConditionHeight(SerializedProperty property, int index)
        {
            if (property.isExpanded && property.objectReferenceValue != null)
            {
                var condition = property.GetAs <Condition>();
                return(EditorGUIUtility.singleLineHeight + InspectorUtils.GetDefaultInspectorHeight(new SerializedObject(condition)));
            }

            return(GenericParamUtils.FieldHeight);
        }
Exemple #14
0
    //TODO fix the problem with collison

    // Use this for initialization
    void Start()
    {
        viewCamera = Camera.main;         //get the camera
        keyHandler = viewCamera.GetComponent <KeyHandler>();
        insu       = new InspectorUtils();
        transformPanel.SetActive(true);
        propertiesPanel.SetActive(false);
        transformButton.gameObject.GetComponent <Image>().color  = Color.white;
        propertiesButton.gameObject.GetComponent <Image>().color = new Color32(141, 141, 142, 100);
    }
Exemple #15
0
 public void DrawInInspector(SerializedProperty property)
 {
     InspectorUtils.DrawObject(property, () => {
         foreach (var field in GetType().GetFields())
         {
             var fieldProperty = property.FindPropertyRelative(field.Name);
             InspectorUtils.DrawField(field, fieldProperty, this);
         }
     });
 }
        /// <summary>
        ///   Initializes the specified object via reflection with the specified property value.
        /// </summary>
        /// <param name="entityManager">Entity manager.</param>
        /// <param name="obj">Object to set property value for.</param>
        /// <param name="propertyValue">Property value to set.</param>
        public override void SetPropertyValue(EntityManager entityManager, object obj, object propertyValue)
        {
            IAttributeTable propertyAttributeTable = (IAttributeTable)propertyValue;

            propertyValue = Activator.CreateInstance(this.PropertyType);
            InspectorType propertyInspectorType = InspectorType.GetInspectorType(this.PropertyType);

            InspectorUtils.InitFromAttributeTable(entityManager, propertyInspectorType, propertyValue, propertyAttributeTable);

            base.SetPropertyValue(entityManager, obj, propertyValue);
        }
Exemple #17
0
        /// <summary>
        ///   Deinitializes the specified component.
        /// </summary>
        /// <param name="component">Component to deinitialize.</param>
        private void DeinitComponent(IEntityComponent component)
        {
            InspectorType inspectorType;

            if (!this.inspectorTypes.TryGetInspectorType(component.GetType(), out inspectorType))
            {
                this.game.Log.Warning(
                    "Entity component '" + component.GetType() + "' not flagged as inspector type, can't deinitialize.");
                return;
            }

            InspectorUtils.Deinit(this, inspectorType, component);
        }
Exemple #18
0
        public void TestCreateFromNullAttributeTable()
        {
            TestInspectorType testInspectorType = null;

            Assert.DoesNotThrow(
                () =>
            {
                testInspectorType =
                    InspectorUtils.CreateFromAttributeTable <TestInspectorType>(
                        this.testGame.EntityManager,
                        this.inspectorType,
                        null);
            });

            Assert.NotNull(testInspectorType);
        }
Exemple #19
0
        private void DrawCondition(Rect rect, SerializedProperty element, GUIContent label, int index, bool selected, bool focused)
        {
            Condition condition   = null;
            string    description = string.Empty;

            if (element.objectReferenceValue != null)
            {
                condition   = element.GetAs <Condition>();
                description = condition.GetDescription();
            }

            rect.x += 10;
            var foldoutRect = rect;

            foldoutRect.height = GenericParamUtils.FieldHeight;

            element.isExpanded = EditorGUI.Foldout(foldoutRect, element.isExpanded, new GUIContent(description), true);
            if (element.isExpanded)
            {
                rect.width  -= 10;
                rect.y      += GenericParamUtils.FieldHeight;
                rect.height -= GenericParamUtils.FieldHeight;

                if (condition)
                {
                    if (InspectorUtils.DrawDefaultInspector(rect, new SerializedObject(condition)))
                    {
                        if (element.serializedObject != null &&
                            element.serializedObject.targetObject != null)
                        {
                            EditorUtility.SetDirty(element.serializedObject.targetObject);
                        }
                    }
                }

                {
                    /*GUILayout.BeginArea(rect);
                     *
                     * if (InspectorUtils.DrawDefaultInspectorWithoutScriptField(new SerializedObject(condition)))
                     * {
                     *  EditorUtility.SetDirty(CurrentProperty.serializedObject.targetObject);
                     * }
                     *
                     * GUILayout.EndArea();*/
                }
            }
        }
Exemple #20
0
        /// <summary>
        /// Draws the dropdown menu for picking a property in the view model to bind to.
        /// </summary>
        private void ShowViewModelPropertyMenu(TwoWayPropertyBinding target, PropertyInfo[] bindableProperties, Type viewPropertyType, Rect position)
        {
            var selectedIndex = Array.IndexOf(
                bindableProperties.Select(p => p.ReflectedType + p.Name).ToArray(),
                target.viewModelName + target.viewModelPropertyName
                );

            var options = bindableProperties.Select(p =>
                                                    new InspectorUtils.MenuItem(
                                                        new GUIContent(p.ReflectedType + "/" + p.Name + " : " + p.PropertyType.Name),
                                                        p.PropertyType == viewPropertyType
                                                        )
                                                    ).ToArray();

            InspectorUtils.ShowCustomSelectionMenu(index =>
                                                   SetViewModelProperty(target, bindableProperties[index]), options, selectedIndex, position);
        }
Exemple #21
0
        public void TestDeserializationFromAttributeTable()
        {
            IAttributeTable attributeTable   = new AttributeTable();
            const string    TestValueString1 = "Test1";
            const string    TestValueString2 = "Test2";

            attributeTable.SetValue(TestData.AttributeString1, TestValueString1);
            attributeTable.SetValue(TestData.AttributeString2, TestValueString2);
            IAttributeTable parentAttributeTable = new AttributeTable();

            parentAttributeTable.SetValue(TestDataParent.AttributeTestData, attributeTable);

            TestDataParent testDataParent = InspectorUtils.CreateFromAttributeTable <TestDataParent>(
                this.testGame.EntityManager, this.parentInspectorType, parentAttributeTable);

            Assert.AreEqual(testDataParent.TestData.String1, TestValueString1);
            Assert.AreEqual(testDataParent.TestData.String2, TestValueString2);
        }
Exemple #22
0
        public void TestCreateFromAttributeTable()
        {
            IAttributeTable attributeTable   = new AttributeTable();
            const string    TestValueString1 = "Test1";
            const string    TestValueString2 = "Test2";

            attributeTable.SetValue(TestInspectorType.AttributeString1, TestValueString1);
            attributeTable.SetValue(TestInspectorType.AttributeString2, TestValueString2);

            TestInspectorType testInspectorType =
                InspectorUtils.CreateFromAttributeTable <TestInspectorType>(
                    this.testGame.EntityManager,
                    this.inspectorType,
                    attributeTable);

            Assert.AreEqual(testInspectorType.String1, TestValueString1);
            Assert.AreEqual(testInspectorType.String2, TestValueString2);
        }
Exemple #23
0
        protected void RecreateRopeButtons()
        {
            EditorGUILayout.BeginHorizontal();
            bool v_forceRecreate = InspectorUtils.DrawButton("Force Recreate Rope", Color.cyan);
            bool v_refreshRope   = InspectorUtils.DrawButton("Refresh Rope", Color.cyan);

            if (m_controller != null && m_controller.gameObject != null && !RopeInternalUtils.IsPrefab(m_controller.gameObject))
            {
                if (v_forceRecreate)
                {
                    m_controller.CreateRope(true);
                }
                else if (v_refreshRope)
                {
                    m_controller.CreateRope(false);
                }
            }
            EditorGUILayout.EndHorizontal();
        }
        public override void OnInspectorGUI()
        {
            InspectorUtils.DrawDefaultScriptField(serializedObject);

            EditorGUI.BeginChangeCheck();

            var list = EditorGUILayout.ObjectField(Target.Prefabs, typeof(PrefabRandomizerList), true, GUILayout.ExpandWidth(true)) as PrefabRandomizerList;

            if (EditorGUI.EndChangeCheck())
            {
                foreach (PrefabRandomizer rand in targets.Select(r => r as PrefabRandomizer))
                {
                    if (rand)
                    {
                        rand.Prefabs = list;
                    }
                }
            }

            GUILayout.BeginHorizontal();
            {
                if (GUILayout.Button("Randomize"))
                {
                    if (targets.Length == 0 || targets.Length == 1)
                    {
                        Undo.RegisterCompleteObjectUndo(Target, "Randomize Prefab");
                        Target.Randomize(true);
                    }
                    else
                    {
                        foreach (PrefabRandomizer obj in targets.Select(a => a as PrefabRandomizer))
                        {
                            obj?.Randomize(true);
                        }
                    }
                }

                Target.Locked = GUILayout.Toggle(Target.Locked, Target.Locked ? "Unlock Prefab" : "Lock Prefab");
            }
            GUILayout.EndHorizontal();

            EditorGUILayout.Space();
        }
Exemple #25
0
        public override void OnInspectorGUI()
        {
            InspectorUtils.DrawDefaultScriptField(serializedObject);

            serializedObject.Update();
            {
                HandleField(ref Dialog.Dialog, "Dialog Script");

                InspectorUtils.DrawFoldableProperty(serializedObject.FindProperty("OnDialogStart"));
                InspectorUtils.DrawFoldableProperty(serializedObject.FindProperty("OnDialogEnd"));

                var actors = serializedObject.FindProperty("Actors");
                if (actors.arraySize != 0)
                {
                    EditorGUILayout.Space();
                    EditorGUILayout.LabelField("Actors", EditorStyles.boldLabel);
                    for (int i = 0; i < actors.arraySize; i++)
                    {
                        EditorGUILayout.PropertyField(actors.GetArrayElementAtIndex(i));
                    }
                }

                var functions = serializedObject.FindProperty("Functions");
                if (functions.arraySize != 0)
                {
                    EditorGUILayout.Space();
                    EditorGUILayout.LabelField("Functions", EditorStyles.boldLabel);
                    for (int i = 0; i < functions.arraySize; i++)
                    {
                        var prop = functions.GetArrayElementAtIndex(i);
                        InspectorUtils.DrawFoldableProperty(prop, prop.FindPropertyRelative("Name").stringValue);
                    }
                }
            }
            serializedObject.ApplyModifiedProperties();

            EditorGUILayout.Space();
            if (GUILayout.Button("Reload"))
            {
                Dialog.ReloadDialog();
            }
        }
        private void ShowViewModelMethodDropdown(EventBinding target, MethodInfo[] bindableViewModelMethods, Type[] viewEventArgs, Rect position)
        {
            var selectedIndex = Array.IndexOf(
                bindableViewModelMethods.Select(m => m.ReflectedType + m.Name).ToArray(),
                target.viewModelName + target.viewModelMethodName
                );

            var options = bindableViewModelMethods.Select(m =>
                                                          new InspectorUtils.MenuItem(
                                                              new GUIContent(m.ReflectedType + "/" + m.Name + "(" + ParameterInfoToString(m.GetParameters()) + ")"),
                                                              MethodMatchesSignature(m, viewEventArgs)
                                                              )
                                                          ).ToArray();

            InspectorUtils.ShowCustomSelectionMenu(
                index => SetBoundMethod(target, bindableViewModelMethods[index]),
                options,
                selectedIndex,
                position);
        }
Exemple #27
0
        public override void OnGUI(Rect rect)
        {
            GUILayout.Label("Parameters", EditorStyles.boldLabel);

            for (var index = 0; index < this.parameterInfos.Length; index++)
            {
                var parameterInfo = this.parameterInfos[index];

                var parameterValue = this.parameterValues[index];

                this.parameterValues[index] = InspectorUtils.DrawValueField(ObjectNames.NicifyVariableName(parameterInfo.Name),
                                                                            parameterInfo.ParameterType,
                                                                            parameterValue);
            }

            if (GUILayout.Button("Invoke"))
            {
                this.invokeAction(this.parameterValues);
            }
        }
Exemple #28
0
        /// <summary>
        /// Draws the dropdown for selecting a method from bindableViewModelCollections
        /// </summary>
        private void ShowCollectionSelectorDropdown(CollectionBinding targetScript, PropertyInfo[] bindableViewModelCollections, Rect position)
        {
            var selectedIndex = Array.IndexOf(
                bindableViewModelCollections.Select(m => m.ReflectedType + m.Name).ToArray(),
                targetScript.viewModelName + targetScript.viewModelPropertyName
                );

            var options = bindableViewModelCollections.Select(m =>
                                                              new InspectorUtils.MenuItem(
                                                                  new GUIContent(m.ReflectedType + "/" + m.Name),
                                                                  true
                                                                  )
                                                              ).ToArray();

            InspectorUtils.ShowCustomSelectionMenu(
                index => SetViewModelProperty(targetScript, bindableViewModelCollections[index]),
                options,
                selectedIndex,
                position);
        }
    protected override void DrawComponentAfterDependenceCheck(Rect position, SerializedProperty property, GUIContent label, System.Type p_type)
    {
        SerializableTypeAttribute v_attr    = (SerializableTypeAttribute)attribute;
        SerializableType          v_serType = GetSerializableType(property);
        SerializableType          v_newType = InspectorUtils.SerializableTypePopup(position, label.text, v_serType, v_attr.FilterType, v_attr.AcceptGenericDefinitions);

        if (v_newType == null)
        {
            v_newType = new SerializableType();
        }
        if (v_serType.CastedType != v_newType.CastedType || v_serType.StringType != v_newType.StringType)
        {
            SetSerializableType(property, v_newType);
            try
            {
                EditorUtility.SetDirty(property.serializedObject.targetObject);
            }
            catch {}
        }
    }
Exemple #30
0
        /// <summary>
        ///   Initializes the specified component with the specified attribute table.
        /// </summary>
        /// <param name="component">Component to initialize.</param>
        /// <param name="attributeTable">Attribute table which contains the data of the component.</param>
        private void InitComponent(IEntityComponent component, IAttributeTable attributeTable)
        {
            InspectorType inspectorType;

            if (!this.inspectorTypes.TryGetInspectorType(component.GetType(), out inspectorType))
            {
                this.game.Log.Warning(
                    "Entity component '" + component.GetType()
                    + "' not flagged as inspector type, can't initialize via reflection.");
                return;
            }

            var inspectorComponent = inspectorType.Attribute as InspectorComponentAttribute;

            if (inspectorComponent != null && inspectorComponent.InitExplicitly)
            {
                return;
            }

            InspectorUtils.InitFromAttributeTable(this, inspectorType, component, attributeTable);
        }