protected override void OnSPInspectorGUI()
        {
            //this.DrawDefaultInspector();

            this.serializedObject.Update();

            this.DrawPropertyField(EditorHelper.PROP_SCRIPT);

            var typeProp = this.serializedObject.FindProperty(PROP_SINGLETONTYPE);
            var label    = EditorHelper.TempContent("Singleton Type");
            var area     = EditorGUILayout.GetControlRect(true, _typeRefDrawer.GetPropertyHeight(typeProp, label));

            _typeRefDrawer.OnGUI(area, typeProp, label);

            var tp = TypeReferencePropertyDrawer.GetTypeFromTypeReference(typeProp);

            if (tp != null && typeof(IManagedSingleton).IsAssignableFrom(tp))
            {
                this.DrawPropertyField(PROP_CREATEIFNONE);
            }

            this.serializedObject.ApplyModifiedProperties();



            //DRAW MEMBERS FOR PREVIEW
            this.DrawTargetMembersPreview();
        }
示例#2
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;
        }
示例#3
0
        public TypeReferenceField(SerializedProperty property, FieldInfo field)
        {
            _fieldDrawer = new TypeReferencePropertyDrawer();
            _label       = new GUIContent(property.displayName);
            _property    = property;

            _fieldDrawer.SetFieldInfo(field);

            SetInheritsAttributeIfFound(field);
            SetTypeOptionsAttributeIfFound(field);
        }
        /// <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 OnAddDropDown(Rect buttonRect, ReorderableList list)
        {
            GenericMenu availableConditionsMenu = new GenericMenu();

            //TypeReferencePropertyDrawer
            foreach (Type builtIn in builtInConditionTypes)
            {
                availableConditionsMenu.AddItem(new GUIContent(builtIn.Name),
                                                false, OnNewConditionTypeSelected, builtIn);
            }

            foreach (Type customType in customConditionTypes)
            {
                string typeName = TypeReferencePropertyDrawer.FormatByNamespaceFlat(customType);

                availableConditionsMenu.AddItem(
                    new GUIContent("Custom/" + typeName), false,
                    OnNewConditionTypeSelected, customType);
            }

            availableConditionsMenu.ShowAsContext();
        }
        protected override void OnEnable()
        {
            base.OnEnable();

            _typeRefDrawer = new TypeReferencePropertyDrawer();
            _typeRefDrawer.AllowAbstractTypes = true;
            _typeRefDrawer.AllowInterfaces    = true;
            _typeRefDrawer.DropDownStyle      = TypeDropDownListingStyle.Flat;
            _typeRefDrawer.SearchPredicate    = (tp) =>
            {
                if (typeof(IManagedSingleton).IsAssignableFrom(tp))
                {
                    //managed singletons can't be interfaces/abstract
                    return(!tp.IsInterface && !tp.IsAbstract);
                }
                else if (typeof(IService).IsAssignableFrom(tp))
                {
                    if (tp == typeof(IService))
                    {
                        return(false);
                    }

                    //currently only allow interface services be listed
                    return(tp.IsInterface);
                }
                else if (typeof(ISingleton).IsAssignableFrom(tp))
                {
                    //standard singletons can't be interfaces/abstract
                    return(!tp.IsInterface && !tp.IsAbstract);
                }
                else
                {
                    return(false);
                }
            };
        }
        protected override void OnSPInspectorGUI()
        {
            this.serializedObject.Update();

            this.DrawDefaultInspectorExcept("_target", "_restrictedType", "_memberName", "_values", "_mode");
            this.DrawPropertyField("_target"); //uses the SelectableComponent PropertyDrawer
            this.DrawPropertyField("_restrictedType");
            this.serializedObject.ApplyModifiedProperties();

            var targProp         = this.serializedObject.FindProperty("_target");
            var restrictTypeProp = this.serializedObject.FindProperty("_restrictedType");
            var memberProp       = this.serializedObject.FindProperty("_memberName");
            var valuesArrProp    = this.serializedObject.FindProperty("_values");
            var modeProp         = this.serializedObject.FindProperty("_mode");

            var targetRef = EditorHelper.GetTargetObjectOfProperty(targProp) as TriggerableTargetObject;

            if (targetRef == null)
            {
                return;
            }

            //SELECT MEMBER
            System.Reflection.MemberInfo selectedMember = null;
            var restrictType = TypeReferencePropertyDrawer.GetTypeFromTypeReference(restrictTypeProp);

            if (restrictType == null && !targetRef.TargetsTriggerArg && targetRef.Target != null &&
                targetRef.Find == TriggerableTargetObject.FindCommand.Direct && targetRef.ResolveBy != TriggerableTargetObject.ResolveByCommand.WithType &&
                targetRef.Target.GetType() != restrictType)
            {
                memberProp.stringValue = SPEditorGUILayout.ReflectedPropertyField(EditorHelper.TempContent("Property", "The property on the target to set."),
                                                                                  targetRef.Target,
                                                                                  memberProp.stringValue,
                                                                                  com.spacepuppy.Dynamic.DynamicMemberAccess.ReadWrite,
                                                                                  out selectedMember,
                                                                                  true);
            }
            else
            {
                if (restrictType == null)
                {
                    if (targetRef.ResolveBy == TriggerableTargetObject.ResolveByCommand.WithType)
                    {
                        restrictType = TypeUtil.FindType(targetRef.ResolveByQuery);
                    }
                    if (restrictType == null)
                    {
                        restrictType = typeof(object);
                    }
                    else
                    {
                        TypeReferencePropertyDrawer.SetTypeToTypeReference(restrictTypeProp, restrictType);
                    }
                }
                memberProp.stringValue = SPEditorGUILayout.ReflectedPropertyField(EditorHelper.TempContent("Property", "The property on the target to set."),
                                                                                  restrictType,
                                                                                  memberProp.stringValue,
                                                                                  out selectedMember,
                                                                                  true);
            }
            this.serializedObject.ApplyModifiedProperties();


            //MEMBER VALUE TO SET TO
            if (selectedMember != null && selectedMember.MemberType == System.Reflection.MemberTypes.Method)
            {
                var methodInfo = selectedMember as System.Reflection.MethodInfo;
                if (methodInfo == null)
                {
                    return;
                }

                var parameters = methodInfo.GetParameters();
                valuesArrProp.arraySize = parameters.Length;

                for (int i = 0; i < parameters.Length; i++)
                {
                    var p         = parameters[i];
                    var valueProp = valuesArrProp.GetArrayElementAtIndex(i);
                    var propType  = p.ParameterType;

                    if (DynamicUtil.TypeIsVariantSupported(propType))
                    {
                        //draw the default variant as the method accepts anything
                        _variantDrawer.RestrictVariantType = false;
                        _variantDrawer.ForcedObjectType    = null;
                        var label = EditorHelper.TempContent("Parameter " + i.ToString(), "The value to set to.");
                        _variantDrawer.OnGUI(EditorGUILayout.GetControlRect(true, _variantDrawer.GetPropertyHeight(valueProp, label)), valueProp, label);
                    }
                    else
                    {
                        _variantDrawer.RestrictVariantType = true;
                        _variantDrawer.TypeRestrictedTo    = propType;
                        _variantDrawer.ForcedObjectType    = (TypeUtil.IsType(propType, typeof(UnityEngine.Object))) ? propType : null;
                        var label = EditorHelper.TempContent("Parameter " + i.ToString(), "The value to set to.");
                        _variantDrawer.OnGUI(EditorGUILayout.GetControlRect(true, _variantDrawer.GetPropertyHeight(valueProp, label)), valueProp, label);
                    }
                }

                modeProp.SetEnumValue(i_SetValueOnTarget.SetMode.Set);
            }
            else if (selectedMember != null)
            {
                var propType = com.spacepuppy.Dynamic.DynamicUtil.GetInputType(selectedMember);
                var emode    = modeProp.GetEnumValue <i_SetValueOnTarget.SetMode>();
                if (emode == i_SetValueOnTarget.SetMode.Toggle)
                {
                    //EditorGUILayout.LabelField(EditorHelper.TempContent(valueProp.displayName), EditorHelper.TempContent(propType.Name));
                    valuesArrProp.arraySize = 0;
                    var evtp  = VariantReference.GetVariantType(propType);
                    var cache = SPGUI.Disable();
                    EditorGUILayout.EnumPopup(EditorHelper.TempContent("Value"), evtp);
                    cache.Reset();
                }
                else
                {
                    valuesArrProp.arraySize = 1;
                    var valueProp = valuesArrProp.GetArrayElementAtIndex(0);
                    if (DynamicUtil.TypeIsVariantSupported(propType))
                    {
                        //draw the default variant as the method accepts anything
                        _variantDrawer.RestrictVariantType = false;
                        _variantDrawer.ForcedObjectType    = null;
                        var label = EditorHelper.TempContent("Value", "The value to set to.");
                        _variantDrawer.OnGUI(EditorGUILayout.GetControlRect(true, _variantDrawer.GetPropertyHeight(valueProp, label)), valueProp, label);
                    }
                    else
                    {
                        _variantDrawer.RestrictVariantType = true;
                        _variantDrawer.TypeRestrictedTo    = propType;
                        _variantDrawer.ForcedObjectType    = (TypeUtil.IsType(propType, typeof(UnityEngine.Object))) ? propType : null;
                        var label = EditorHelper.TempContent("Value", "The value to set to.");
                        _variantDrawer.OnGUI(EditorGUILayout.GetControlRect(true, _variantDrawer.GetPropertyHeight(valueProp, label)), valueProp, label);
                    }
                }

                if (com.spacepuppy.Dynamic.Evaluator.WillArithmeticallyCompute(propType))
                {
                    EditorGUILayout.PropertyField(modeProp);
                }
                else
                {
                    //modeProp.SetEnumValue(i_SetValueOnTarget.SetMode.Set);
                    EditorGUI.BeginChangeCheck();
                    emode = (i_SetValueOnTarget.SetMode)SPEditorGUILayout.EnumPopupExcluding(EditorHelper.TempContent(modeProp.displayName), emode, i_SetValueOnTarget.SetMode.Decrement, i_SetValueOnTarget.SetMode.Increment);
                    if (EditorGUI.EndChangeCheck())
                    {
                        modeProp.SetEnumValue(emode);
                    }
                }
            }
            else
            {
                modeProp.SetEnumValue(i_SetValueOnTarget.SetMode.Set);
            }

            this.serializedObject.ApplyModifiedProperties();
        }
        public override void OnInspectorGUI()
        {
            RenderHeader();

            EditorGUILayout.LabelField("Controller Input Mappings", EditorStyles.boldLabel);
            EditorGUILayout.HelpBox("Use this profile to define all the controllers and their inputs your users will be able to use in your application.\n\n" +
                                    "You'll want to define all your Input Actions and Controller Data Providers first so you can wire up actions to hardware sensors, controllers, gestures, and other input devices.", MessageType.Info);
            EditorGUILayout.Space();

            ThisProfile.CheckProfileLock();
            serializedObject.Update();

            EditorGUILayout.LabelField("Select a profile type:");

            changed = false;

            var showDropdown = EditorGUILayout.DropdownButton(AddMappingDefinitionContent, FocusType.Keyboard);

            if (Event.current.type == EventType.Repaint)
            {
                dropdownRect = GUILayoutUtility.GetLastRect();
            }

            if (showDropdown)
            {
                TypeReferencePropertyDrawer.DisplayDropDown(dropdownRect, mappingTypes, null, TypeGrouping.ByNamespaceFlat);
            }

            if (Event.current.type == EventType.ExecuteCommand)
            {
                if (Event.current.commandName == TypeReferencePropertyDrawer.TypeReferenceUpdated)
                {
                    controllerMappingProfiles.arraySize += 1;
                    var newItem = controllerMappingProfiles.GetArrayElementAtIndex(controllerMappingProfiles.arraySize - 1);
                    CreateNewProfileInstance(ThisProfile, newItem, TypeReferencePropertyDrawer.SelectedType);

                    TypeReferencePropertyDrawer.SelectedType      = null;
                    TypeReferencePropertyDrawer.SelectedReference = null;

                    changed = true;
                }
            }

            EditorGUILayout.Space();

            for (int i = 0; i < controllerMappingProfiles.arraySize; i++)
            {
                var controllerProfile = controllerMappingProfiles.GetArrayElementAtIndex(i);

                EditorGUILayout.BeginHorizontal();
                changed |= RenderProfile(ThisProfile, controllerProfile, GUIContent.none, false);

                if (GUILayout.Button(RemoveMappingDefinitionContent, EditorStyles.miniButtonRight, GUILayout.Width(24f)))
                {
                    controllerMappingProfiles.DeleteArrayElementAtIndex(i);
                    changed = true;
                }

                EditorGUILayout.EndHorizontal();

                if (changed)
                {
                    break;
                }
            }

            serializedObject.ApplyModifiedProperties();

            if (changed && MixedRealityToolkit.IsInitialized)
            {
                EditorApplication.delayCall += () => MixedRealityToolkit.Instance.ResetProfile(MixedRealityToolkit.Instance.ActiveProfile);
            }
        }
        protected override void OnSPInspectorGUI()
        {
            this.serializedObject.Update();

            this.DrawDefaultInspectorExcept("_searchEntity", "_componentType", "_memberName", "_value", "_mode");
            this.DrawPropertyField("_searchEntity");
            this.DrawPropertyField("_componentType"); //uses the TypeReference PropertyDrawer

            var compTypeProp = this.serializedObject.FindProperty("_componentType");
            var memberProp   = this.serializedObject.FindProperty("_memberName");
            var valueProp    = this.serializedObject.FindProperty("_value");
            var modeProp     = this.serializedObject.FindProperty("_mode");


            //SELECT MEMBER
            System.Reflection.MemberInfo selectedMember;
            memberProp.stringValue = SPEditorGUILayout.ReflectedPropertyField(EditorHelper.TempContent("Property", "The property on the target to set."),
                                                                              TypeReferencePropertyDrawer.GetTypeFromTypeReference(compTypeProp),
                                                                              memberProp.stringValue,
                                                                              out selectedMember);
            this.serializedObject.ApplyModifiedProperties();


            //MEMBER VALUE TO SET TO
            if (selectedMember != null)
            {
                var propType = com.spacepuppy.Dynamic.DynamicUtil.GetReturnType(selectedMember);
                var emode    = modeProp.GetEnumValue <i_SetValue.SetMode>();
                if (emode == i_SetValue.SetMode.Toggle)
                {
                    //EditorGUILayout.LabelField(EditorHelper.TempContent(valueProp.displayName), EditorHelper.TempContent(propType.Name));
                    var evtp  = VariantReference.GetVariantType(propType);
                    var cache = SPGUI.Disable();
                    EditorGUILayout.EnumPopup(EditorHelper.TempContent(valueProp.displayName), evtp);
                    cache.Reset();
                }
                else
                {
                    if (propType == typeof(object))
                    {
                        //draw the default variant as the method accepts anything
                        _variantDrawer.RestrictVariantType = false;
                        _variantDrawer.ForcedObjectType    = null;
                        _variantDrawer.OnGUI(EditorGUILayout.GetControlRect(), valueProp, EditorHelper.TempContent("Value", "The value to set to."));
                    }
                    else
                    {
                        _variantDrawer.RestrictVariantType = true;
                        _variantDrawer.TypeRestrictedTo    = propType;
                        _variantDrawer.ForcedObjectType    = (TypeUtil.IsType(propType, typeof(Component))) ? propType : null;
                        _variantDrawer.OnGUI(EditorGUILayout.GetControlRect(), valueProp, EditorHelper.TempContent("Value", "The value to set to."));
                    }
                }

                if (com.spacepuppy.Dynamic.Evaluator.WillArithmeticallyCompute(propType))
                {
                    EditorGUILayout.PropertyField(modeProp);
                }
                else
                {
                    //modeProp.SetEnumValue(i_SetValue.SetMode.Set);
                    EditorGUI.BeginChangeCheck();
                    emode = (i_SetValue.SetMode)SPEditorGUILayout.EnumPopupExcluding(EditorHelper.TempContent(modeProp.displayName), emode, i_SetValue.SetMode.Decrement, i_SetValue.SetMode.Increment);
                    if (EditorGUI.EndChangeCheck())
                    {
                        modeProp.SetEnumValue(emode);
                    }
                }
            }
            else
            {
                modeProp.SetEnumValue(i_SetValue.SetMode.Set);
            }

            this.serializedObject.ApplyModifiedProperties();
        }
        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();
            }
        }
示例#12
0
 private string GroupVariableType(System.Type variableType)
 {
     return("Custom/" +
            TypeReferencePropertyDrawer.FormatByNamespace(variableType));
 }