public void parseXml(XmlElement elem) { m_layerList.Clear(); XmlNodeList layersNodeList = elem.SelectNodes("Layer"); XmlElement layerElem = null; XmlLayer layer; foreach (XmlNode layerNode in layersNodeList) { layerElem = (XmlElement)layerNode; layer = new XmlLayer(); m_layerList.Add(layer); layer.xmlLayers = this; layer.parseXml(layerElem); } }
// 添加状态机之间的转换 static public void BuildStateMachineTransition(XmlLayer xmlLayer) { XmlStateMachine xmlSrcStateMachine = null; XmlStateMachine xmlDestStateMachine = null; XmlState xmlDestState = null; foreach (var stateMachineTransition in xmlLayer.xmlStateMachineTransitionList) { xmlSrcStateMachine = xmlLayer.getXmlStateMachineByName(stateMachineTransition.srcStateMachineName); xmlDestStateMachine = xmlLayer.getXmlStateMachineByName(stateMachineTransition.destStateMachineName); xmlDestState = xmlDestStateMachine.getXmlStateByName(stateMachineTransition.destStateName); stateMachineTransition.animatorTransition = xmlSrcStateMachine.animatorStateMachine.AddStateMachineTransition(xmlDestStateMachine.animatorStateMachine, xmlDestState.animatorState); //stateMachineTransition.animatorTransition = xmlDestStateMachine.animatorStateMachine.AddStateMachineTransition(xmlSrcStateMachine.animatorStateMachine, xmlDestState.animatorState); } }
static public void BuildAnimationStateLayer(XmlLayer xmlLayer) { int stateMachineIdx = 0; AnimatorStateMachine stateMachine = null; for (stateMachineIdx = 0; stateMachineIdx < xmlLayer.stateMachineList.Count; ++stateMachineIdx) { // 获取当前状态机 if (0 == stateMachineIdx) // 系统默认创建一个主动画状态机,自状态机需要自己创建 { stateMachine = xmlLayer.animatorControllerLayer.stateMachine; xmlLayer.stateMachineList[stateMachineIdx].animatorStateMachine = stateMachine; stateMachine.name = xmlLayer.stateMachineList[stateMachineIdx].name; } else // 自状态机需要从主状态机创建 { xmlLayer.stateMachineList[stateMachineIdx].animatorStateMachine = xmlLayer.stateMachineList[0].animatorStateMachine.AddStateMachine(xmlLayer.stateMachineList[stateMachineIdx].name, xmlLayer.stateMachineList[stateMachineIdx].pos); } BuildAnimationStateMachine(xmlLayer.stateMachineList[stateMachineIdx]); BuildStateTransition(xmlLayer.stateMachineList[stateMachineIdx]); } }