Beispiel #1
0
 public void Remove(YamlType pYamlType, Yaml_BaseObject pObject)
 {
     if (!mCurrentDic.ContainsKey(pYamlType) || mCurrentDic[pYamlType] == null)
     {
         return;
     }
     mCurrentDic[pYamlType].Remove(pObject);
 }
Beispiel #2
0
 public void Add(YamlType pYamlType, Yaml_BaseObject pObject)
 {
     if (!mCurrentDic.ContainsKey(pYamlType))
     {
         mCurrentDic.Add(pYamlType, new List <Yaml_BaseObject>());
     }
     mCurrentDic[pYamlType].Add(pObject);
 }
Beispiel #3
0
    static public T GetObject <T>(this Yaml_BaseObject pObject, string pFileID) where T : Yaml_BaseObject
    {
        if (pObject == null)
        {
            return(default(T));
        }
        var tResolver = GetResolver(pObject.fullPath);

        return(tResolver == null ? default(T) : tResolver.GetObject <T>(pFileID));
    }
Beispiel #4
0
    public void Resolve(string pFullPath)
    {
        mCurrentDic = new Dictionary <YamlType, List <Yaml_BaseObject> >();
        Yaml_BaseObject tLastObject = null;

        using (StreamReader tReader = new StreamReader(pFullPath))
        {
            while (!tReader.EndOfStream)
            {
                var tContent = tReader.ReadLine();
                if (string.IsNullOrEmpty(tContent))
                {
                    continue;
                }
                var tMatch = Regex.Match(tContent, @"--- !u!(?<yamlType>\d+) &(?<fileID>\d+)");
                if (!tMatch.Success)
                {
                    if (tLastObject == null)
                    {
                        continue;
                    }
                    tLastObject.Resolver(tContent);

                    if (tLastObject.GetType() == typeof(Yaml_MonoBehaviour))
                    {
                        var tScript = tLastObject as Yaml_MonoBehaviour;
                        if (string.IsNullOrEmpty(tScript.scriptGuid))
                        {
                            continue;
                        }
                        Yaml_MonoBehaviour tTempScript = null;
                        if (sScriptTypeDic.ContainsKey(tScript.scriptGuid))
                        {
                            var tMonoScript = sScriptTypeDic[tScript.scriptGuid];
                            tTempScript = Activator.CreateInstance(tMonoScript, tScript) as Yaml_MonoBehaviour;
                        }

                        if (tTempScript != null)
                        {
                            Remove(YamlType.Monobehaviour, tLastObject);
                            tLastObject = tTempScript;
                            Add(YamlType.Monobehaviour, tLastObject);
                        }
                    }
                    continue;
                }
                var tVal         = tMatch.Groups["yamlType"].Value;
                var tFileID      = tMatch.Groups["fileID"].Value;
                var tYamlTypeVal = 0;
                if (!int.TryParse(tVal, out tYamlTypeVal))
                {
                    continue;
                }
                var tYamlType = (YamlType)tYamlTypeVal;
                if (tYamlType == YamlType.Unknown)
                {
                    continue;
                }
                switch (tYamlType)
                {
                case YamlType.GameObject:
                    tLastObject = new Yaml_GameObject(new Yaml_BaseArg(tFileID, pFullPath, tYamlType));
                    break;

                case YamlType.Transform:
                    tLastObject = new Yaml_Trasnform(new Yaml_BaseArg(tFileID, pFullPath, tYamlType));
                    break;

                case YamlType.Monobehaviour:
                    tLastObject = new Yaml_MonoBehaviour(new Yaml_BaseArg(tFileID, pFullPath, tYamlType));
                    break;

                case YamlType.Prefab:
                    prefabRoot  = new Yaml_Prefab(new Yaml_BaseArg(tFileID, pFullPath, tYamlType));
                    tLastObject = prefabRoot;
                    break;
                }
                Add(tYamlType, tLastObject);
            }
        }
        if (prefabRoot == null)
        {
            throw new NullReferenceException("找不到根节点");
        }
        prefabRoot.ToTreeStruct();
    }