Пример #1
0
        public override void VerifyAssetError(SoAssetPostprocessor so)
        {
            ErrorLogic.SetValue(false);
            var inSpriteAtlas        = false;
            var folder               = System.IO.Path.GetDirectoryName(Path);
            var spriteAtlasAssetPath = StringUtil.Contact(folder.Replace("Sprite", "Atlas"), ".spriteatlas");

            if (File.Exists(spriteAtlasAssetPath))
            {
                string allText;
                if (spriteAtlasFile.ContainsKey(spriteAtlasAssetPath))
                {
                    allText = spriteAtlasFile[spriteAtlasAssetPath];
                }
                else
                {
                    allText = File.ReadAllText(spriteAtlasAssetPath);
                    spriteAtlasFile[spriteAtlasAssetPath] = allText;
                }

                if (allText.Contains(AssetDatabase.AssetPathToGUID(Path)))
                {
                    inSpriteAtlas = true;
                }
            }

            if (!inSpriteAtlas)
            {
                base.VerifyAssetError(so);
            }
        }
Пример #2
0
        public override void FixAndReimport(SoAssetPostprocessor so)
        {
            var texturePostprocessorBase = so as SoTexturePostprocessorBase;

            TextureAssetPostprocessor.SetPlatformSettings(GetAssetImporter <TextureImporter>(), texturePostprocessorBase);
            EditorUtility.SetDirty(GetAssetImporter <TextureImporter>());
        }
        public static void OnPostprocessSpriteAtlas(string assetPath)
        {
            var spriteAtlas = AssetDatabase.LoadAssetAtPath <SpriteAtlas>(assetPath);

            if (!CustomAssetPostprocessor.IsNewCreateFile(assetPath))
            {
                return;
            }

            var postprocessorUtils = SoAssetPostprocessorUtils.GetSoAssetPostprocessorUtils();
            var guid = postprocessorUtils.Get(PostprocessorAssetType.SpriteAtlas, assetPath);

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

            var path = AssetDatabase.GUIDToAssetPath(guid);
            var so   = AssetDatabase.LoadAssetAtPath <SoSpriteAtlasPostprocessor>(path);

            if (so == null)
            {
                so = SoAssetPostprocessor.GetDefault(PostprocessorAssetType.SpriteAtlas) as SoSpriteAtlasPostprocessor;
            }

            SetIncludeInBuild(spriteAtlas);
            SetPackingSettings(spriteAtlas);
            SetTextureSettings(spriteAtlas);
            SetPlatformSettings(spriteAtlas, so);
            EditorUtility.SetDirty(spriteAtlas);
            AssetDatabase.SaveAssets();
        }
Пример #4
0
        public override void FixAndReimport(SoAssetPostprocessor so)
        {
            var modelPostprocessor = so as SoModelPostprocessor;

            ModelAssetPostprocessor.SetSettings(GetAssetImporter <ModelImporter>(), modelPostprocessor);
            EditorUtility.SetDirty(GetAssetImporter <ModelImporter>());
        }
Пример #5
0
        public override void FixAndReimport(SoAssetPostprocessor so)
        {
            var texturePostprocessorBase = so as SoTexturePostprocessorBase;

            SpriteAtlasAssetPostprocessor.SetPlatformSettings(GetSpriteAltas(), texturePostprocessorBase as SoSpriteAtlasPostprocessor);
            EditorUtility.SetDirty(GetSpriteAltas());
        }
Пример #6
0
        public override void VerifyAssetError(SoAssetPostprocessor so)
        {
            ErrorLogic.SetValue(false);
            var textureImporter = GetAssetImporter <TextureImporter>();

            if (textureImporter.npotScale == TextureImporterNPOTScale.None)
            {
                base.VerifyAssetError(so);
            }
        }
Пример #7
0
        private void OnCreate(object o)
        {
            var so       = SoAssetPostprocessor.Create(this.assetType);
            var path     = AssetDatabase.GetAssetPath(so);
            var hashCode = path.GetHashCode();

            paths.Add(path);
            Reload();
            BeginRename(FindItem(hashCode, rootItem), 0.25f);
        }
Пример #8
0
        public static void VerifyConfigs()
        {
            var so      = GetSoAssetPostprocessorFolder();
            var folders = so.folders;
            var dirty   = false;
            Dictionary <PostprocessorAssetType, string> defaultSoAssetPostprocessors = null;
            List <AssetPostprocessorFolder>             lostFolders = null;

            if (folders != null)
            {
                foreach (var folder in folders)
                {
                    if (!Directory.Exists(folder.path))
                    {
                        lostFolders = lostFolders ?? new List <AssetPostprocessorFolder>();
                        lostFolders.Add(folder);
                        dirty = true;
                        continue;
                    }

                    var soPath = AssetDatabase.GUIDToAssetPath(folder.guid);
                    var soAssetPostprocessor = AssetDatabase.LoadAssetAtPath <SoAssetPostprocessor>(soPath);
                    if (soAssetPostprocessor == null)
                    {
                        defaultSoAssetPostprocessors = defaultSoAssetPostprocessors ?? new Dictionary <PostprocessorAssetType, string>();
                        if (!defaultSoAssetPostprocessors.ContainsKey(folder.assetType))
                        {
                            var defaultSo = SoAssetPostprocessor.GetDefault(folder.assetType);
                            var assetPath = AssetDatabase.GetAssetPath(defaultSo);
                            defaultSoAssetPostprocessors.Add(folder.assetType, AssetDatabase.AssetPathToGUID(assetPath));
                        }

                        folder.guid = defaultSoAssetPostprocessors[folder.assetType];
                        dirty       = true;
                    }
                }
            }

            if (lostFolders != null)
            {
                foreach (var folder in lostFolders)
                {
                    so.folders.Remove(folder);
                }

                lostFolders.Clear();
            }

            if (dirty)
            {
                EditorUtility.SetDirty(so);
                AssetDatabase.SaveAssets();
            }
        }
Пример #9
0
        public void SoPostprocessorChanged(string guid)
        {
            var assetPath = AssetDatabase.GUIDToAssetPath(guid);

            soAssetPostprocessor = AssetDatabase.LoadAssetAtPath <SoAssetPostprocessor>(assetPath);
            postprocessorGuid    = guid;
            for (int i = 0; i < rootItem.children.Count; i++)
            {
                var item = rootItem.children[i] as AssetListItem;
                item.SetDirty();
            }
        }
Пример #10
0
        public override void VerifyAssetState(SoAssetPostprocessor so)
        {
            WarnLogic.SetValue(false);

            var    modelPostprocessor = so as SoModelPostprocessor;
            string message;

            if (!ModelAssetPostprocessor.CompareSettings(GetAssetImporter <ModelImporter>(), modelPostprocessor, out message))
            {
                WarnLogic.SetValue(true);
                WarnLogic.SetMessage(message.TrimStart('\n'));
            }
        }
Пример #11
0
        public override void VerifyAssetState(SoAssetPostprocessor so)
        {
            WarnLogic.SetValue(false);

            var    texturePostprocessorBase = so as SoSpriteAtlasPostprocessor;
            string message;

            if (!SpriteAtlasAssetPostprocessor.CompareSettings(GetSpriteAltas(), texturePostprocessorBase, out message))
            {
                WarnLogic.SetValue(true);
                WarnLogic.SetMessage(message.TrimStart('\n'));
            }
        }
Пример #12
0
 public void SetFolder(PostprocessorAssetType assetType, string path)
 {
     if (this.assetType != assetType || this.folder != path)
     {
         this.assetType = assetType;
         this.folder    = path;
         selectState    = AssetState.None;
         var guid      = postprocessorUtils.Get(this.assetType, this.folder);
         var assetPath = AssetDatabase.GUIDToAssetPath(guid);
         soAssetPostprocessor = AssetDatabase.LoadAssetAtPath <SoAssetPostprocessor>(assetPath);
         postprocessorGuid    = guid;
         Refresh(true);
     }
 }
Пример #13
0
        public override void VerifyAssetState(SoAssetPostprocessor so)
        {
            WarnLogic.SetValue(false);

            var    texturePostprocessorBase = so as SoTexturePostprocessorBase;
            var    importer = GetAssetImporter <TextureImporter>();
            string message;

            if (!TextureAssetPostprocessor.CompareSettings(GetAssetImporter <TextureImporter>(), texturePostprocessorBase, out message))
            {
                WarnLogic.SetValue(true);
            }

            WarnLogic.SetMessage(message.TrimStart('\n'));
        }
Пример #14
0
        private void OnDeleteSoAssetPostprocessor(string deleteGuid)
        {
            var so          = SoAssetPostprocessorUtils.GetSoAssetPostprocessorUtils();
            var defaultSo   = SoAssetPostprocessor.GetDefault(selectAssetType);
            var defaultGuid = AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(defaultSo));
            var paths       = so.GetPaths(selectAssetType);

            for (int i = 0; i < paths.Count; i++)
            {
                var path = paths[i];
                var guid = so.Get(selectAssetType, path);
                if (guid == deleteGuid)
                {
                    so.Set(selectAssetType, path, defaultGuid);
                }
            }
        }
Пример #15
0
        public override void VerifyAssetError(SoAssetPostprocessor so)
        {
            var(width, height) = GetTextureSize(GetAssetImporter <TextureImporter>());
            var message = string.Empty;

            if (width != height)
            {
                ErrorLogic.SetValue(true);
                message = "The width of the texture should be the same as the height";
            }

            if (!Helper.IsValuePowerOf2(width) || !Helper.IsValuePowerOf2(height))
            {
                ErrorLogic.SetValue(true);
                message = StringUtil.Contact(message, "\n", "The size of the texture should be a power of 2");
            }

            ErrorLogic.SetMessage(message.TrimStart('\n'));
        }
Пример #16
0
        public static void OnPreprocessTexture(TextureImporter importer)
        {
            var assetType = (PostprocessorAssetType)(-1);

            if (importer.assetPath.Contains("Sprite"))
            {
                assetType = PostprocessorAssetType.Sprite;
            }
            else if (importer.assetPath.Contains("Texture"))
            {
                assetType = PostprocessorAssetType.Texture;
            }

            if (assetType != PostprocessorAssetType.Sprite && assetType != PostprocessorAssetType.Texture)
            {
                return;
            }

            var postprocessorUtils = SoAssetPostprocessorUtils.GetSoAssetPostprocessorUtils();
            var guid = postprocessorUtils.Get(assetType, importer.assetPath);

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

            var path = AssetDatabase.GUIDToAssetPath(guid);
            SoTexturePostprocessorBase soPostprocessor = null;

            if (!string.IsNullOrEmpty(path))
            {
                soPostprocessor = AssetDatabase.LoadAssetAtPath <SoTexturePostprocessorBase>(path);
            }

            if (soPostprocessor == null)
            {
                soPostprocessor = SoAssetPostprocessor.GetDefault(assetType) as SoTexturePostprocessorBase;
            }

            importer.textureType = assetType == PostprocessorAssetType.Sprite ? TextureImporterType.Sprite : TextureImporterType.Default;
            SetDefaultSettings(assetType, importer);
            SetPlatformSettings(importer, soPostprocessor);
        }
Пример #17
0
        public static void OnPostprocessModel(ModelImporter importer)
        {
            postprocessorUtils = postprocessorUtils ? postprocessorUtils : SoAssetPostprocessorUtils.GetSoAssetPostprocessorUtils();
            var guid = postprocessorUtils.Get(PostprocessorAssetType.Model, importer.assetPath);

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

            var path = AssetDatabase.GUIDToAssetPath(guid);
            var so   = AssetDatabase.LoadAssetAtPath <SoModelPostprocessor>(path);

            if (so == null)
            {
                so = SoAssetPostprocessor.GetDefault(PostprocessorAssetType.Model) as SoModelPostprocessor;
            }

            SetSettings(importer, so);
            Reimport(importer, so);
        }
Пример #18
0
        protected override TreeViewItem BuildRoot()
        {
            var root        = new TreeViewItem(-1, -1);
            var defaultSo   = SoAssetPostprocessor.GetDefault(this.assetType);
            var defaultGuid = AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(defaultSo));

            root.children = new List <TreeViewItem>();
            foreach (var path in paths)
            {
                var item = new AssetPostprocessorConfigItem(path, 0, Path.GetFileNameWithoutExtension(path), defaultGuid);
                root.AddChild(item);
            }

            root.children.Sort((lhs, rhs) => {
                var lhsItem = lhs as AssetPostprocessorConfigItem;
                var rhsItem = rhs as AssetPostprocessorConfigItem;
                return(-lhsItem.IsDefault.CompareTo(rhsItem.IsDefault));
            });

            return(root);
        }
Пример #19
0
        private void AddFolder(string[] paths)
        {
            var defaultSo = SoAssetPostprocessor.GetDefault(this.assetType);

            ;
            var assetPath = AssetDatabase.GetAssetPath(defaultSo);
            var guid      = AssetDatabase.AssetPathToGUID(assetPath);

            for (var i = 0; i < paths.Length; i++)
            {
                var path = paths[i];
                if (this.paths.Contains(path))
                {
                    continue;
                }

                this.paths.Add(path);
                soAssetPostprocessorUtils.Set(this.assetType, path, guid, false);
                dirty = true;
            }
            AssetDatabase.SaveAssets();
        }
Пример #20
0
        private void OnDeleteConfig(object @object)
        {
            var selectIds = @object as IList <int>;

            if (selectIds != null && selectIds.Count == 1)
            {
                var item = FindItem(selectIds[0], rootItem) as AssetPostprocessorConfigItem;
                if (postprocessorConfigGuid == item.Guid)
                {
                    var defaultConfig = SoAssetPostprocessor.GetDefault(this.assetType);
                    var path          = AssetDatabase.GetAssetPath(defaultConfig);
                    var guid          = AssetDatabase.AssetPathToGUID(path);
                    soAssetPostprocessorUtils.Set(this.assetType, this.folderPath, guid);
                    postprocessorConfigGuid = guid;
                }

                paths.Remove(item.Path);
                DeleteSoAssetPostprocessor?.Invoke(item.Guid);
                AssetDatabase.DeleteAsset(item.Path);
                AssetDatabase.Refresh();
            }

            Reload();
        }
Пример #21
0
 public abstract void VerifyAssetError(SoAssetPostprocessor so);
Пример #22
0
 public abstract void VerifyAssetState(SoAssetPostprocessor so);
Пример #23
0
 public override void VerifyAssetError(SoAssetPostprocessor so)
 {
     ErrorLogic.SetValue(false);
 }
Пример #24
0
 public abstract void FixAndReimport(SoAssetPostprocessor so);