Exemple #1
0
    public void UpdateResources()
    {
        //Resources.Load(
//		foreach(var n in Resources.FindObjectsOfTypeAll(typeof(ILoadableResource))/*GameObject.FindObjectsOfType(typeof(ILoadableResource))*/)
//		{
//			(n as ILoadableResource).iSetResourcePath(PrefabManager.GetPrefabPath((n as ILoadableResource).iGetObject()));
//PrefabManager.GetPrefabPath(res)
//		}
        foreach (var n in GameObject.FindObjectsOfType <GameObject>())
        {
            foreach (var c in n.GetComponents <ILoadableResource>())
            {
                c.iSetResourcePath(PrefabManager.GetPrefabPath(c.iGetObject()));
                EditorUtility.SetDirty(n);
                EditorUtility.SetDirty(c as Component);
            }
        }

        var levelDirectoryPath = new DirectoryInfo(Application.dataPath);
        var fileInfo           = levelDirectoryPath.GetFiles("*.*", SearchOption.AllDirectories);

        foreach (FileInfo file in fileInfo)
        {
            if ((file.Extension == ".prefab" || file.Extension == ".asset") && file.FullName.Contains("Resources\\"))
            {
                var indexStart = file.FullName.IndexOf("Resources\\") + 10;
                var path       = file.FullName.Substring(indexStart, file.FullName.Length - indexStart - file.Extension.Length).Replace('\\', '/');

                var res = Resources.Load(path);
                var ilr = res as ILoadableResource;
                if (ilr != null)
                {
                    ilr.iSetResourcePath(path);
                    EditorUtility.SetDirty(res);
                    Debug.Log(path);
                }
            }
        }

        Resources.UnloadUnusedAssets();
    }