コード例 #1
0
        public void ReplaceAnimation(WorkspaceAnimation animation, Animator animator, int id, int overrideIndex, int resampleCount, bool linear, bool EulerFilter, double filterPrecision, string method, int insertPos, bool negateQuaternions, double filterTolerance)
        {
            AnimationClip clip = Parser.m_AnimationClips[id].instance;

            if (overrideIndex >= 0)
            {
                AnimatorOverrideController animatorOverride = (AnimatorOverrideController)Parser.file.Components[overrideIndex];
                clip = GetOverrideClip(clip, animatorOverride);
            }
            var replaceMethod = (ReplaceAnimationMethod)Enum.Parse(typeof(ReplaceAnimationMethod), method);

            Operations.ReplaceAnimation(animation, animator, clip, resampleCount, linear, EulerFilter, (float)filterPrecision, replaceMethod, insertPos, negateQuaternions, (float)filterTolerance);
            uint clipNameID = Animator.StringToHash(clip.m_Name);

            for (int i = 0; i < Parser.m_Controller.m_StateMachineArray.Length; i++)
            {
                StateMachineConstant stateMachine = Parser.m_Controller.m_StateMachineArray[i];
                for (int j = 0; j < stateMachine.m_StateConstantArray.Count; j++)
                {
                    StateConstant state = stateMachine.m_StateConstantArray[j];
                    if (state.m_NameID == clipNameID)
                    {
                        state.m_Speed = 1;

                        i = Parser.m_Controller.m_StateMachineArray.Length;
                        break;
                    }
                }
            }

            Changed = true;
        }
コード例 #2
0
        public void SetClipSpeed(int id, int overrideIndex, double speed)
        {
            AnimationClip clip = Parser.m_AnimationClips[id].instance;

            if (overrideIndex >= 0)
            {
                AnimatorOverrideController animatorOverride = (AnimatorOverrideController)Parser.file.Components[overrideIndex];
                clip = GetOverrideClip(clip, animatorOverride);
            }
            uint clipNameID = Animator.StringToHash(clip.m_Name);

            for (int i = 0; i < Parser.m_Controller.m_StateMachineArray.Length; i++)
            {
                StateMachineConstant stateMachine = Parser.m_Controller.m_StateMachineArray[i];
                for (int j = 0; j < stateMachine.m_StateConstantArray.Count; j++)
                {
                    StateConstant state = stateMachine.m_StateConstantArray[j];
                    if (state.m_NameID == clipNameID)
                    {
                        state.m_Speed = (float)speed;

                        i = Parser.m_Controller.m_StateMachineArray.Length;
                        break;
                    }
                }
            }

            Changed = true;
        }
コード例 #3
0
        public void SetClipAttributes(int id, int overrideIndex, double start, double stop, double rate, bool hq, int wrap, bool loopTime, bool keepY)
        {
            AnimationClip clip = Parser.m_AnimationClips[id].instance;

            if (overrideIndex >= 0)
            {
                AnimatorOverrideController animatorOverride = (AnimatorOverrideController)Parser.file.Components[overrideIndex];
                clip = GetOverrideClip(clip, animatorOverride);
            }
            Operations.SetClipAttributes(clip, start, stop, rate, hq, wrap, loopTime, keepY);
            uint clipNameID = Animator.StringToHash(clip.m_Name);

            for (int i = 0; i < Parser.m_Controller.m_StateMachineArray.Length; i++)
            {
                StateMachineConstant stateMachine = Parser.m_Controller.m_StateMachineArray[i];
                for (int j = 0; j < stateMachine.m_StateConstantArray.Count; j++)
                {
                    StateConstant state = stateMachine.m_StateConstantArray[j];
                    if (state.m_NameID == clipNameID)
                    {
                        state.m_Loop = loopTime;

                        i = Parser.m_Controller.m_StateMachineArray.Length;
                        break;
                    }
                }
            }

            Changed = true;
        }
コード例 #4
0
        public void RemoveStateConstant(int id, int overrideIndex)
        {
            AnimationClip clip = Parser.m_AnimationClips[id].instance;

            if (overrideIndex >= 0)
            {
                AnimatorOverrideController animatorOverride = (AnimatorOverrideController)Parser.file.Components[overrideIndex];
                clip = GetOverrideClip(clip, animatorOverride);
            }

            string clipName    = clip.m_Name;
            uint   stateNameID = Animator.StringToHash(clipName);

            for (int i = 0; i < Parser.m_Controller.m_StateMachineArray.Length; i++)
            {
                StateMachineConstant stateMachine = Parser.m_Controller.m_StateMachineArray[i];
                for (int j = 0; j < stateMachine.m_StateConstantArray.Count; j++)
                {
                    StateConstant state = stateMachine.m_StateConstantArray[j];
                    if (state.m_NameID == stateNameID)
                    {
                        stateMachine.m_StateConstantArray.RemoveAt(j);

                        bool nodeFound = false;
                        for (int k = 0; k < state.m_BlendTreeConstantArray.Length; k++)
                        {
                            BlendTreeConstant blend = state.m_BlendTreeConstantArray[k];
                            for (int l = 0; l < blend.m_NodeArray.Length; l++)
                            {
                                BlendTreeNodeConstant node = blend.m_NodeArray[l];
                                if (node.m_ClipID == id)
                                {
                                    nodeFound = true;
                                    break;
                                }
                            }
                            if (nodeFound)
                            {
                                break;
                            }
                        }
                        if (!nodeFound)
                        {
                            Report.ReportLog("Warning! StateConstant found for the clip " + clipName + " but it seems to have no BlendTreeNodeConstant. Still deleted.");
                        }
                        return;
                    }
                }
            }
        }
コード例 #5
0
        public void LoadFrom(Stream stream)
        {
            BinaryReader reader = new BinaryReader(stream);

            int numLayers = reader.ReadInt32();

            m_LayerArray = new LayerConstant[numLayers];
            for (int i = 0; i < numLayers; i++)
            {
                m_LayerArray[i] = new LayerConstant(stream);
            }

            int numStates = reader.ReadInt32();

            m_StateMachineArray = new StateMachineConstant[numStates];
            for (int i = 0; i < numStates; i++)
            {
                m_StateMachineArray[i] = new StateMachineConstant(stream);
            }

            m_Values        = new ValueArrayConstant(stream);
            m_DefaultValues = new ValueArray(stream);
        }
コード例 #6
0
        public void LoadFrom(Stream stream)
        {
            BinaryReader reader = new BinaryReader(stream);

            int numLayers = reader.ReadInt32();
            m_LayerArray = new LayerConstant[numLayers];
            for (int i = 0; i < numLayers; i++)
            {
                m_LayerArray[i] = new LayerConstant(stream);
            }

            int numStates = reader.ReadInt32();
            m_StateMachineArray = new StateMachineConstant[numStates];
            for (int i = 0; i < numStates; i++)
            {
                m_StateMachineArray[i] = new StateMachineConstant(stream);
            }

            m_Values = new ValueArrayConstant(stream);
            m_DefaultValues = new ValueArray(stream);
        }
コード例 #7
0
        public void CopyStateConstant(int id, int overrideIndex)
        {
            AnimationClip clip = Parser.m_AnimationClips[id].instance;

            if (overrideIndex >= 0)
            {
                AnimatorOverrideController animatorOverride = (AnimatorOverrideController)Parser.file.Components[overrideIndex];
                clip = GetOverrideClip(clip, animatorOverride);
            }

            string clipName    = clip.m_Name;
            uint   stateNameID = Animator.StringToHash(clipName);

            for (int i = 0; i < Parser.m_Controller.m_StateMachineArray.Length; i++)
            {
                StateMachineConstant stateMachine = Parser.m_Controller.m_StateMachineArray[i];
                bool stateFound = false;
                for (int j = 0; j < stateMachine.m_StateConstantArray.Count; j++)
                {
                    StateConstant state = stateMachine.m_StateConstantArray[j];
                    if (state.m_NameID == stateNameID)
                    {
                        bool nodeFound = false;
                        for (int k = 0; k < state.m_BlendTreeConstantArray.Length; k++)
                        {
                            BlendTreeConstant blend = state.m_BlendTreeConstantArray[k];
                            for (int l = 0; l < blend.m_NodeArray.Length; l++)
                            {
                                BlendTreeNodeConstant node = blend.m_NodeArray[l];
                                if (node.m_ClipID == id)
                                {
                                    nodeFound = true;
                                    break;
                                }
                            }
                            if (nodeFound)
                            {
                                break;
                            }
                        }
                        if (!nodeFound)
                        {
                            Report.ReportLog("Warning! StateConstant found for the clip " + clipName + " but it seems to have no BlendTreeNodeConstant. No new StateConstant created.");
                        }
                        stateFound = true;
                        break;
                    }
                }
                if (!stateFound)
                {
                    for (int j = 0; j < stateMachine.m_StateConstantArray.Count; j++)
                    {
                        StateConstant state = stateMachine.m_StateConstantArray[j];
                        for (int k = 0; k < state.m_BlendTreeConstantArray.Length; k++)
                        {
                            BlendTreeConstant blend = state.m_BlendTreeConstantArray[k];
                            if (blend.m_NodeArray.Length > 0)
                            {
                                string baseLayerName = null;
                                using (Stream stream = new MemoryStream())
                                {
                                    state.WriteTo(stream, Parser.file.VersionNumber);

                                    stream.Position = 0;
                                    StateConstant destState = new StateConstant(stream, Parser.file.VersionNumber);
                                    stateMachine.m_StateConstantArray.Add(destState);

                                    Parser.AddString(clipName);
                                    foreach (SelectorStateConstant selector in stateMachine.m_SelectorStateConstantArray)
                                    {
                                        KeyValuePair <uint, string> layerEntry = Parser.m_TOS.Find
                                                                                 (
                                            delegate(KeyValuePair <uint, string> entry)
                                        {
                                            return(entry.Key == selector.m_FullPathID);
                                        }
                                                                                 );
                                        if (layerEntry.Key != 0)
                                        {
                                            baseLayerName = layerEntry.Value;
                                            break;
                                        }
                                    }
                                    string clipBaseName = baseLayerName + "." + clipName;
                                    uint   statePathID  = Parser.AddString(clipBaseName);
                                    destState.m_NameID = stateNameID;
                                    destState.m_PathID = destState.m_FullPathID = statePathID;

                                    destState.m_BlendTreeConstantArray[0].m_NodeArray[0].m_ClipID = (uint)id;
                                }
                                string sourceClipName  = null;
                                int    sourceClipIndex = (int)state.m_BlendTreeConstantArray[0].m_NodeArray[0].m_ClipID;
                                if (sourceClipIndex >= 0 && sourceClipIndex < Parser.m_AnimationClips.Count)
                                {
                                    AnimationClip sourceClip = Parser.m_AnimationClips[sourceClipIndex].instance;
                                    if (sourceClip != null)
                                    {
                                        sourceClipName = sourceClip.m_Name;
                                    }
                                }
                                Report.ReportLog("StateConstant in StateMachineArray[" + i + "] for clip " + clipName + " added (copied from clip " + (sourceClipName != null ? sourceClipName : "index " + sourceClipIndex) + "). Used Layer \"" + baseLayerName + "\", BlendArrayLength=" + state.m_BlendTreeConstantArray.Length + ", BlendTree entry=" + k + " with " + blend.m_NodeArray.Length + " node(s) used.");
                                Changed = true;

                                stateFound = true;
                                break;
                            }
                        }
                        if (stateFound)
                        {
                            break;
                        }
                    }
                    if (!stateFound)
                    {
                        Report.ReportLog("Warning! No StateConstant found as template in StateMachineArray[" + i + "] with BlendTreeNodeConstant. Skipped.");
                    }
                }
            }
        }