コード例 #1
0
ファイル: GraphGUI.cs プロジェクト: wensincai/Unity5.4
        private void LiveLink()
        {
            this.m_LiveLinkInfo.Clear();
            if (!this.tool.liveLink)
            {
                return;
            }
            AnimatorControllerPlayable controller = AnimatorController.FindAnimatorControllerPlayable(this.tool.previewAnimator, this.tool.animatorController);

            if (!controller.node.IsValid())
            {
                return;
            }
            AnimatorStateInfo      currentAnimatorStateInfo = controller.GetCurrentAnimatorStateInfo(AnimatorControllerTool.tool.selectedLayerIndex);
            AnimatorStateInfo      nextAnimatorStateInfo    = controller.GetNextAnimatorStateInfo(AnimatorControllerTool.tool.selectedLayerIndex);
            AnimatorTransitionInfo animatorTransitionInfo   = controller.GetAnimatorTransitionInfo(AnimatorControllerTool.tool.selectedLayerIndex);
            int shortNameHash  = currentAnimatorStateInfo.shortNameHash;
            int shortNameHash2 = nextAnimatorStateInfo.shortNameHash;

            this.m_LiveLinkInfo.currentStateMachine        = ((shortNameHash == 0) ? null : this.rootStateMachine.FindStateMachine(this.ResolveHash(controller, currentAnimatorStateInfo.fullPathHash)));
            this.m_LiveLinkInfo.currentState               = ((shortNameHash == 0) ? null : this.m_LiveLinkInfo.currentStateMachine.FindState(shortNameHash).state);
            this.m_LiveLinkInfo.currentStateNormalizedTime = currentAnimatorStateInfo.normalizedTime;
            this.m_LiveLinkInfo.currentStateLoopTime       = currentAnimatorStateInfo.loop;
            if (this.m_LiveLinkInfo.currentState == null)
            {
                return;
            }
            this.m_LiveLinkInfo.nextStateMachine        = ((shortNameHash2 == 0) ? null : this.rootStateMachine.FindStateMachine(this.ResolveHash(controller, nextAnimatorStateInfo.fullPathHash)));
            this.m_LiveLinkInfo.nextState               = ((shortNameHash2 == 0) ? null : this.m_LiveLinkInfo.nextStateMachine.FindState(shortNameHash2).state);
            this.m_LiveLinkInfo.nextStateNormalizedTime = nextAnimatorStateInfo.normalizedTime;
            this.m_LiveLinkInfo.nextStateLoopTime       = nextAnimatorStateInfo.loop;
            this.m_LiveLinkInfo.srcNode        = this.stateMachineGraph.FindNode(this.m_LiveLinkInfo.currentState);
            this.m_LiveLinkInfo.dstNode        = ((!this.m_LiveLinkInfo.nextState) ? null : this.stateMachineGraph.FindNode(this.m_LiveLinkInfo.nextState));
            this.m_LiveLinkInfo.transitionInfo = animatorTransitionInfo;
            if (this.tool.autoLiveLink)
            {
                AnimatorStateMachine animatorStateMachine = this.m_LiveLinkInfo.currentStateMachine;
                if (this.m_LiveLinkInfo.currentState != null && this.m_LiveLinkInfo.nextState != null && ((double)this.m_LiveLinkInfo.transitionInfo.normalizedTime > 0.5 || animatorTransitionInfo.anyState))
                {
                    animatorStateMachine = this.m_LiveLinkInfo.nextStateMachine;
                }
                if (shortNameHash != 0 && animatorStateMachine != this.activeStateMachine && Event.current.type == EventType.Repaint)
                {
                    List <AnimatorStateMachine> hierarchy = new List <AnimatorStateMachine>();
                    MecanimUtilities.StateMachineRelativePath(this.rootStateMachine, animatorStateMachine, ref hierarchy);
                    this.tool.BuildBreadCrumbsFromSMHierarchy(hierarchy);
                }
            }
        }
コード例 #2
0
ファイル: StateNode.cs プロジェクト: wensincai/Unity5.4
        private void AddNewBlendTreeCallback()
        {
            Motion               stateEffectiveMotion = AnimatorControllerTool.tool.animatorController.GetStateEffectiveMotion(this.state, AnimatorControllerTool.tool.selectedLayerIndex);
            BlendTree            blendTree            = stateEffectiveMotion as BlendTree;
            AnimatorStateMachine stateMachine         = AnimatorControllerTool.tool.animatorController.layers[AnimatorControllerTool.tool.selectedLayerIndex].stateMachine;
            bool flag = true;

            if (blendTree != null)
            {
                string title   = "This will delete current BlendTree in state.";
                string message = "You cannot undo this action.";
                if (EditorUtility.DisplayDialog(title, message, "Delete", "Cancel"))
                {
                    MecanimUtilities.DestroyBlendTreeRecursive(blendTree);
                }
                else
                {
                    flag = false;
                }
            }
            else
            {
                Undo.RegisterCompleteObjectUndo(stateMachine, "Blend Tree Added");
            }
            if (flag)
            {
                BlendTree blendTree2 = new BlendTree();
                blendTree2.hideFlags = HideFlags.HideInHierarchy;
                if (AssetDatabase.GetAssetPath(AnimatorControllerTool.tool.animatorController) != string.Empty)
                {
                    AssetDatabase.AddObjectToAsset(blendTree2, AssetDatabase.GetAssetPath(AnimatorControllerTool.tool.animatorController));
                }
                blendTree2.name = "Blend Tree";
                BlendTree arg_10B_0 = blendTree2;
                string    defaultBlendTreeParameter = AnimatorControllerTool.tool.animatorController.GetDefaultBlendTreeParameter();
                blendTree2.blendParameterY = defaultBlendTreeParameter;
                arg_10B_0.blendParameter   = defaultBlendTreeParameter;
                AnimatorControllerTool.tool.animatorController.SetStateEffectiveMotion(this.state, blendTree2, AnimatorControllerTool.tool.selectedLayerIndex);
            }
        }
コード例 #3
0
 public void RemoveNodeMotions(IEnumerable <UnityEditor.Graphs.Node> nodes)
 {
     foreach (UnityEditor.Graphs.Node current in nodes)
     {
         Node node = current as Node;
         if (!(this.m_RootBlendTree == node.motion))
         {
             if (!(node.motion == null))
             {
                 if (node.parent)
                 {
                     BlendTree blendTree = node.parent.motion as BlendTree;
                     int       index     = Graph.FindMotionIndexOnBlendTree(blendTree, node.motion);
                     blendTree.RemoveChild(index);
                 }
                 BlendTree blendTree2 = node.motion as BlendTree;
                 if (blendTree2 && MecanimUtilities.AreSameAsset(this.m_RootBlendTree, blendTree2))
                 {
                     MecanimUtilities.DestroyBlendTreeRecursive(blendTree2);
                 }
             }
         }
     }
 }