Exemple #1
0
        private void RenderNewVariableSection()
        {
            EditorGUILayout.LabelField("New Variable");

            EditorGUI.indentLevel += 2;

            newVariableName = EditorGUILayout.TextField("Name: ", newVariableName);

            Rect controlRect = EditorGUILayout.GetControlRect();

            newVariableType = TypeReferencePropertyDrawer.DrawTypeSelectionControl(controlRect,
                                                                                   typeWindowContent, newVariableType, newVariableTypeFilter);

            EditorGUILayout.BeginHorizontal();

            GUILayout.FlexibleSpace();

            if (GUILayout.Button("Cancel", GUILayout.MinWidth(100f)))
            {
                ResetNewVariableSection();
            }

            if (GUILayout.Button("Add", GUILayout.MinWidth(100f)) && AddAction != null)
            {
                Type selectionAsType = Type.GetType(newVariableType);
                AddAction(newVariableName, selectionAsType);
                serializedVariables.SerializedContainer.Update();
                ResetNewVariableSection();
            }

            EditorGUILayout.EndHorizontal();

            EditorGUI.indentLevel -= 2;
        }
        /// <summary>
        /// Displays the drop down box for the type to be displayed
        /// </summary>
        /// <param name="position">The position to render this at. It is ref so
        /// that it can be adjusted to exclude the used area</param>
        /// <param name="label">The label to be displayed</param>
        /// <param name="currentSelection">The current selection</param>
        /// <returns>The selected item</returns>
        protected string RenderTypeSelection(ref Rect position, GUIContent label, string currentSelection)
        {
            Type   interfaceType       = typeof(InterfaceType);
            string interfaceTypeString = interfaceType.FullName;

            Rect drawRect = new Rect(position)
            {
                height = EditorGUIUtility.singleLineHeight
            };

            position.yMin += drawRect.height;

            string selection = TypeReferencePropertyDrawer.DrawTypeSelectionControl(drawRect, label,
                                                                                    currentSelection, new ClassImplementsAttribute(interfaceType));

            return(selection);
        }
        private void RenderTypeSelection()
        {
            if (sceneHunterTypeFilter == null)
            {
                return;
            }

            string previousSelection = selectedSceneHunterType;

            Rect controlRect = EditorGUILayout.GetControlRect();

            selectedSceneHunterType = TypeReferencePropertyDrawer.DrawTypeSelectionControl(
                controlRect, typeWindowContent, selectedSceneHunterType, sceneHunterTypeFilter);

            if (previousSelection != selectedSceneHunterType)
            {
                ChangeScenePopulator();
            }
        }
        private void RenderCodeParameter(CodeGenerationParameter parameter)
        {
            System.Object existingValue;

            parameterValues.TryGetValue(parameter.Identifier, out existingValue);

            string displayName = ObjectNames.NicifyVariableName(parameter.Identifier);

            System.Object newValue = null;

            switch (parameter.ParameterType)
            {
            case "int":
                int intValue = existingValue == null ? 0 : (int)existingValue;

                intValue = EditorGUILayout.IntField(displayName, intValue);

                parameterValues[parameter.Identifier] = intValue;
                newValue = intValue;
                break;

            case "string":
                string stringValue = existingValue == null ? string.Empty : (string)existingValue;

                stringValue = EditorGUILayout.TextField(displayName, stringValue);

                parameterValues[parameter.Identifier] = stringValue;
                newValue = stringValue;
                break;

            case "float":
                float floatValue = existingValue == null ? 0f : (float)existingValue;

                floatValue = EditorGUILayout.FloatField(displayName, floatValue);

                parameterValues[parameter.Identifier] = floatValue;
                newValue = floatValue;
                break;

            case "double":
                double doubleValue = existingValue == null ? 0 : (double)existingValue;

                doubleValue = EditorGUILayout.DoubleField(displayName, doubleValue);

                parameterValues[parameter.Identifier] = doubleValue;
                newValue = doubleValue;
                break;

            case "type":
                Type typeValue = existingValue as Type;

                string currentSelection = typeValue == null ? "" : typeValue.AssemblyQualifiedName;

                Rect typeRect = EditorGUILayout.GetControlRect();

                string selection = TypeReferencePropertyDrawer.DrawTypeSelectionControl(typeRect,
                                                                                        new GUIContent(displayName), currentSelection, typeDropdownFilter);

                typeValue = Type.GetType(selection);

                parameterValues[parameter.Identifier] = typeValue;
                newValue = typeValue;
                break;

            default:
                Debug.LogError(parameter.ParameterType + " is not a supported input type");
                break;
            }

            if (newValue != null && newValue.Equals(existingValue))
            {
                RefreshReplacementString();
            }
        }