Exemplo n.º 1
0
        protected override void OnSPInspectorGUI()
        {
            this.serializedObject.Update();

            _targetProp = this.serializedObject.FindProperty(PROP_TARGET);

            this.DrawPropertyField(EditorHelper.PROP_SCRIPT);
            this.DrawPropertyField(PROP_ORDER);
            this.DrawPropertyField(PROP_TIMESUPPLIER);
            SPEditorGUILayout.PropertyField(_targetProp);
            this.DrawPropertyField(PROP_TWEENTOKEN);
            _dataList.DoLayoutList();
            this.DrawPropertyField(PROP_ONCOMPLETE);


            this.DrawDefaultInspectorExcept(EditorHelper.PROP_SCRIPT, PROP_TARGET, PROP_TIMESUPPLIER, PROP_ONCOMPLETE, PROP_TWEENTOKEN);

            this.serializedObject.ApplyModifiedProperties();
        }
        protected override void OnSPInspectorGUI()
        {
            this.serializedObject.Update();

            var iterator = serializedObject.GetIterator();

            for (bool enterChildren = true; iterator.NextVisible(enterChildren); enterChildren = false)
            {
                if (iterator.name == PROP_MODIFIERS)
                {
                    this.DrawModifierTypes(iterator);
                }
                else
                {
                    SPEditorGUILayout.PropertyField(iterator, true);
                }
            }

            this.serializedObject.ApplyModifiedProperties();
        }
Exemplo n.º 3
0
        protected override void OnSPInspectorGUI()
        {
            this.serializedObject.Update();

            var propReflect = this.serializedObject.FindProperty(PROP_REFLECTNAMES);

            SPEditorGUILayout.PropertyField(propReflect);

            var propVars = this.serializedObject.FindProperty(PROP_VARIABLES);
            var lbl_Vars = EditorHelper.TempContent("Variables");

            _variablesDrawer.ConfigurePropertyList((TypeReferencePropertyDrawer.GetTypeFromTypeReference(propReflect)));
            var h = _variablesDrawer.GetPropertyHeight(propVars, lbl_Vars);
            var r = EditorGUILayout.GetControlRect(true, _variablesDrawer.GetPropertyHeight(propVars, lbl_Vars));

            _variablesDrawer.OnGUI(r, propVars, lbl_Vars);

            this.DrawDefaultInspectorExcept(EditorHelper.PROP_SCRIPT, PROP_REFLECTNAMES, PROP_VARIABLES);

            this.serializedObject.ApplyModifiedProperties();
        }
        protected override void OnSPInspectorGUI()
        {
            this.serializedObject.Update();


            this.DrawDefaultInspectorExcept(PROP_STATEMACHINE, PROP_STATE, PROP_WAITON);

            var stateMachineProp = this.serializedObject.FindProperty(PROP_STATEMACHINE);

            SPEditorGUILayout.PropertyField(stateMachineProp);

            var src = GameObjectUtil.GetGameObjectFromSource(stateMachineProp.objectReferenceValue);

            if (src != null)
            {
                var states = ParentComponentStateSupplier <IAIState> .GetComponentsOnTarg(src, false).ToArray();

                var stateProp = this.serializedObject.FindProperty(PROP_STATE);

                int index = System.Array.IndexOf(states, stateProp.objectReferenceValue);
                var names = (from s in states select EditorHelper.TempContent(s.DisplayName)).ToArray();

                EditorGUI.BeginChangeCheck();
                index = EditorGUILayout.Popup(EditorHelper.TempContent("State"), index, names);
                if (EditorGUI.EndChangeCheck())
                {
                    stateProp.objectReferenceValue = (index >= 0) ? states[index] as UnityEngine.Object : null;
                }
            }
            else
            {
                EditorGUILayout.LabelField("State", "*Select a State Machine first*");
            }


            this.DrawPropertyField(PROP_WAITON);


            this.serializedObject.ApplyModifiedProperties();
        }
        private void DrawAnimIdSelector(object animator)
        {
            if (animator == null)
            {
                this.DrawPropertyField(PROP_ID);
                return;
            }

            using (var lst = com.spacepuppy.Collections.TempCollection.GetList <string>())
            {
                GetAnimationIds(lst, animator);
                if (lst.Count == 0)
                {
                    this.DrawPropertyField(PROP_ID);
                    return;
                }
                else
                {
                    var propId = this.serializedObject.FindProperty(PROP_ID);
                    propId.stringValue = SPEditorGUILayout.OptionPopupWithCustom(propId.displayName, propId.stringValue, lst.ToArray());
                }
            }
        }
Exemplo n.º 6
0
        public bool OnGUILayout(SerializedProperty property, GUIContent label, bool includeChildren, GUILayoutOption[] options)
        {
            if (label == null)
            {
                label = EditorHelper.TempContent(property.displayName);
            }

            if (!includeChildren || !property.hasVisibleChildren)
            {
                //return ScriptAttributeUtility.SharedNullInternalPropertyHandler.OnGUILayout(property, label, includeChildren, options);
                return(EditorGUILayout.PropertyField(property, label, includeChildren, options));
            }

            EditorGUI.BeginChangeCheck();

            //draw header
            property.isExpanded = EditorGUILayout.Foldout(property.isExpanded, label);

            //draw children
            if (property.isExpanded)
            {
                var iterator = property.Copy();
                var end      = property.GetEndProperty();
                for (bool enterChildren = true; iterator.NextVisible(enterChildren); enterChildren = false)
                {
                    if (SerializedProperty.EqualContents(iterator, end))
                    {
                        break;
                    }

                    SPEditorGUILayout.PropertyField(iterator, EditorHelper.TempContent(iterator.displayName), iterator.hasVisibleChildren, options);
                }
            }

            return(EditorGUI.EndChangeCheck());
        }
        protected override void OnSPInspectorGUI()
        {
            this.serializedObject.Update();

            this.DrawPropertyField(EditorHelper.PROP_SCRIPT);



            if (Application.isPlaying)
            {
                GUI.enabled = false;
            }

            this.DrawPropertyField(PROP_NOTIFTYPE);

            var useGlobalProp = this.serializedObject.FindProperty(PROP_USEGLOBAL);
            var targetProp    = this.serializedObject.FindProperty(PROP_TARGET);

            SPEditorGUILayout.PropertyField(useGlobalProp);
            if (useGlobalProp.boolValue)
            {
                targetProp.objectReferenceValue = null;
            }
            else
            {
                SPEditorGUILayout.PropertyField(targetProp);
            }

            GUI.enabled = true;



            this.DrawDefaultInspectorExcept(EditorHelper.PROP_SCRIPT, PROP_NOTIFTYPE, PROP_USEGLOBAL, PROP_TARGET);

            this.serializedObject.ApplyModifiedProperties();
        }
Exemplo n.º 8
0
        protected override void OnSPInspectorGUI()
        {
            this.serializedObject.Update();

            this.DrawPropertyField(EditorHelper.PROP_SCRIPT);

            var propFileName = this.serializedObject.FindProperty(PROP_BUILDFILENAME);

            EditorGUILayout.PropertyField(propFileName);
            if (!string.IsNullOrEmpty(propFileName.stringValue))
            {
                var propBuildDir = this.serializedObject.FindProperty(PROP_BUILDDIR);
                propBuildDir.stringValue = SPEditorGUILayout.FolderPathTextfield(EditorHelper.TempContent(propBuildDir.displayName, propBuildDir.tooltip), propBuildDir.stringValue, "Build Directory");
            }
            this.DrawPropertyField(PROP_VERSION);

            this.DrawScenes();

            this.DrawBuildOptions();

            this.DrawInputSettings();

            this.DrawPlayerSettingOverrides();

            this.serializedObject.ApplyModifiedProperties();

            //build button
            if (this.serializedObject.isEditingMultipleObjects)
            {
                return;
            }

            EditorGUILayout.Space();

            this.DrawBuildButtons();
        }
Exemplo n.º 9
0
        protected override void OnSPInspectorGUI()
        {
            this.serializedObject.Update();

            var targ = this.target as AIController;

            if (targ == null)
            {
                return;
            }

            this.DrawPropertyField(EditorHelper.PROP_SCRIPT);

            var sourceProp = this.serializedObject.FindProperty(PROP_STATESOURCE);

            SPEditorGUILayout.PropertyField(sourceProp);

            var cache     = SPGUI.DisableIfPlaying();
            var stateProp = this.serializedObject.FindProperty(PROP_DEFAULTSTATE);

            switch (sourceProp.GetEnumValue <AIStateMachineSourceMode>())
            {
            case AIStateMachineSourceMode.SelfSourced:
            {
                var states = ComponentStateSupplier <IAIState> .GetComponentsOnTarg(targ.gameObject).Cast <Component>().ToArray();

                stateProp.objectReferenceValue = SPEditorGUILayout.SelectComponentField(stateProp.displayName, states, stateProp.objectReferenceValue as Component);
            }
            break;

            case AIStateMachineSourceMode.ChildSourced:
            {
                var states = ParentComponentStateSupplier <IAIState> .GetComponentsOnTarg(targ.gameObject, false);

                var names = (from s in states select EditorHelper.TempContent(GameObjectUtil.GetGameObjectFromSource(s).name + " (" + s.GetType().Name + ")")).ToArray();
                int i     = states.IndexOf(stateProp.objectReferenceValue);
                i = EditorGUILayout.Popup(EditorHelper.TempContent(stateProp.displayName), i, names);
                stateProp.objectReferenceValue = (i >= 0) ? states[i] as UnityEngine.Object : null;
            }
            break;

            default:
            {
                var states = ArrayUtil.Empty <Component>();
                stateProp.objectReferenceValue = SPEditorGUILayout.SelectComponentField(stateProp.displayName, states, stateProp.objectReferenceValue as Component);
            }
            break;
            }

            cache.Reset();


            this.DrawDefaultInspectorExcept(EditorHelper.PROP_SCRIPT, PROP_STATESOURCE, PROP_DEFAULTSTATE);

            this.serializedObject.ApplyModifiedProperties();


            if (Application.isPlaying)
            {
                if (targ.States != null && targ.States.Current != null)
                {
                    var c   = targ.States.Current;
                    var msg = string.Format("Currently active state is {0} ({1}).", c.DisplayName, c.GetType().Name);
                    EditorGUILayout.HelpBox(msg, MessageType.Info);
                }
                else
                {
                    EditorGUILayout.HelpBox("Currently active state is null.", MessageType.Info);
                }
            }
        }
        private void DrawModifierTypes(SerializedProperty prop)
        {
            //TODO - we want to include a drop down that only lists the IStateModifiers that actually exist on the nodes...

            SPEditorGUILayout.PropertyField(prop, true);
        }
Exemplo n.º 11
0
        protected override void OnSPInspectorGUI()
        {
            this.serializedObject.Update();

            this.DrawDefaultInspectorExcept("_target", "_memberName", "_value", "_mode");
            this.DrawPropertyField("_target"); //uses the SelectableComponent PropertyDrawer

            var targProp   = this.serializedObject.FindProperty("_target");
            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.ReflectedRecursingPropertyField(EditorHelper.TempContent("Property", "The property on the target to set."),
                                                                                       targProp.objectReferenceValue,
                                                                                       memberProp.stringValue,
                                                                                       com.spacepuppy.Dynamic.DynamicMemberAccess.ReadWrite,
                                                                                       out selectedMember);
            this.serializedObject.ApplyModifiedProperties();


            //MEMBER VALUE TO SET TO
            if (selectedMember != null)
            {
                var propType = com.spacepuppy.Dynamic.DynamicUtil.GetInputType(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 (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_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();
        }
        protected override void OnSPInspectorGUI()
        {
            this.serializedObject.Update();

            this.DrawPropertyField(EditorHelper.PROP_SCRIPT);
            this.DrawPropertyField(PROP_ORDER);
            this.DrawPropertyField(PROP_ACTIVATEON);

            this.DrawTargetAnimatorProperty();

            var propMode = this.serializedObject.FindProperty(PROP_MODE);

            SPEditorGUILayout.PropertyField(propMode);

            switch (propMode.GetEnumValue <i_PlayAnimation.PlayByMode>())
            {
            case i_PlayAnimation.PlayByMode.PlayAnim:
            {
                this.serializedObject.FindProperty(PROP_ID).stringValue = string.Empty;

                var clipProp = this.serializedObject.FindProperty(PROP_CLIP);
                var obj      = EditorGUILayout.ObjectField(EditorHelper.TempContent(clipProp.displayName), clipProp.objectReferenceValue, typeof(UnityEngine.Object), true);
                if (obj == null || obj is AnimationClip || obj is IScriptableAnimationClip)
                {
                    clipProp.objectReferenceValue = obj;
                }
                else if (GameObjectUtil.IsGameObjectSource(obj))
                {
                    clipProp.objectReferenceValue = ObjUtil.GetAsFromSource <IScriptableAnimationClip>(obj) as UnityEngine.Object;
                }

                this.DrawPropertyField(PROP_SETTINGS);
            }
            break;

            case i_PlayAnimation.PlayByMode.PlayAnimByID:
            {
                this.serializedObject.FindProperty(PROP_CLIP).objectReferenceValue = null;

                this.DrawPropertyField(PROP_ID);

                if (this.serializedObject.FindProperty(PROP_TARGETANIMATOR).FindPropertyRelative(TriggerableTargetObjectPropertyDrawer.PROP_TARGET).objectReferenceValue is Animation)
                {
                    this.DrawPropertyField(PROP_SETTINGS);
                }
            }
            break;

            case i_PlayAnimation.PlayByMode.PlayAnimFromResource:
            {
                this.serializedObject.FindProperty(PROP_CLIP).objectReferenceValue = null;

                this.DrawPropertyField(PROP_ID);

                this.DrawPropertyField(PROP_SETTINGS);
            }
            break;
            }

            this.DrawDefaultInspectorExcept(EditorHelper.PROP_SCRIPT, PROP_ORDER, PROP_ACTIVATEON, PROP_MODE, PROP_TARGETANIMATOR, PROP_ID, PROP_CLIP, PROP_SETTINGS);

            this.serializedObject.ApplyModifiedProperties();
        }
        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();
        }
Exemplo n.º 14
0
        private void OnGUI()
        {
            //draw header
            GUILayout.Space(3);
            EditorGUI.BeginChangeCheck();
            _mode = SPEditorGUILayout.SelectionTabs(_mode, _modes, 2);
            if (EditorGUI.EndChangeCheck())
            {
                _prefabResults.Clear();
                _sceneResults.Clear();
                _forceRefresh = true;
            }
            GUILayout.Space(3);

            switch (_mode)
            {
            case 0:
                EditorGUI.BeginChangeCheck();
                _targetScript = SPEditorGUILayout.TypeDropDown(GUIContent.none, typeof(Component), _targetScript, false, false);
                if (EditorGUI.EndChangeCheck() || _forceRefresh)
                {
                    this.FillBySearchForComponentUsage(false);
                }
                if (_prefabResults.Count == 0)
                {
                    var msgStyle = new GUIStyle(GUI.skin.label);
                    msgStyle.alignment = TextAnchor.MiddleCenter;
                    msgStyle.fontStyle = FontStyle.Bold;
                    string msg = (_targetScript == null) ? "Choose a script file." : "No prefabs use component " + _targetScript.FullName;
                    EditorGUI.LabelField(new Rect(0f, this.position.height / 2f, this.position.width, EditorGUIUtility.singleLineHeight), msg, msgStyle);
                }
                else
                {
                    this.DoDrawPrefabList();
                }
                break;

            case 1:
                EditorGUI.BeginChangeCheck();
                _targetScript = SPEditorGUILayout.TypeDropDown(GUIContent.none, typeof(Component), _targetScript, false, false);
                if (EditorGUI.EndChangeCheck() || _forceRefresh)
                {
                    this.FillBySearchForComponentUsage(true);
                }
                if (_prefabResults.Count == 0)
                {
                    var msgStyle = new GUIStyle(GUI.skin.label);
                    msgStyle.alignment = TextAnchor.MiddleCenter;
                    msgStyle.fontStyle = FontStyle.Bold;
                    string msg = (_targetScript == null) ? "Choose a script file." : "No scene objects use component " + _targetScript.FullName;
                    EditorGUI.LabelField(new Rect(0f, this.position.height / 2f, this.position.width, EditorGUIUtility.singleLineHeight), msg, msgStyle);
                }
                else
                {
                    this.DoDrawSceneList();
                }
                break;

            case 2:
                if (GUILayout.Button("Search!"))
                {
                    this.FillBySearchForMissingComponents(false);
                }
                if (_prefabResults.Count == 0)
                {
                    var msgStyle = new GUIStyle(GUI.skin.label);
                    msgStyle.alignment = TextAnchor.MiddleCenter;
                    msgStyle.fontStyle = FontStyle.Bold;
                    EditorGUI.LabelField(new Rect(0f, this.position.height / 2f, this.position.width, EditorGUIUtility.singleLineHeight * 2f), "No prefabs are missing any script references!\nClick Search to check again.", msgStyle);
                }
                else
                {
                    this.DoDrawPrefabList();
                }
                break;

            case 3:
                if (GUILayout.Button("Search!"))
                {
                    this.FillBySearchForMissingComponents(true);
                }
                if (_prefabResults.Count == 0)
                {
                    var msgStyle = new GUIStyle(GUI.skin.label);
                    msgStyle.alignment = TextAnchor.MiddleCenter;
                    msgStyle.fontStyle = FontStyle.Bold;
                    EditorGUI.LabelField(new Rect(0f, this.position.height / 2f, this.position.width, EditorGUIUtility.singleLineHeight * 2f), "No scene objects are missing any script references!\nClick Search to check again.", msgStyle);
                }
                else
                {
                    this.DoDrawSceneList();
                }
                break;
            }

            _forceRefresh = false;
        }
        protected void DrawConditionsBlock()
        {
            EditorGUILayout.BeginVertical("Box");

            VariantReference vref = EditorHelper.GetTargetObjectOfProperty(this.serializedObject.FindProperty(PROP_TARGET)) as VariantReference;

            System.Type enumType = vref != null?vref.GetPropertyReturnType() : null;

            if (enumType != null && !enumType.IsEnum)
            {
                enumType = null;
            }

            //draw conditions blocks
            var conditionsArrayProp = this.serializedObject.FindProperty(PROP_CONDITIONS);

            for (int i = 0; i < conditionsArrayProp.arraySize; i++)
            {
                var conditionBlockProp = conditionsArrayProp.GetArrayElementAtIndex(i);
                var valueProp          = conditionBlockProp.FindPropertyRelative(PROP_CONDITIONBLOCK_VALUE);
                var flagsProp          = conditionBlockProp.FindPropertyRelative(PROP_CONDITIONBLOCK_FLAGS);

                EditorGUILayout.LabelField((enumType != null) ? "Case " + ConvertUtil.ToEnumOfType(enumType, valueProp.intValue).ToString() + ":": "Case " + valueProp.intValue.ToString() + ":", EditorStyles.boldLabel);

                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.PrefixLabel("Value");

                if (enumType == null)
                {
                    valueProp.intValue = EditorGUILayout.IntField(valueProp.intValue);
                }
                else
                {
                    switch ((i_TriggerOnEnumState.EnumFlagTestModes)flagsProp.intValue)
                    {
                    case i_TriggerOnEnumState.EnumFlagTestModes.NoFlag:
                    {
                        valueProp.intValue = ConvertUtil.ToInt(EditorGUILayout.EnumPopup(ConvertUtil.ToEnumOfType(enumType, valueProp.intValue)));
                    }
                    break;

                    default:
                    {
                        //valueProp.intValue = ConvertUtil.ToInt(EditorGUILayout.EnumFlagsField(ConvertUtil.ToEnumOfType(enumType, valueProp.intValue)));
                        valueProp.intValue = SPEditorGUILayout.EnumFlagField(enumType, valueProp.intValue);
                    }
                    break;
                    }
                }

                flagsProp.intValue = ConvertUtil.ToInt(EditorGUILayout.EnumPopup((i_TriggerOnEnumState.EnumFlagTestModes)flagsProp.intValue));
                EditorGUILayout.EndHorizontal();

                var triggerProp = conditionBlockProp.FindPropertyRelative(PROP_CONDITIONBLOCK_TRIGGER);
                SPEditorGUILayout.PropertyField(triggerProp);

                EditorGUILayout.Space();
            }

            //draw else
            EditorGUILayout.LabelField("Default Case:", EditorStyles.boldLabel);
            SPEditorGUILayout.PropertyField(this.serializedObject.FindProperty(PROP_DEFAULTCONDITION));

            EditorGUILayout.Space();

            //draw add buttons
            var fullRect  = EditorGUILayout.GetControlRect();
            var leftRect  = new Rect(fullRect.xMin, fullRect.yMin, fullRect.width / 2f, fullRect.height);
            var rightRect = new Rect(fullRect.xMin + leftRect.width, fullRect.yMin, fullRect.width / 2f, fullRect.height);

            if (GUI.Button(leftRect, "Add Condition"))
            {
                conditionsArrayProp.arraySize++;
            }
            if (GUI.Button(rightRect, "Remove Condition"))
            {
                conditionsArrayProp.arraySize--;
            }

            EditorGUILayout.EndVertical();
        }
Exemplo n.º 16
0
        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.GetParameters(selectedMember).FirstOrDefault();
                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);
                    GUI.enabled = false;
                    EditorGUILayout.EnumPopup(EditorHelper.TempContent(valueProp.displayName), evtp);
                    GUI.enabled = true;
                }
                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
                    {
                        var argType = VariantReference.GetVariantType(propType);
                        _variantDrawer.RestrictVariantType     = true;
                        _variantDrawer.VariantTypeRestrictedTo = argType;
                        _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();
        }
        protected override void OnSPInspectorGUI()
        {
            this.serializedObject.Update();

            this.DrawPropertyField(EditorHelper.PROP_SCRIPT);
            this.DrawPropertyField(PROP_ORDER);
            this.DrawPropertyField(PROP_ACTIVATEON);

            this.DrawTargetAnimatorProperty();

            var controller = this.serializedObject.FindProperty(PROP_TARGETANIMATOR).FindPropertyRelative(TriggerableTargetObjectPropertyDrawer.PROP_TARGET).objectReferenceValue;

            if (controller is Animation || controller is SPLegacyAnimController)
            {
                var propMode = this.serializedObject.FindProperty(PROP_MODE);
                SPEditorGUILayout.PropertyField(propMode);

                switch (propMode.GetEnumValue <i_PlayAnimation.PlayByMode>())
                {
                case i_PlayAnimation.PlayByMode.PlayAnim:
                {
                    this.serializedObject.FindProperty(PROP_ID).stringValue = string.Empty;

                    var clipProp = this.serializedObject.FindProperty(PROP_CLIP);
                    var obj      = EditorGUILayout.ObjectField(EditorHelper.TempContent(clipProp.displayName), clipProp.objectReferenceValue, typeof(UnityEngine.Object), true);
                    if (obj == null || obj is AnimationClip || obj is IScriptableAnimationClip)
                    {
                        clipProp.objectReferenceValue = obj;
                    }
                    else if (GameObjectUtil.IsGameObjectSource(obj))
                    {
                        clipProp.objectReferenceValue = ObjUtil.GetAsFromSource <IScriptableAnimationClip>(obj) as UnityEngine.Object;
                    }
                }
                break;

                case i_PlayAnimation.PlayByMode.PlayAnimByID:
                {
                    this.serializedObject.FindProperty(PROP_CLIP).objectReferenceValue = null;

                    //this.DrawPropertyField(PROP_ID);
                    this.DrawAnimIdSelector(controller);
                }
                break;

                case i_PlayAnimation.PlayByMode.PlayAnimFromResource:
                {
                    this.serializedObject.FindProperty(PROP_CLIP).objectReferenceValue = null;

                    this.DrawPropertyField(PROP_ID);
                }
                break;
                }

                this.DrawAnimSettings();
                this.DrawPropertyField(PROP_QUEUEMODE);
                this.DrawPropertyField(PROP_PLAYMODE);
                this.DrawPropertyField(PROP_CROSSFADEDUR);
            }
            else if (controller is ISPAnimator)
            {
                var propId = this.serializedObject.FindProperty(PROP_ID);
                propId.stringValue = DrawSPAnimatorFunctionPopup(EditorGUILayout.GetControlRect(), controller as ISPAnimator, propId.stringValue);
            }
            else if (controller is ISPAnimationSource)
            {
                this.serializedObject.FindProperty(PROP_MODE).SetEnumValue <i_PlayAnimation.PlayByMode>(i_PlayAnimation.PlayByMode.PlayAnimByID);
                this.serializedObject.FindProperty(PROP_CLIP).objectReferenceValue = null;

                this.DrawPropertyField(PROP_ID);
                this.DrawAnimSettings();
                this.DrawPropertyField(PROP_QUEUEMODE);
                this.DrawPropertyField(PROP_PLAYMODE);
                this.DrawPropertyField(PROP_CROSSFADEDUR);
            }

            this.DrawDefaultInspectorExcept(EditorHelper.PROP_SCRIPT, PROP_ORDER, PROP_ACTIVATEON, PROP_MODE, PROP_TARGETANIMATOR, PROP_ID, PROP_CLIP, PROP_SETTINGSMASK, PROP_SETTINGS, PROP_QUEUEMODE, PROP_PLAYMODE, PROP_CROSSFADEDUR);

            this.serializedObject.ApplyModifiedProperties();
        }