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 LoadFrom(Stream stream) { BinaryReader reader = new BinaryReader(stream); int numTransistions = reader.ReadInt32(); m_TransitionConstantArray = new TransitionConstant[numTransistions]; for (int i = 0; i < numTransistions; i++) { m_TransitionConstantArray[i] = new TransitionConstant(stream); } int numBlendIndices = reader.ReadInt32(); m_BlendTreeConstantIndexArray = new int[numBlendIndices]; for (int i = 0; i < numBlendIndices; i++) { m_BlendTreeConstantIndexArray[i] = reader.ReadInt32(); } int numInfos = reader.ReadInt32(); m_LeafInfoArray = new LeafInfoConstant[numInfos]; for (int i = 0; i < numInfos; i++) { m_LeafInfoArray[i] = new LeafInfoConstant(stream); } int numBlends = reader.ReadInt32(); m_BlendTreeConstantArray = new BlendTreeConstant[numBlends]; for (int i = 0; i < numBlends; i++) { m_BlendTreeConstantArray[i] = new BlendTreeConstant(stream); } m_NameID = reader.ReadUInt32(); m_PathID = reader.ReadUInt32(); m_TagID = reader.ReadUInt32(); m_Speed = reader.ReadSingle(); m_CycleOffset = reader.ReadSingle(); m_IKOnFeet = reader.ReadBoolean(); m_Loop = reader.ReadBoolean(); m_Mirror = reader.ReadBoolean(); reader.ReadByte(); }
public void LoadFrom(Stream stream, uint version) { BinaryReader reader = new BinaryReader(stream); int numTransistions = reader.ReadInt32(); m_TransitionConstantArray = new TransitionConstant[numTransistions]; for (int i = 0; i < numTransistions; i++) { m_TransitionConstantArray[i] = new TransitionConstant(stream, version); } int numBlendIndices = reader.ReadInt32(); m_BlendTreeConstantIndexArray = new int[numBlendIndices]; for (int i = 0; i < numBlendIndices; i++) { m_BlendTreeConstantIndexArray[i] = reader.ReadInt32(); } if (version < AssetCabinet.VERSION_5_0_0) { int numInfos = reader.ReadInt32(); m_LeafInfoArray = new LeafInfoConstant[numInfos]; for (int i = 0; i < numInfos; i++) { m_LeafInfoArray[i] = new LeafInfoConstant(stream); } } int numBlends = reader.ReadInt32(); m_BlendTreeConstantArray = new BlendTreeConstant[numBlends]; for (int i = 0; i < numBlends; i++) { m_BlendTreeConstantArray[i] = new BlendTreeConstant(stream, version); } m_NameID = reader.ReadUInt32(); m_PathID = reader.ReadUInt32(); if (version >= AssetCabinet.VERSION_5_0_0) { m_FullPathID = reader.ReadUInt32(); } m_TagID = reader.ReadUInt32(); if (version >= AssetCabinet.VERSION_5_0_0) { m_SpeedParamID = reader.ReadUInt32(); m_MirrorParamID = reader.ReadUInt32(); m_CycleOffsetParamID = reader.ReadUInt32(); } m_Speed = reader.ReadSingle(); m_CycleOffset = reader.ReadSingle(); m_IKOnFeet = reader.ReadBoolean(); if (version >= AssetCabinet.VERSION_5_0_0) { m_WriteDefaultValues = reader.ReadBoolean(); } m_Loop = reader.ReadBoolean(); m_Mirror = reader.ReadBoolean(); if (version < AssetCabinet.VERSION_5_0_0) { stream.Position++; } }
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."); } } } }