private static bool IsUpdateRequired(GameObject storageGo, int patchCounter)
    {
        PersistentClassMappingsStorage storage = storageGo.GetComponent <PersistentClassMappingsStorage>();

        if (storage == null)
        {
            return(false);
        }
        return(storage.PatchCounter < patchCounter);
    }
    //2.2 -> 2.2.1
    private static void UpdateMappedAssemblyNames2(string storagePath)
    {
        GameObject storageGO = (GameObject)AssetDatabase.LoadAssetAtPath(storagePath, typeof(GameObject));

        if (storageGO == null)
        {
            return;
        }

        if (!IsUpdateRequired(storageGO, 3))
        {
            return;
        }

        storageGO = Instantiate(storageGO);
        PersistentClassMappingsStorage storage = storageGO.GetComponent <PersistentClassMappingsStorage>();

        if (storage == null)
        {
            storage = storageGO.AddComponent <PersistentClassMappingsStorage>();
        }
        storage.Version      = RTSLVersion.Version.ToString();
        storage.PatchCounter = 3;

        PersistentClassMapping[] mappings = storageGO.GetComponentsInChildren <PersistentClassMapping>(true);
        for (int i = 0; i < mappings.Length; ++i)
        {
            PersistentClassMapping mapping = mappings[i];
            mapping.Version            = RTSLVersion.Version.ToString();
            mapping.MappedTypeName     = FixTypeName2(mapping.MappedTypeName);
            mapping.MappedAssemblyName = FixAssemblyName2(mapping.MappedAssemblyQualifiedName, mapping.MappedNamespace, mapping.MappedAssemblyName);

            PersistentPropertyMapping[] properties = mapping.PropertyMappings;
            for (int j = 0; j < properties.Length; ++j)
            {
                PersistentPropertyMapping property = properties[j];
                property.MappedTypeName     = FixTypeName2(property.MappedTypeName);
                property.MappedAssemblyName = FixAssemblyName2(property.MappedAssemblyQualifiedName, property.MappedNamespace, property.MappedAssemblyName);
            }
        }

        EditorUtility.SetDirty(storageGO);
        PrefabUtility.SaveAsPrefabAsset(storageGO, storagePath);
        DestroyImmediate(storageGO);
    }
    //2.05 -> 2.1
    private static void UpdateTags(string storagePath)
    {
        GameObject storageGO = (GameObject)AssetDatabase.LoadAssetAtPath(storagePath, typeof(GameObject));

        if (storageGO == null)
        {
            return;
        }

        if (!IsUpdateRequired(storageGO, 1))
        {
            return;
        }

        storageGO = Instantiate(storageGO);
        PersistentClassMappingsStorage storage = storageGO.GetComponent <PersistentClassMappingsStorage>();

        if (storage == null)
        {
            storage = storageGO.AddComponent <PersistentClassMappingsStorage>();
        }
        storage.Version      = new Version(2, 1).ToString();
        storage.PatchCounter = 1;

        PersistentClassMapping[] mappings = storageGO.GetComponentsInChildren <PersistentClassMapping>(true);
        for (int i = 0; i < mappings.Length; ++i)
        {
            PersistentClassMapping      mapping    = mappings[i];
            PersistentPropertyMapping[] properties = mapping.PropertyMappings;
            for (int j = 0; j < properties.Length; ++j)
            {
                PersistentPropertyMapping property = properties[j];
                property.PersistentTag        = j + 1;
                mapping.PersistentPropertyTag = j + 1;
            }
        }

        EditorUtility.SetDirty(storageGO);
        PrefabUtility.SaveAsPrefabAsset(storageGO, storagePath);
        DestroyImmediate(storageGO);
    }
Exemple #4
0
        private static void GetMappings(string mappingStoragePath, string[] mappingTemplateStoragePath, List <PersistentClassMapping> mappingsList, out PersistentClassMappingsStorage storage)
        {
            List <GameObject> storageList = new List <GameObject>();
            GameObject        storageGO   = (GameObject)AssetDatabase.LoadAssetAtPath(mappingStoragePath, typeof(GameObject));

            if (storageGO != null)
            {
                storageList.Add(storageGO);
            }
            else
            {
                for (int i = 0; i < mappingTemplateStoragePath.Length; ++i)
                {
                    storageGO = (GameObject)AssetDatabase.LoadAssetAtPath(mappingTemplateStoragePath[i], typeof(GameObject));
                    if (storageGO != null)
                    {
                        storageList.Add(storageGO);
                    }
                }
            }

            if (storageList != null && storageList.Count > 0)
            {
                for (int i = 0; i < storageList.Count; ++i)
                {
                    PersistentClassMapping[] mappings = storageList[i].GetComponentsInChildren <PersistentClassMapping>(true);
                    mappingsList.AddRange(mappings);
                }

                storage = storageList[0].GetComponent <PersistentClassMappingsStorage>();
            }
            else
            {
                storage = null;
            }
        }
Exemple #5
0
        public static PersistentClassMapping[] GetMappings(string mappingStoragePath, string[] mappingTemplateStoragePath, out PersistentClassMappingsStorage storage)
        {
            List <PersistentClassMapping> mappingsList = new List <PersistentClassMapping>();

            GetMappings(mappingStoragePath, mappingTemplateStoragePath, mappingsList, out storage);
            return(mappingsList.ToArray());
        }
Exemple #6
0
 public static PersistentClassMapping[] GetSurrogateMappings(out PersistentClassMappingsStorage storage)
 {
     return(GetMappings(RTSLPath.SurrogatesMappingsStoragePath, RTSLPath.SurrogatesMappingsTemplatePath.ToArray(), out storage));
 }