public YamlGradient(YamlMappingNode mainNode) { /* * foreach (var pair in mainNode.Children) * { * Debug.LogWarning(pair.Key + " @ " + pair.Value); * } */ MainNode = mainNode; NumColorKeysNode = YamlObjectUtil.SearchMappingChildNode <YamlScalarNode>(mainNode, "m_NumColorKeys"); NumAlphaKeysNode = YamlObjectUtil.SearchMappingChildNode <YamlScalarNode>(mainNode, "m_NumAlphaKeys"); int length = MaxKeyLength; ColorList = new List <YamlColor>(length); CtimeKeyListNode = new List <YamlScalarNode>(length); AtimeKeyListNode = new List <YamlScalarNode>(length); for (int i = 0; i < length; i++) { string key = "key" + i; string akey = "atime" + i; string ckey = "ctime" + i; var kcNode = YamlObjectUtil.SearchMappingChildNode <YamlMappingNode>(mainNode, key); var cNode = YamlObjectUtil.SearchMappingChildNode <YamlScalarNode>(mainNode, ckey); var aNode = YamlObjectUtil.SearchMappingChildNode <YamlScalarNode>(mainNode, akey); ColorList.Add(new YamlColor(kcNode)); CtimeKeyListNode.Add(cNode); AtimeKeyListNode.Add(aNode); } }
public override void YamlInit(YamlDataContext context) { base.YamlInit(context); var p = YamlObjectUtil.GetMappingValueNode(YamlNode); if (p == null) { return; } NameNode = YamlObjectUtil.SearchMappingChildNode <YamlScalarNode>(p, "m_Name"); ComponmentNode = YamlObjectUtil.SearchMappingChildNode <YamlSequenceNode>(p, "m_Component"); Componments = new List <YamlComponment>(); foreach (var c in ComponmentNode.Children) { YamlMappingNode child = c as YamlMappingNode; if (child == null) { continue; } YamlKeyLocalRef r = new YamlKeyLocalRef(child); YamlUnityObject yo = null; if (context.ObjectIdMap.TryGetValue(r.RefId, out yo)) { Componments.Add(yo as YamlComponment); } } Transofrm = GetComponment <YamlTransform>(); }
public override void YamlInit(YamlDataContext context) { base.YamlInit(context); var p = YamlObjectUtil.GetMappingValueNode <YamlMappingNode>(YamlNode); if (p != null) { ChildrenNode = YamlObjectUtil.SearchMappingChildNode <YamlSequenceNode>(p, "m_Children"); } var fatherNode = YamlObjectUtil.SearchMappingChildNode <YamlMappingNode>(p, "m_Father"); //Debug.LogError(fatherNode); Father = YamlObjectUtil.SearchMappingChildNode <YamlScalarNode>(fatherNode, "fileID"); Children = new List <YamlTransform>(); foreach (YamlMappingNode cn in ChildrenNode) { var c = YamlObjectUtil.SearchMappingChildNode <YamlScalarNode>(cn, "fileID"); YamlUnityObject yo = null; if (context.ObjectIdMap.TryGetValue(c.Value, out yo)) { //Debug.LogWarning("ADD CHILD :" + yo.ObjectName + " => " +ObjectName); Children.Add(yo as YamlTransform); } } }
public YamlKeyLocalRef(YamlMappingNode node) { var p = YamlObjectUtil.GetMappingValueNode <YamlMappingNode>(node); if (p != null) { RefIdNode = YamlObjectUtil.SearchMappingChildNode <YamlScalarNode>(p, "fileID"); } }
public YamlParticleInitialModule(YamlMappingNode mainNode) { InitialModuleNode = mainNode; StartLifeTime = new YamlMinMaxCurve(GetNode("startLifetime")); StartSpeed = new YamlMinMaxCurve(GetNode("startSpeed")); //color... StartColor = new YamlMinMaxGradient(GetNode("startColor")); StartSize = new YamlMinMaxCurve(GetNode("startSize")); StartRotationX = new YamlMinMaxCurve(GetNode("startRotationX")); StartRotationY = new YamlMinMaxCurve(GetNode("startRotationY")); StartRotation = new YamlMinMaxCurve(GetNode("startRotation")); Rotation3DNode = YamlObjectUtil.SearchMappingChildNode <YamlScalarNode>(InitialModuleNode, "rotation3D"); MaxNumParticlesNode = YamlObjectUtil.SearchMappingChildNode <YamlScalarNode>(InitialModuleNode, "maxNumParticles"); }
public YamlMinMaxGradient(YamlMappingNode mainNode) { /* * foreach (var pair in mainNode.Children) * { * Debug.LogWarning(pair.Key + " @ " + pair.Value); * } * Debug.LogWarning("================="); */ MainNode = mainNode; MaxGradient = new YamlGradient(YamlObjectUtil.SearchMappingChildNode <YamlMappingNode>(mainNode, "maxGradient")); MinGradient = new YamlGradient(YamlObjectUtil.SearchMappingChildNode <YamlMappingNode>(mainNode, "minGradient")); MinColor = new YamlColor(YamlObjectUtil.SearchMappingChildNode <YamlMappingNode>(mainNode, "minColor")); MaxColor = new YamlColor(YamlObjectUtil.SearchMappingChildNode <YamlMappingNode>(mainNode, "maxColor")); MinMaxStateNode = YamlObjectUtil.SearchMappingChildNode <YamlScalarNode>(mainNode, "minMaxState"); }
public override void YamlInit(YamlDataContext context) { base.YamlInit(context); var p = YamlObjectUtil.GetMappingValueNode(YamlNode); if (p == null) { return; } YamlNode node = null; if (p.Children.TryGetValue("InitialModule", out node)) { InitialModuleNode = node as YamlMappingNode; InitialModule = new YamlParticleInitialModule(InitialModuleNode); } StartDelay = new YamlMinMaxCurve(YamlObjectUtil.SearchMappingChildNode <YamlMappingNode>(p, "startDelay")); PrewarmNode = YamlObjectUtil.SearchMappingChildNode <YamlScalarNode>(p, "prewarm"); LengthInSecNode = YamlObjectUtil.SearchMappingChildNode <YamlScalarNode>(p, "lengthInSec"); }
//16进制转成10进制 RGBA public YamlColor(YamlMappingNode mainNode) { ColorNode = YamlObjectUtil.SearchMappingChildNode <YamlScalarNode>(mainNode, "rgba"); }
public YamlMappingNode GetNode(string key) { return(YamlObjectUtil.SearchMappingChildNode <YamlMappingNode>(InitialModuleNode, key)); }
private void Parse(YamlStream yaml, List <YamlObjectInfo> infoList, List <YamlMappingNode> nodeList) { string rootGameObjectId = ""; DataContext = new YamlDataContext(); //--解析 YAML 文件-- 缓存所有对象-- Yaml = yaml; InfoList = infoList; NodeList = nodeList; int length = Mathf.Min(infoList.Count, nodeList.Count); for (int i = 0; i < length; i++) { string typeStr; try { typeStr = nodeList[i].Children.First().Key.ToString(); } catch (Exception) { typeStr = "error parse type -- list node"; foreach (var pair in nodeList[i].Children) { Debug.LogWarning(pair.Key + " : " + pair.Value); } } YamlUnityObject yo = YamlObjectFactory.Create(typeStr); if (yo != null) { yo.SetLocalInfo(infoList[i].TypeId, infoList[i].LocalId); yo.SetYamlNode(nodeList[i]); ObjectIdMap.Add(yo.LocalId, yo); } if (typeStr == "Prefab") { //是prefab!记录一下ID var p = YamlObjectUtil.GetMappingValueNode(nodeList[i]); YamlMappingNode r = YamlObjectUtil.SearchMappingChildNode(p, "m_RootGameObject") as YamlMappingNode; if (r != null) { rootGameObjectId = YamlObjectUtil.SearchMappingChildNode(r, "fileID").ToString(); } //Debug.LogWarning("root gameobject = " + rootGameObjectId); } } //---重新关联组件对象--- foreach (var pair in ObjectIdMap) { //Debug.Log(string.Format("id:{0}, object:{1}", pair.Key, pair.Value.TypeName)); var type = pair.Value.GetType(); var obj = pair.Value; if (type != typeof(YamlGameObject)) { string attachId = obj.GetAttachId(); //找到attachId try { obj.SetAttachGameObject(ObjectIdMap[attachId] as YamlGameObject); } catch (Exception e) { Debug.LogError(e); } } else { obj.SetAttachGameObject(obj as YamlGameObject); } } DataContext.ObjectIdMap = ObjectIdMap; //--关联结束后,初始化GOMEOBJECT-- foreach (var pair in ObjectIdMap) { var go = pair.Value as YamlGameObject; if (go != null) { go.GameObjectInit(DataContext); } } //--设置prefab的根gameobject if (!string.IsNullOrEmpty(rootGameObjectId)) { RootGameObject = ObjectIdMap[rootGameObjectId] as YamlGameObject; } RootGameObject.Transofrm.RootTransofrmInit(DataContext); }