Пример #1
0
            private static bool HandlePrefabOnSelection(UnityEngine.Object obj)
            {
                string assetPath = AssetDatabase.GetAssetPath(obj);

                if (Utility.IsPrefab(assetPath))
                {
                    var guid          = AssetDatabase.AssetPathToGUID(assetPath);
                    var prefabInCache = APCache.GetValue(guid) as APPrefab;

                    if (prefabInCache == null)
                    {
                        return(false);
                    }

                    var currentPrefab = APResources.GetAPPrefabFromAssetGuid(guid);

                    if (prefabInCache.InLayers != currentPrefab.InLayers ||
                        prefabInCache.InAssetBundle != currentPrefab.InAssetBundle ||
                        prefabInCache.ContainTags != currentPrefab.ContainTags)
                    {
                        webCommunicationService.UpdateObjectsIntoCache(APAssetType.Prefab, currentPrefab, SyncManager.ModifiedAssets);
                        return(true);
                    }
                }

                return(false);
            }
        private void CopyAssetPropertyToClipboard(string msg, Func <APAsset, string> selector)
        {
            if (string.IsNullOrEmpty(msg))
            {
                return;
            }

            var decompressedMessage = Encoding.UTF8.GetString(CLZF2.Decompress(Convert.FromBase64String(msg)));
            var assets = decompressedMessage.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
            var names  = new List <string>();

            foreach (var assetId in assets)
            {
                var asset = APCache.GetValue(assetId);
                if (asset != null)
                {
                    names.Add(selector(asset));
                }
            }

            TextEditor textEditor = new TextEditor();

            textEditor.ReplaceSelection(string.Join("\n", names.ToArray()));
            textEditor.OnFocus();
            textEditor.Copy();
        }
Пример #3
0
            private static bool HandleNewAnimationClipOnSelection(UnityEngine.Object obj)
            {
                string assetPath = AssetDatabase.GetAssetPath(obj);

                if (Utility.IsUntyNewAnimation(assetPath))
                {
                    var guid             = AssetDatabase.AssetPathToGUID(assetPath);
                    var animationInCache = APCache.GetValue(guid) as APAnimation;

                    if (animationInCache == null)
                    {
                        return(false);
                    }

                    var currentAnimation = APResources.GetAPAnimationFromClip(obj as AnimationClip);
                    currentAnimation.Id = guid;

                    if (animationInCache.CycleOffset - currentAnimation.CycleOffset > 0.001f ||
                        animationInCache.LoopPose != currentAnimation.LoopPose ||
                        animationInCache.LoopTime != currentAnimation.LoopTime ||
                        animationInCache.FPS != currentAnimation.FPS ||
                        animationInCache.InAssetBundle != currentAnimation.InAssetBundle ||
                        animationInCache.Length - currentAnimation.Length > 0.001f)
                    {
                        webCommunicationService.UpdateObjectsIntoCache(APAssetType.AnimationClip, currentAnimation, SyncManager.ModifiedAssets);
                        return(true);
                    }
                }

                return(false);
            }
Пример #4
0
        private static void HandleDeletedAssets(string[] deletedAssets)
        {
            var animationClips = APCache.GetAssetsListByTypeFromCache <APAnimation>(APAssetType.AnimationClip);

            foreach (var assetPath in deletedAssets)
            {
                Utility.DebugLog(string.Format("Deleted: {0}", assetPath));

                if (Utility.IsModelPath(assetPath))
                {
                    foreach (var clip in animationClips)
                    {
                        if (clip.Path.Contains(assetPath))
                        {
                            APCache.Remove(APAssetType.AnimationClip, clip.Id);
                            SyncManager.DeleteAssets.Enqueue(clip);
                            SyncManager.DeleteAssets.Enqueue(APResources.GetBlackListAPAsset(assetPath));
                        }
                    }
                }

                var id    = AssetDatabase.AssetPathToGUID(assetPath);
                var asset = APCache.GetValue(AssetDatabase.AssetPathToGUID(assetPath));
                if (asset != null)
                {
                    APCache.Remove(id);
                    APCache.RemoveFromBlacklist(assetPath);
                    SyncManager.DeleteAssets.Enqueue(asset);
                    SyncManager.DeleteAssets.Enqueue(APResources.GetBlackListAPAsset(assetPath));
                }
            }
        }
Пример #5
0
            private static bool HandleMaterialOnSelection(UnityEngine.Object obj)
            {
                string assetPath       = AssetDatabase.GetAssetPath(obj);
                var    currentMaterial = (obj as Material);
                var    guid            = AssetDatabase.AssetPathToGUID(assetPath);
                var    materialInCache = APCache.GetValue(APAssetType.Material, guid) as APMaterial;

                if (materialInCache != null && !currentMaterial.shader.name.Equals(materialInCache.Shader, StringComparison.CurrentCultureIgnoreCase))
                {
                    webCommunicationService.UpdateObjectsIntoCache(APAssetType.Material, guid, SyncManager.ModifiedAssets);
                    return(true);
                }

                return(false);
            }
        public void UpdateObjectsIntoCache(APAssetType type, string assetid, Queue <APAsset> modifedAssets = null)
        {
            APAsset asset = APResources.GetAPAssetByPath(type, assetid);

            if (APCache.HasAsset(type, assetid))
            {
                var previousAssets = APCache.GetValue(type, assetid);
                if (asset != null && previousAssets != null)
                {
                    asset.Used = previousAssets.Used;
                    APCache.SetValue(type, assetid, asset);
                    if (modifedAssets != null)
                    {
                        modifedAssets.Enqueue(asset);
                    }
                }
            }
        }
Пример #7
0
        private static void UpdateModelInCache(string modelAssetPath)
        {
            var guid = AssetDatabase.AssetPathToGUID(modelAssetPath);

            webCommunicationService.UpdateObjectsIntoCache(APAssetType.Model, guid, SyncManager.ModifiedAssets);

            var animationsInCache = APCache.GetAssetsListByTypeFromCache <APAnimation>(APAssetType.AnimationClip);
            HashSet <string> animationsAssetIdInCache = new HashSet <string>();

            foreach (var animation in animationsInCache)
            {
                if (animation.Id.ToLower().Contains(guid.ToLower()))
                {
                    animationsAssetIdInCache.Add(animation.Id);
                }
            }

            var clipIds = APResources.GetAnimationClipAssetIdInModel(modelAssetPath);

            foreach (var id in clipIds)
            {
                if (animationsAssetIdInCache.Contains(id))
                {
                    webCommunicationService.UpdateObjectsIntoCache(APAssetType.AnimationClip, id, SyncManager.ModifiedAssets);
                }
                else
                {
                    var clip = APResources.GetAPAssetByPath(APAssetType.AnimationClip, id);
                    APCache.SetValue(APAssetType.AnimationClip, id, clip);
                    SyncManager.AddedAssets.Enqueue(clip);
                }
            }

            foreach (var id in animationsAssetIdInCache)
            {
                if (!clipIds.Contains(id))
                {
                    var clip = APCache.GetValue(APAssetType.AnimationClip, id);
                    APCache.Remove(id);
                    SyncManager.DeleteAssets.Enqueue(clip);
                }
            }
        }
Пример #8
0
            private static bool HandleRenderTextureOnSelection(UnityEngine.Object obj)
            {
                string assetPath = AssetDatabase.GetAssetPath(obj);
                string guid      = AssetDatabase.AssetPathToGUID(assetPath);
                var    rtInCache = APCache.GetValue(guid) as APTexture;

                if (rtInCache == null)
                {
                    return(false);
                }

                var rtCurrent = APResources.GetAPTextureFromAssetGuid(guid);

                if (rtInCache.Width != rtCurrent.Width ||
                    rtInCache.Height != rtCurrent.Height ||
                    rtInCache.MipMap != rtCurrent.MipMap)
                {
                    webCommunicationService.UpdateObjectsIntoCache(APAssetType.Texture, AssetDatabase.AssetPathToGUID(assetPath), SyncManager.ModifiedAssets);
                    return(true);
                }

                return(false);
            }
Пример #9
0
        private static void HandleMovedAssets(string[] movedAssets, string[] movedFromAssetPaths)
        {
            for (var i = 0; i < movedAssets.Length; i++)
            {
                Utility.DebugLog(string.Format("moved {0} to {1}", movedFromAssetPaths[i], movedAssets[i]));
                var sid = AssetDatabase.AssetPathToGUID(movedAssets[i]);
                if (Utility.IsModelPath(movedAssets[i]))
                {
                    var clipIds = APResources.GetAnimationClipAssetIdInModel(movedAssets[i]);
                    foreach (var id in clipIds)
                    {
                        APCache.MoveTo(sid, movedAssets[i]);
                        var clip = APCache.GetValue(APAssetType.AnimationClip, id);
                        SyncManager.MovedFromAssets.Enqueue(id);
                        SyncManager.MovedToAssets.Enqueue(clip);
                    }
                }

                APCache.MoveTo(sid, movedAssets[i]);
                var asset = APCache.GetValue(sid);
                SyncManager.MovedFromAssets.Enqueue(sid);
                SyncManager.MovedToAssets.Enqueue(asset);
            }
        }