public void LoadFrom(Stream stream) { BinaryReader reader = new BinaryReader(stream); int numBlends = reader.ReadInt32(); m_NodeArray = new BlendTreeNodeConstant[numBlends]; for (int i = 0; i < numBlends; i++) { m_NodeArray[i] = new BlendTreeNodeConstant(stream); } }
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; } } } }
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."); } } } }