示例#1
0
        public void ApplySettings <T>(AssetImporter assetImport, T obj) where T : UnityEngine.Object
        {
            TextureImporter importer = assetImport as TextureImporter;

            if (importer == null)
            {
                return;
            }

            importer.textureType      = TextureImporterType.Sprite;
            importer.spriteImportMode = SpriteImportMode.Single;

            //自动设置打包tag;
            string fileName = Path.GetFileNameWithoutExtension(assetImport.assetPath);

            importer.spritePackingTag = AssetFormatConst.PREFIX_SPRITE_TAG_AGRB_POT + fileName;

            // 关闭Read/Write和Mipmap
            importer.mipmapEnabled       = false;
            importer.isReadable          = false;
            importer.alphaIsTransparency = true;

            AssetImportHelper.OverrideAndroid(importer, TextureImporterFormat.ETC2_RGBA8);
            AssetImportHelper.OverrideIos(importer, TextureImporterFormat.PVRTC_RGBA4);
            importer.SaveAndReimport();
        }
示例#2
0
        public void ApplySettings <T>(AssetImporter assetImport, T obj) where T : Object
        {
            TextureImporter importer = assetImport as TextureImporter;

            if (importer == null)
            {
                return;
            }

            importer.textureType         = TextureImporterType.Sprite;
            importer.textureShape        = TextureImporterShape.Texture2D;
            importer.npotScale           = TextureImporterNPOTScale.None;
            importer.spriteImportMode    = SpriteImportMode.Single;
            importer.sRGBTexture         = true;
            importer.alphaIsTransparency = true;
            importer.wrapMode            = TextureWrapMode.Repeat;
            importer.filterMode          = FilterMode.Bilinear;
            importer.mipmapEnabled       = false;
            importer.isReadable          = false;
            importer.spritePackingTag    = string.Empty;
            AssetImportHelper.OverrideAndroid(importer, TextureImporterFormat.RGBA32);
            AssetImportHelper.OverrideIos(importer, TextureImporterFormat.RGBA32);

            importer.SaveAndReimport();
        }
示例#3
0
 public bool IsMatch <T>(T t, string assetPath) where T : UnityEngine.Object
 {
     if (!AssetImportHelper.IsMath(assetPath, FilterPath))
     {
         return(false);
     }
     if (_filter == null)
     {
         return(false);
     }
     return(_filter.IsMatch <T>(t));
 }
示例#4
0
        public override bool IsInternalMatch(Texture2D tex)
        {
            if (!AssetImportHelper.IsPot(tex))
            {
                return(false);
            }

            if (!AssetImportHelper.HasAlphaChannel(tex))
            {
                return(false);
            }

            return(true);
        }
示例#5
0
        public void ApplySettings <T>(AssetImporter assetImport, T obj) where T : UnityEngine.Object
        {
            TextureImporter importer = assetImport as TextureImporter;

            if (importer == null)
            {
                return;
            }

            importer.textureType   = TextureImporterType.Default;
            importer.textureShape  = TextureImporterShape.Texture2D;
            importer.npotScale     = TextureImporterNPOTScale.None;
            importer.mipmapEnabled = false;
            importer.isReadable    = false;

            AssetImportHelper.OverrideAndroid(importer, TextureImporterFormat.RGB24);
            AssetImportHelper.OverrideIos(importer, TextureImporterFormat.PVRTC_RGB4);
            importer.SaveAndReimport();
        }
        /*
         * Read project
         */
        public static bool ReadProject(Project project, string projectFolder)
        {
            // Force an Asset Refresh before starting this, in case Unity
            // doesn't have auto-refresh on.
            AssetDatabase.Refresh();

            // Asset paths are relative to project folder
            string unityPrjFolder = Application.dataPath.Replace("Assets", "");

            projectFolder = projectFolder.Replace(unityPrjFolder, "");

            // Ensure the target folder is empty, and exists.
            if (!IsProjectFolderEmpty())
            {
                ClearProjectFolder();
                CreateProjectFolders();
            }

            try {
                string    fullPrjPath  = projectFolder + "/" + projectFileName;
                TextAsset projectAsset = AssetDatabase.LoadAssetAtPath <TextAsset>(fullPrjPath);
                if (projectAsset == null)
                {
                    throw new Exception("No project asset found at " + fullPrjPath + ".");
                }
                else
                {
                    AssetImportHelper.SetupSprites(projectFolder);
                }

                string   projectContents = Encoding.UTF8.GetString(projectAsset.bytes);
                JSONNode root            = JSONNode.Parse(projectContents);

                project.project = root["name"];

                // Read assets
                EditorUtility.DisplayProgressBar("Arcweave", "Loading assets...", 0.0f);
                ReadAssets(project, root["assets"].AsObject, projectFolder);

                // Read attributes
                EditorUtility.DisplayProgressBar("Arcweave", "Creating attributes...", 10.0f);
                ReadAttributes(project, root["attributes"].AsObject);

                // Read components
                EditorUtility.DisplayProgressBar("Arcweave", "Creating components...", 20.0f);
                ReadComponents(project, root["components"].AsObject, projectFolder);

                // Read elements
                EditorUtility.DisplayProgressBar("Arcweave", "Creating elements...", 30.0f);
                ReadElements(project, root["elements"].AsObject, projectFolder);

                // Read jumpers
                EditorUtility.DisplayProgressBar("Arcweave", "Creating jumpers...", 37.5f);
                ReadJumpers(project, root["jumpers"].AsObject);

                // Read connections
                EditorUtility.DisplayProgressBar("Arcweave", "Creating connections...", 45.0f);
                ReadConnections(project, root["connections"].AsObject);

                // Read notes
                EditorUtility.DisplayProgressBar("Arcweave", "Creating notes...", 60.0f);
                ReadNotes(project, root["notes"].AsObject);

                // Read boards
                EditorUtility.DisplayProgressBar("Arcweave", "Creating boards...", 75.0f);
                BoardUtils.ReadBoards(project, root["boards"].AsObject);

                // Re-do the entity linking
                project.Relink();

                // Resolve references inside elements and connections
                // Must happen after reading everything, so Arcweave has the referenced elements instantiated.
                EditorUtility.DisplayProgressBar("Arcweave", "Preprocessing HTML...", 90.0f);
                for (int i = 0; i < project.elements.Length; i++)
                {
                    project.elements[i].ParseHTML(project);
                }

                for (int i = 0; i < project.connections.Length; i++)
                {
                    project.connections[i].ParseHTML(project);
                }

                // Set default roots for boards
                for (int i = 0; i < project.boards.Length; i++)
                {
                    BoardUtils.SetDefaultRoot(project.boards[i]);
                    EditorUtility.SetDirty(project.boards[i]);
                }

                // Handle root set in the JSON
                string startingElementID = root["startingElement"];
                if (!string.IsNullOrEmpty(startingElementID))
                {
                    Element startingElement = project.GetElement(startingElementID);
                    if (startingElement != null)
                    {
                        Board rootBoard = project.GetBoardForElement(startingElementID);
                        if (rootBoard != null)
                        {
                            project.startingBoardIdx = project.GetBoardIndex(rootBoard);
                            rootBoard.rootElementId  = startingElementID;
                        }
                    }
                    else
                    {
                        Debug.LogWarning("[Arcweave] Cannot find starting element of id: " + startingElementID + ". Fallback to computing roots.");
                    }
                }
            } catch (Exception e) {
                Debug.LogError("[Arcweave] Cannot load project: " + e.Message + "\n" + e.StackTrace);
                EditorUtility.ClearProgressBar();
                return(false);
            }

            Debug.Log("[Arcweave] Import completed successfully.");
            EditorUtility.ClearProgressBar();
            return(true);
        }