static public void BuildAnimationClip(XmlClip xmlClip) { AnimationClip clip = null; int idx = 0; UnityEngine.Object[] assetArr = null; XmlState xmlState = null; AnimatorState animatorState; //AnimationClip clip = AssetDatabase.LoadAssetAtPath(state.fullMotion, typeof(AnimationClip)) as AnimationClip; clip = null; idx = 0; string preFixStr = "__preview__"; assetArr = AssetDatabase.LoadAllAssetsAtPath(xmlClip.fullMotion); // 一个 anim 就一个动画,但是一个 fbx 可能有多个动画,因此同一使用这个加载资源,否则只能加载第一个。在 fbx 中还会有一个奇怪的 Clip ,名字类似 "__preview___72_a_U1_M_P_PlantNTurn90_Run_R_Fb_p90_No_0_PJ_4",这个也要排除,排除 Clip 前缀是 "__preview__" 的 Clip 就行了 for (idx = 0; idx < assetArr.Length; ++idx) { clip = assetArr[idx] as AnimationClip; if (clip != null) { if (!clip.name.Contains(preFixStr)) { xmlState = xmlClip.getXmlStateByName(clip.name); animatorState = xmlClip.stateMachine.animatorStateMachine.AddState(clip.name); xmlState.animatorState = animatorState; animatorState.motion = clip; BuildState(xmlState); } } } }
public void parseXml(XmlElement elem) { clear(); m_name = ExportUtil.getXmlAttrStr(elem.Attributes["name"]); m_pos = ExportUtil.getXmlAttrVector3(elem.Attributes["pos"]); // 解析没有动画文件的 State XmlNodeList noStateNodeList = elem.SelectNodes("State"); XmlElement stateElem = null; XmlState state = null; foreach (XmlNode stateNode in noStateNodeList) { stateElem = (XmlElement)stateNode; state = new XmlState(); state.stateMachine = this; m_noResStateList.Add(state); state.parseXml(stateElem); } // 解析有动画资源文件的 State XmlNodeList clipNodeList = elem.SelectNodes("Clip"); XmlElement clipElem = null; XmlClip _clip; foreach (XmlNode clipNode in clipNodeList) { clipElem = (XmlElement)clipNode; _clip = new XmlClip(); _clip.stateMachine = this; m_clipList.Add(_clip); _clip.parseXml(clipElem); } // 解析状态机中的转换 XmlNodeList tranNodeList = elem.SelectNodes("StateTransition"); XmlElement tranElem = null; XmlStateTransition _tran; foreach (XmlNode tranNode in tranNodeList) { tranElem = (XmlElement)tranNode; _tran = new XmlStateTransition(); _tran.stateMachine = this; m_tranList.Add(_tran); _tran.parseXml(tranElem); } }