コード例 #1
0
ファイル: StateUtility.cs プロジェクト: xclouder/godbattle
        /// <summary>
        /// Reset the supplied node properties.
        /// <param name="node">The node to be reseted.</param>
        /// </summary>
        public static void ResetNode (ActionNode node) {
            // Get the owner as an Uniyt object
            var ownerUnityObj = node != null ? node.owner as UnityEngine.Object : null;
            // Validate parameters
            if (ownerUnityObj != null) {

                // Register Undo
                #if UNITY_4_0_0 || UNITY_4_1 || UNITY_4_2
                Undo.RegisterUndo(ownerUnityObj, "Reset Node");
                #else
                Undo.RecordObject(ownerUnityObj, "Reset Node");
                #endif

                node.name = node.GetType().Name;
                node.Reset();
                node.OnValidate();
                StateUtility.SetDirty(node.owner);
            }
        }
コード例 #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");
        }
コード例 #3
0
        /// <summary>
        /// Saves a node.
        /// <param name="node">The target node to be saved.</param>
        /// </summary>
        void Save (ActionNode node) {
            // It's a valid node?
            if (node == null)
                return;

            Type type =  node.GetType();                    // get type
            m_NodeTypes.Add(type.ToString());               // save type
            m_NodeTypeHash.Add(TypeToHash(type));           // save type hash
            m_NodeFieldStartIndex.Add(m_NextFieldIndex);    // save the index of the first field
            m_BranchIndex.Add(node.branch != null ? node.branch.GetIndex() : -1);   // save the parent branch index

            // Save serialized fields
            FieldInfo[] fields = NodeSerialization.GetSerializedFields (type);
            for (int i = 0; i < fields.Length; i++) {
                var field = fields[i];
                SaveNodeField (field.FieldType, field.GetValue(node), field.Name);
                m_NextFieldIndex++;
            }
        }
コード例 #4
0
ファイル: SerializedNode.cs プロジェクト: xclouder/godbattle
     /// <summary>
     /// Class constructor. Create SerializedNode for inspected object.
     /// <param name="target">The node to get the be inspected.</param>
     /// </summary>
 	public SerializedNode (ActionNode target) {
         m_Target = target;
         m_Type = m_Target.GetType();
         m_RecreateData = true;
     }
コード例 #5
0
ファイル: NodeEditor.cs プロジェクト: xclouder/godbattle
        /// <summary>
        /// Draws the node inspector.
        /// <param name="target">The node that is being inspected.</param>
        /// </summary>
        public void DrawNode (ActionNode target) {
            // Create style?
            if (s_Styles == null)
                s_Styles = new NodeEditor.Styles();

            if (target == null) {
                m_SerializedNode = null;
                m_Target = null;
                m_TargetContent = GUIContent.none;
                m_TargetIconContent = GUIContent.none;
                m_TargetType = string.Empty;
            }
            // The target node has changed?
            else if (m_SerializedNode == null || m_SerializedNode.target != target) {
                m_SerializedNode = new SerializedNode(target);
                m_Target = target;

                Type targetType = m_Target.GetType();
                m_TargetType = " (" + targetType.Name + ")";
                var nodeInfo = AttributeUtility.GetAttribute<NodeInfoAttribute>(targetType, false) ?? new NodeInfoAttribute();
                m_TargetContent = new GUIContent(target.name + m_TargetType, null, nodeInfo.description);
                m_TargetIconContent = new GUIContent(IconUtility.GetIcon(targetType));

                // Update Values
                m_SerializedNode.Update();
            }

            // The serialized node is not null?
            if (m_SerializedNode != null) {
                // Draw node title
                this.DrawTitle();

                if (m_Target != null && BehaviourWindow.IsVisible(m_Target.instanceID)) {
                    // Draw node properties
                    this.OnInspectorGUI();

                    // Update target content?
                    if (Event.current.type == EventType.Used && m_Target != null) {
                        m_TargetContent.text = m_Target.name + m_TargetType;
                    }
                }
            }
        }