Beispiel #1
0
    static AssetFile GetAssetFile(Object target)
    {
        string assetPath = AssetDatabase.GetAssetPath(target).ToLower();

        if (IsValid(assetPath) == false)
        {
            return(null);
        }
        string name = Path.GetFileName(assetPath);
        //Editor模式下是InstanceID
        string    md5   = target.GetInstanceID().ToString();
        AssetFile asset = list.Get(name);

        if (asset == null)
        {
            asset = list.Get(md5);
        }
        if (asset != null)
        {
            asset.asset = assetPath;
        }

        if (asset == null)
        {
            asset       = new AssetFile();
            asset.name  = name;
            asset.asset = assetPath;
            asset.md5   = md5;
            asset.size  = 0;
        }


        return(asset);
    }
Beispiel #2
0
    static void UpdateAssetList(AssetList list, string dir)
    {
        DirectoryInfo dirInfo = new DirectoryInfo(dir);

        if (dirInfo.Exists == false)
        {
            return;
        }

        string[] files = Directory.GetFiles(dir, "*.*", SearchOption.AllDirectories);

        for (int i = 0; i < files.Length; ++i)
        {
            string file = files[i].Replace("\\", "/").ToLower();
            if (file.EndsWith(".meta", System.StringComparison.Ordinal) ||
                file.EndsWith(".manifest", System.StringComparison.Ordinal))
            {
                continue;
            }

            string name      = Path.GetFileName(file);
            string assetPath = name;

            if (file.Contains("assets/"))
            {
                assetPath = file.Substring(file.IndexOf("assets/", System.StringComparison.Ordinal));
            }
            Object target = AssetDatabase.LoadAssetAtPath <Object>(assetPath);
            string md5    = target.GetInstanceID().ToString();

            AssetFile asset = list.Get(name);
            if (asset == null)
            {
                asset = list.Get(assetPath);
            }
            if (asset == null)
            {
                asset = list.Get(md5);
            }
            if (asset == null)
            {
                asset       = new AssetFile();
                asset.name  = name;
                asset.asset = assetPath;
            }

            asset.size = 0;

            asset.md5 = md5;

            list.Add(asset);
        }
    }
Beispiel #3
0
    public static AssetFile Get(string key)
    {
        AssetFile file = list.Get(key);

        return(file);
    }