Ejemplo n.º 1
0
 public void AddDep(CaheFile item)
 {
     if (!depList.Contains(item))
     {
         depList.Add(item);
     }
 }
Ejemplo n.º 2
0
 public void AddRef(CaheFile item)
 {
     if (!refList.Contains(item))
     {
         refList.Add(item);
     }
 }
Ejemplo n.º 3
0
    void GenerateFiles(string[] files, CacheFileRefType refType)
    {
        for (int i = 0; i < files.Length; i++)
        {
            CaheFile file = new CaheFile();
            file.filename = files[i];
            file.guid     = AssetDatabase.AssetPathToGUID(file.filename);
            file.type     = GetType(Path.GetExtension(file.filename));

            if (CacheFileAssetType.IsScriptOrConfig(file.type) && refType == CacheFileRefType.NoUse)
            {
            }
            else
            {
                file.refType = refType;
            }

            if (dict.ContainsKey(file.guid))
            {
                Debug.Log(refType + "  " + file.filename);
                continue;
            }
            dict.Add(file.guid, file);
        }
    }
Ejemplo n.º 4
0
    void GenerateDependencies(CaheFile file, CacheFileRefType refType)
    {
        string[] dependencies = AssetDatabase.GetDependencies(file.filename, false);
        for (int i = 0; i < dependencies.Length; i++)
        {
            string   guid = AssetDatabase.AssetPathToGUID(dependencies[i]);
            bool     has  = dict.ContainsKey(guid);
            CaheFile def;
            if (has)
            {
                def = dict[guid];
            }
            else
            {
                def          = new CaheFile();
                def.filename = dependencies[i];
                def.guid     = guid;
                def.type     = GetType(Path.GetExtension(def.filename));
                if (def.refType == CacheFileRefType.None)
                {
                    if (CacheFileAssetType.IsScriptOrConfig(def.type) && refType == CacheFileRefType.NoUse)
                    {
                    }
                    else
                    {
                        def.refType = refType;
                    }
                }
                dict.Add(def.guid, def);
            }


            file.AddDep(def);
            def.AddRef(file);

            if (!has)
            {
                GenerateDependencies(def, refType);
            }
        }
    }
Ejemplo n.º 5
0
    public void Generate()
    {
        string mresourceRoot = "Assets/Game/MResources";

        string[] files;

        // MResources Unity
        if (Directory.Exists(mresourceRoot))
        {
            files = Directory.GetFiles(mresourceRoot, "*.*", SearchOption.AllDirectories)
                    .Where(s => unityExts.Contains(Path.GetExtension(s).ToLower())).ToArray();

            GenerateFiles(files, CacheFileRefType.MResource);
        }

        // Resource Unity
        string[] resourcesDirs = Directory.GetDirectories("Assets", "Resources", SearchOption.AllDirectories);
        for (int i = 0; i < resourcesDirs.Length; i++)
        {
            files = Directory.GetFiles(resourcesDirs[i], "*.*", SearchOption.AllDirectories)
                    .Where(s => unityExts.Contains(Path.GetExtension(s).ToLower())).ToArray();
            GenerateFiles(files, CacheFileRefType.Resource);
        }

        // Editor
        string[] editorDirs = Directory.GetDirectories("Assets", "Editor", SearchOption.AllDirectories);
        for (int i = 0; i < editorDirs.Length; i++)
        {
            files = Directory.GetFiles(editorDirs[i], "*.*", SearchOption.AllDirectories)
                    .Where(s => Path.GetExtension(s).ToLower() != ".meta").ToArray();


            GenerateFiles(files, CacheFileRefType.Editor);
        }


        // Ref
        list = new List <CaheFile>(dict.Values);

        for (int i = 0; i < list.Count; i++)
        {
            GenerateDependencies(list[i], CacheFileRefType.Ref);
        }

        // NoUse Unity
        files = Directory.GetFiles("Assets", "*.*", SearchOption.AllDirectories)
                .Where(s => unityExts.Contains(Path.GetExtension(s).ToLower())).ToArray();

        for (int i = 0; i < files.Length; i++)
        {
            string guid = AssetDatabase.AssetPathToGUID(files[i]);
            if (dict.ContainsKey(guid))
            {
                continue;
            }

            CaheFile file = new CaheFile();
            file.filename = files[i];
            file.guid     = guid;
            file.type     = GetType(Path.GetExtension(file.filename));
            if (!CacheFileAssetType.IsScriptOrConfig(file.type))
            {
                file.refType = CacheFileRefType.NoUse;
            }
            dict.Add(file.guid, file);

            GenerateDependencies(file, CacheFileRefType.NoUse);
        }

        // Other
        files = Directory.GetFiles("Assets", "*.*", SearchOption.AllDirectories)
                .Where(s => !ignoreExts.Contains(Path.GetExtension(s).ToLower()) && s.IndexOf("Assets/StreamingAssets") == -1).ToArray();

        for (int i = 0; i < files.Length; i++)
        {
            string guid = AssetDatabase.AssetPathToGUID(files[i]);
            if (dict.ContainsKey(guid))
            {
                continue;
            }

            CaheFile file = new CaheFile();
            file.filename = files[i];
            file.guid     = guid;
            file.type     = GetType(Path.GetExtension(file.filename));
            if (file.filename.StartsWith(mresourceRoot))
            {
                file.refType = CacheFileRefType.MResource;
            }
            else if (file.filename.IndexOf("/Resources/") != -1)
            {
                file.refType = CacheFileRefType.Resource;
            }
            else
            {
                if (!CacheFileAssetType.IsScriptOrConfig(file.type))
                {
                    file.refType = CacheFileRefType.NoUse;
                }
            }
            dict.Add(file.guid, file);
        }



        list = new List <CaheFile>(dict.Values);
        for (int i = 0; i < list.Count; i++)
        {
            list[i].ToGUIDList();
        }

        string json = JsonUtility.ToJson(this, true);

        if (!Directory.Exists(outRoot))
        {
            Directory.CreateDirectory(outRoot);
        }

        File.WriteAllText(outFile_data, json);
        File.WriteAllText(outFile_data_js, "var guidData = " + json);

        string url = "file:///" + Path.GetFullPath(outFile_index);

        Debug.Log(url);
        Application.OpenURL(url);
    }