Exemple #1
0
        //----- property -----

        //----- method -----

        private void ApplyDummyAsset()
        {
            if (Application.isPlaying)
            {
                return;
            }

            DeleteCreatedAsset();

            if (RawImage.texture != null && RawImage.texture.name != DummyAssetName)
            {
                return;
            }

            if (string.IsNullOrEmpty(assetGuid))
            {
                return;
            }

            var assetPath = AssetDatabase.GUIDToAssetPath(assetGuid);

            if (string.IsNullOrEmpty(assetPath))
            {
                return;
            }

            if (textureAssetCache == null)
            {
                textureAssetCache = new FixedQueue <AssetCacheInfo>(100);
            }

            Texture textureAsset = null;

            var cacheAssetInfo = textureAssetCache.FirstOrDefault(x => x.assetGuid == assetGuid);

            if (cacheAssetInfo == null)
            {
                textureAsset = AssetDatabase.LoadMainAssetAtPath(assetPath) as Texture;

                if (textureAsset != null)
                {
                    cacheAssetInfo = new AssetCacheInfo()
                    {
                        assetGuid    = assetGuid,
                        textureAsset = textureAsset,
                    };

                    textureAssetCache.Enqueue(cacheAssetInfo);
                }
            }
            else
            {
                textureAsset = cacheAssetInfo.textureAsset;

                textureAssetCache.Remove(cacheAssetInfo);

                textureAssetCache.Enqueue(cacheAssetInfo);
            }

            if (textureAsset == null)
            {
                return;
            }

            DeleteCreatedAsset();

            var texture = new Texture2D(textureAsset.width, textureAsset.height, TextureFormat.ARGB32, false);

            texture.name = DummyAssetName;

            texture.hideFlags = HideFlags.DontSaveInEditor;

            Graphics.ConvertTexture(textureAsset, texture);

            // Bug: UnityのバグでこのタイミングでアクティブなRenderTextureを空にしないと下記警告が出る.
            // 「Releasing render texture that is set to be RenderTexture.active!」.
            RenderTexture.active = null;

            RawImage.texture = texture;
        }
Exemple #2
0
        //----- property -----

        //----- method -----

        private void ApplyDummyAsset()
        {
            if (Application.isPlaying)
            {
                return;
            }

            if (Image.sprite != null && Image.sprite.name != DummyAssetName)
            {
                return;
            }

            if (string.IsNullOrEmpty(assetGuid))
            {
                return;
            }

            if (string.IsNullOrEmpty(spriteId))
            {
                return;
            }

            var assetPath = AssetDatabase.GUIDToAssetPath(assetGuid);

            if (string.IsNullOrEmpty(assetPath))
            {
                return;
            }

            if (spriteAssetCache == null)
            {
                spriteAssetCache = new FixedQueue <AssetCacheInfo>(250);
            }

            Sprite spriteAsset = null;

            var cacheAssetInfo = spriteAssetCache.FirstOrDefault(x => x.assetGuid == assetGuid && x.spriteId == spriteId);

            if (cacheAssetInfo == null)
            {
                spriteAsset = AssetDatabase.LoadAllAssetsAtPath(assetPath)
                              .OfType <Sprite>()
                              .FirstOrDefault(x => x.GetSpriteID().ToString() == spriteId);

                if (spriteAsset != null)
                {
                    cacheAssetInfo = new AssetCacheInfo()
                    {
                        assetGuid   = assetGuid,
                        spriteId    = spriteId,
                        spriteAsset = spriteAsset,
                    };

                    spriteAssetCache.Enqueue(cacheAssetInfo);
                }
            }
            else
            {
                spriteAsset = cacheAssetInfo.spriteAsset;

                spriteAssetCache.Remove(cacheAssetInfo);

                spriteAssetCache.Enqueue(cacheAssetInfo);
            }

            if (spriteAsset == null)
            {
                return;
            }

            DeleteCreatedAsset();

            var texture       = spriteAsset.texture;
            var rect          = spriteAsset.rect;
            var pivot         = spriteAsset.pivot;
            var pixelsPerUnit = spriteAsset.pixelsPerUnit;
            var border        = spriteAsset.border;

            var sprite = Sprite.Create(texture, rect, pivot, pixelsPerUnit, 0, SpriteMeshType.FullRect, border);

            sprite.name = DummyAssetName;

            sprite.hideFlags = HideFlags.DontSaveInEditor;

            Image.sprite = sprite;
        }
Exemple #3
0
    /// <summary>
    /// 分析引用关系
    /// </summary>
    public void Analyze()
    {
        if (_isAnalyzed)
        {
            return;
        }
        _isAnalyzed = true;

        _cacheInfo     = FastAssetBundleUtils.GetCacheInfo(assetPath);
        _isFileChanged = _cacheInfo == null || !_cacheInfo.fileHash.Equals(GetHash());
        if (_cacheInfo != null)
        {
            _bundleCrc = _cacheInfo.bundleCrc;
            if (_isFileChanged)
            {
                Debug.Log("File was changed : " + assetPath);
            }
        }

        Object[]      deps    = EditorUtility.CollectDependencies(new Object[] { asset });
        List <Object> depList = new List <Object>();

        for (int i = 0; i < deps.Length; i++)
        {
            Object o = deps[i];
            //不包含脚本对象
            //不包含LightingDataAsset对象
            if (o is MonoScript || o is LightingDataAsset)
            {
                continue;
            }

            //不包含builtin对象
            string path = AssetDatabase.GetAssetPath(o);
            if (path.StartsWith("Resources"))
            {
                continue;
            }

            depList.Add(o);
        }
        deps = depList.ToArray();


        var res = from s in deps
                  let obj = AssetDatabase.GetAssetPath(s)
                            select obj;
        var paths = res.Distinct().ToArray();

        for (int i = 0; i < paths.Length; i++)
        {
            if (File.Exists(paths[i]) == false)
            {
                //Debug.Log("invalid:" + paths[i]);
                continue;
            }
            FileInfo        fi     = new FileInfo(paths[i]);
            FastAssetTarget target = FastAssetBundleUtils.Load(fi);
            if (target == null)
            {
                continue;
            }

            this.AddDependParent(target);

            target.Analyze();
        }
    }