Exemplo n.º 1
0
        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>();
        }
Exemplo n.º 2
0
        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);
                }
            }
        }
Exemplo n.º 3
0
        public void ModifyNode(string kName, string v)
        {
            var p = YamlObjectUtil.GetMappingValueNode(YamlNode);

            if (p == null)
            {
                return;
            }
            YamlNode node = null;

            if (p.Children.TryGetValue(kName, out node))
            {
                YamlScalarNode scal = node as YamlScalarNode;
                if (scal == null)
                {
                    return;
                }
                string ori = scal.Value;
                scal.Value = v;
                Debug.Log(string.Format("{0} : value modify : {1}->{2}", kName, ori, v));
            }
            else
            {
                Debug.LogError("modify node error: " + kName);
            }
        }
Exemplo n.º 4
0
        public YamlKeyLocalRef(YamlMappingNode node)
        {
            var p = YamlObjectUtil.GetMappingValueNode <YamlMappingNode>(node);

            if (p != null)
            {
                RefIdNode = YamlObjectUtil.SearchMappingChildNode <YamlScalarNode>(p, "fileID");
            }
        }
Exemplo n.º 5
0
        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");
        }
Exemplo n.º 6
0
        public string GetNodeString(string kName)
        {
            var p = YamlObjectUtil.GetMappingValueNode(YamlNode);

            if (p == null)
            {
                return("");
            }
            YamlNode node = null;

            if (p.Children.TryGetValue(kName, out node))
            {
                YamlScalarNode scal = node as YamlScalarNode;
                if (scal == null)
                {
                    return("");
                }
                return(scal.Value);
            }
            return("");
        }
Exemplo n.º 7
0
        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);
        }