Esempio n. 1
0
        public static APCodeFile GetCodeFile(string path)
        {
            string guid = AssetDatabase.AssetPathToGUID(path);

            APCodeFile codeFile = new APCodeFile();

            codeFile.Path     = path;
            codeFile.Hash     = Utility.GetFileMd5(path);
            codeFile.Name     = Utility.GetFileName(path);
            codeFile.FileSize = Utility.GetFileSize(path);
            codeFile.FileType = Utility.GetFileExtension(path);
            codeFile.Icon     = GetIconID(path);
            codeFile.Id       = guid;

            if (codeFile.FileType.Equals(".cs", StringComparison.OrdinalIgnoreCase))
            {
                var tags = GetTagsInCode(File.ReadAllText(codeFile.Path)).ToArray();
                codeFile.ContainTags = string.Join(",", tags);

                if (!string.IsNullOrEmpty(codeFile.ContainTags))
                {
                    Utility.DebugLog("Tags In CodeFile: " + codeFile.ContainTags);
                }
            }

            return(codeFile);
        }
Esempio n. 2
0
        private static void AddNewImportAssets(string assetPath)
        {
            Utility.DebugLog(string.Format("New: {0}", assetPath));

            if (!File.Exists(assetPath) && Directory.Exists(assetPath))
            {
                return;
            }

            if (Utility.IsStreamingAssetsFile(assetPath))
            {
                APStreamingAssetsFile file = APResources.GetStreamingAssetFile(assetPath);
                APCache.Add(APAssetType.StreamingAssets, file.Id, file);
                SyncManager.AddedAssets.Enqueue(file);
                return;
            }
            else if (Utility.IsCodeFile(assetPath))
            {
                APCodeFile codeFile = APResources.GetCodeFile(assetPath);
                APCache.Add(APAssetType.Script, codeFile.Id, codeFile);
                SyncManager.AddedAssets.Enqueue(codeFile);
                return;
            }

            var guid = AssetDatabase.AssetPathToGUID(assetPath);

            UnityEngine.Object obj = AssetDatabase.LoadAssetAtPath(assetPath, typeof(UnityEngine.Object));

            APAsset asset = null;

            // if new path
            //
            if (obj is Texture)
            {
                if (obj is MovieTextureType)
                {
                    var movie = APResources.GetAPAssetByPath(APAssetType.MovieTexture, guid);
                    if (movie != null)
                    {
                        APCache.SetValue(APAssetType.MovieTexture, movie.Id, movie);
                    }
                    SyncManager.AddedAssets.Enqueue(movie);
                    return;
                }

                asset = APResources.GetAPAssetByPath(APAssetType.Texture, guid);
                if (asset != null)
                {
                    APCache.SetValue(APAssetType.Texture, asset.Id, asset);
                }
            }
            else if (Utility.IsModels(obj, assetPath))
            {
                AddModelInCache(assetPath);
                return;
            }
            else if (obj is AnimationClip)
            {
                asset = APResources.GetAPAssetByPath(APAssetType.AnimationClip, guid);
                if (asset != null)
                {
                    APCache.SetValue(APAssetType.AnimationClip, asset.Id, asset);
                }
            }
            else if (obj is AudioClip)
            {
                asset = APResources.GetAPAssetByPath(APAssetType.AudioClip, guid);
                if (asset != null)
                {
                    APCache.SetValue(APAssetType.AudioClip, asset.Id, asset);
                }
            }
            else if (obj is Font)
            {
                asset = APResources.GetAPAssetByPath(APAssetType.Font, guid);
                if (asset != null)
                {
                    APCache.SetValue(APAssetType.Font, asset.Id, asset);
                }
            }
            else if (obj is Shader)
            {
                asset = APResources.GetAPAssetByPath(APAssetType.Shader, guid);
                if (asset != null)
                {
                    APCache.SetValue(APAssetType.Shader, asset.Id, asset);
                }
            }
            else if (obj is Material || obj is PhysicMaterial || obj is PhysicsMaterial2D)
            {
                asset = APResources.GetAPAssetByPath(APAssetType.Material, guid);
                if (asset != null)
                {
                    APCache.SetValue(APAssetType.Material, asset.Id, asset);
                }
            }
            else if (Utility.IsPrefab(assetPath))
            {
                asset = APResources.GetAPAssetByPath(APAssetType.Prefab, guid);
                if (asset != null)
                {
                    APCache.SetValue(APAssetType.Prefab, asset.Id, asset);
                }
            }
            else
            {
                if (assetPath.ToLower().StartsWith("assets"))
                {
                    asset = APResources.GetOtherFile(assetPath);
                    if (asset != null)
                    {
                        APCache.Add(APAssetType.Others, asset.Id, asset);
                    }
                }
            }

            if (asset != null)
            {
                SyncManager.AddedAssets.Enqueue(asset);
            }

            Utility.DebugLog("New object type = " + obj);
        }