예제 #1
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            Rect typePos = new Rect(position.x, position.y, 80, position.height);

            position.xMin = typePos.xMax;
            Rect varPos = new Rect(position.x, position.y, position.width, position.height);


            Type type = Type.GetType(property.type);

            //create types selection popup
            //if ( selectedType == typeof(System.Object)) {
            if (property.objectReferenceValue == null)
            {
                type = EditorGUILayoutEx.unityTypes [0];
            }
            else
            {
                type = ((UnityVariable)property.objectReferenceValue).ValueType;
            }


            String name        = ((UnityVariable)property.objectReferenceValue).name;
            bool   typeChanged = false;

            EditorGUI.BeginChangeCheck();
            typeSelected = EditorGUILayoutEx.CustomObjectPopup <Type> (null, type, EditorGUILayoutEx.unityTypesDisplayOptions, EditorGUILayoutEx.unityTypes, null, null, null, null, typePos);

            //if change of type create new variable
            if (typeSelected != type && !typeSelected.IsSubclassOf(type) /*&& type!=typeof(UnityEngine.Object)*/)
            {
                property.objectReferenceValue = UnityVariable.CreateInstanceOf(typeSelected);
                typeChanged = true;
            }
            //	}

            property.objectReferenceValue = EditorGUILayoutEx.UnityVariablePopup(null, property.objectReferenceValue as UnityVariable, typeSelected, new List <GUIContent>(), new List <UnityVariable>(), varPos);

            UnityVariable variable = ((UnityVariable)property.objectReferenceValue);

            variable.drawer = this;
            variable.name   = name;

            if (EditorGUI.EndChangeCheck() || typeChanged)
            {
                property.serializedObject.ApplyModifiedProperties();
                //EditorUtilityEx.ApplySerializedPropertyTo(variable);
            }
        }
예제 #2
0
        //
        // Methods
        //



        /// <summary>
        /// Handles the onGUI event.
        /// </summary>
        /// <param name="property">Property.</param>
        /// <param name="node">Node.</param>
        /// <param name="guiContent">GUI content.</param>
        public override void OnGUI(SerializedNodeProperty property, ActionNode node, GUIContent guiContent)
        {
            //if (animatorSerialized == null || aniController == null) {
            if (aniController == null)
            {
                //!!! Serialization never serialized Animator cos its initialized in Reset after
//								NodePropertyIterator iter= property.serializedNode.GetIterator();
//								iter.Find(attribute.animatorFieldName);
//								 animatorSerialized=iter.current;
                //				//								if(animatorSerialized==null || animatorSerialized.value==null){
                //										Debug.LogError("AnimatorStateNodePropertyDrawer> No Animator component set on node parent GameObject");
                //									return;
                //								}

                //runtimeContoller =( (Animator)animatorSerialized.value).runtimeAnimatorController;
                Animator animator = node.GetType().GetField(attribute.animatorFieldName).GetValue(node) as Animator;



                RuntimeAnimatorController runtimeContoller;


                runtimeContoller = animator.runtimeAnimatorController;

                if (runtimeContoller is AnimatorOverrideController)
                {
                    aniController = ((AnimatorOverrideController)runtimeContoller).runtimeAnimatorController as UnityEditor.Animations.AnimatorController;
                }
                else
                {
                    aniController = runtimeContoller as UnityEditor.Animations.AnimatorController;
                }
            }



            animatorStateDisplayOptions = MecanimUtility.GetDisplayOptions(aniController);
            animatorStateValues         = MecanimUtility.GetAnimatorStates(aniController);



            if (property.value != null)
            {
                if (animatorStateValues.Length > 0)
                {
                    animatorStateSelectedPrev = animatorStateSelected = animatorStateValues.FirstOrDefault((itm) => itm.nameHash == ((ws.winx.unity.AnimatorState)property.value).nameHash);
                }
            }


            animatorStateSelected = EditorGUILayoutEx.CustomObjectPopup(guiContent, animatorStateSelected, animatorStateDisplayOptions, animatorStateValues);                                     //,compare);



            //TODO try Begin/End Check
            if (animatorStateSelectedPrev != animatorStateSelected)
            {
                NodePropertyIterator iter = property.serializedNode.GetIterator();
                iter.Find(attribute.layerIndexFieldName);
                SerializedNodeProperty layerIndexSerialized = iter.current;

                layerIndexSerialized.value = MecanimUtility.GetLayerIndex(aniController, animatorStateSelected);
                layerIndexSerialized.ApplyModifiedValue();



                ws.winx.unity.AnimatorState state = property.value as ws.winx.unity.AnimatorState;
                if (state == null)
                {
                    state = ScriptableObject.CreateInstance <ws.winx.unity.AnimatorState>();
                }

                state.motion   = animatorStateSelected.motion;
                state.nameHash = animatorStateSelected.nameHash;
                state.layer    = (int)layerIndexSerialized.value;

                if (state.motion is UnityEditor.Animations.BlendTree)
                {
                    BlendTree tree           = (BlendTree)state.motion;
                    int       blendParamsNum = tree.GetRecursiveBlendParamCount();

                    state.blendParamsHashes = new int[blendParamsNum];

                    for (int i = 0; i < blendParamsNum; i++)
                    {
                        state.blendParamsHashes[i] = Animator.StringToHash(tree.GetRecursiveBlendParam(i));
                    }
                }
                else
                {
                    state.blendParamsHashes = null;
                }

                //property.value=state;
                property.ValueChanged();


                property.ApplyModifiedValue();

                animatorStateSelectedPrev = animatorStateSelected;
            }



            if (animatorStateSelected.motion == null)
            {
                Debug.LogError("Selected state doesn't have Motion set");
            }
        }
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            //TODO change to obtain controller thru property.serializedObject.Find(attribute.animator)....
            UnityEditor.Animations.AnimatorController animatorController = ((MonoBehaviour)property.serializedObject.targetObject).GetComponent <Animator> ().runtimeAnimatorController as UnityEditor.Animations.AnimatorController;

            if (animatorController != null)
            {
                //property.serializedObject.Update();

                animatorStateValues = MecanimUtility.GetAnimatorStates(animatorController);
                displayOptions      = MecanimUtility.GetDisplayOptions(animatorController);


                EditorGUI.indentLevel = 0;


                //if already have been serialzied before
                if (property.objectReferenceValue != null)
                {
                    if (animatorStateValues.Length > 0)
                    {
                        animatorStateSelected = animatorStateValues.FirstOrDefault((itm) => itm.nameHash == ((ws.winx.unity.AnimatorState)property.objectReferenceValue).nameHash) as UnityEditor.Animations.AnimatorState;
                    }
                }

                //animaStateInfoSelected = property.objectReferenceValue as UnityEditor.Animations.AnimatorState;



                // Check if it was modified this frame, to avoid overwriting the property constantly

                UnityEditor.Animations.AnimatorState prevAnimatorStateSelected = animatorStateSelected;
                animatorStateSelected = EditorGUILayoutEx.CustomObjectPopup(label, animatorStateSelected, displayOptions, animatorStateValues, null, null, null, null, position) as UnityEditor.Animations.AnimatorState;



                if (animatorStateSelected != null && animatorStateSelected.nameHash != prevAnimatorStateSelected.nameHash)
                {
                    ws.winx.unity.AnimatorState state = property.objectReferenceValue as ws.winx.unity.AnimatorState;

                    if (state == null)
                    {
                        state = ScriptableObject.CreateInstance <ws.winx.unity.AnimatorState>();
                    }

                    state.motion   = animatorStateSelected.motion;
                    state.nameHash = animatorStateSelected.nameHash;
                    state.name     = animatorStateSelected.name;

                    if (state.motion is UnityEditor.Animations.BlendTree)
                    {
                        BlendTree tree           = (BlendTree)state.motion;
                        int       blendParamsNum = tree.GetRecursiveBlendParamCount();

                        state.blendParamsHashes = new int[blendParamsNum];

                        for (int i = 0; i < blendParamsNum; i++)
                        {
                            state.blendParamsHashes[i] = Animator.StringToHash(tree.GetRecursiveBlendParam(i));
                        }
                    }
                    else
                    {
                        state.blendParamsHashes = null;
                    }



                    property.objectReferenceValue = state;
                    property.serializedObject.ApplyModifiedProperties();
                }
            }
        }
예제 #4
0
        public override void OnGUI(SerializedNodeProperty property, BehaviourMachine.ActionNode node, GUIContent guiContent)
        {
            Rect position = GUILayoutUtility.GetRect(Screen.width - 32f, 32f);



            Rect typePos = new Rect(position.x, position.y, 80, position.height);

            position.xMin = typePos.xMax;
            Rect varPos = new Rect(position.x, position.y, position.width, position.height);


            Type type;

            GUIContent[] displayOptionsTypes;
            Type[]       types;

            UniUnityVariablePropertyAttribute attributeUni = attribute as UniUnityVariablePropertyAttribute;


            if (property.value == null)
            {
                type = EditorGUILayoutEx.unityTypes [0];
            }
            else
            {
                type = ((UnityVariable)property.value).ValueType;
            }

            //blackboard vars LOCAL
            BlackboardCustom blackboard = node.blackboard as BlackboardCustom;

            List <UnityVariable> blackboardVariablesLocalList = blackboard.GetVariableBy(type);


            List <GUIContent> displayOptionsVariablesLocal = blackboardVariablesLocalList.Select((item) => new GUIContent("Local/" + item.name)).ToList();


            //blackboard vars GLOBAL


            if (attributeUni.typesCustom != null)
            {
                GUIContent[] displayOptionsCustom = attributeUni.typesCustom.Select((itm) => new GUIContent(itm.Name)).ToArray();

                if (attributeUni.only)
                {
                    types = attributeUni.typesCustom;
                    displayOptionsTypes = displayOptionsCustom;
                }
                else
                {
                    types = attributeUni.typesCustom.Concat <Type>(EditorGUILayoutEx.unityTypes).ToArray();

                    displayOptionsTypes = displayOptionsCustom.Concat <GUIContent>(EditorGUILayoutEx.unityTypesDisplayOptions).ToArray();
                }
            }
            else
            {
                displayOptionsTypes = EditorGUILayoutEx.unityTypesDisplayOptions;
                types = EditorGUILayoutEx.unityTypes;
            }



            //String name = attributeUni.name;

            //create types selection popup
            typeSelected = EditorGUILayoutEx.CustomObjectPopup <Type> (null, type, displayOptionsTypes, types, null, null, null, null, typePos);

            //if change of type create new variable
            if (typeSelected != type && !typeSelected.IsSubclassOf(type) /*&& type!=typeof(UnityEngine.Object)*/)
            {
                property.value = UnityVariable.CreateInstanceOf(typeSelected);
            }


            property.value = EditorGUILayoutEx.UnityVariablePopup(null, property.value as UnityVariable, typeSelected, displayOptionsVariablesLocal, blackboardVariablesLocalList, varPos);



            property.serializedNode.ApplyModifiedProperties();
        }