示例#1
0
        public Material CreateMaterial(string shader, bool setTexture)
        {
            HugeImporter importer = serializedObject.targetObject as HugeImporter;
            string       path     = importer.assetPath;

            string matPath = path.Substring(0, path.LastIndexOf("."));

            if (File.Exists(matPath + ".mat"))
            {
                int index = 1;
                while (File.Exists(matPath + "_" + index + ".mat"))
                {
                    index++;
                }

                matPath += "_" + index;
            }

            matPath += ".mat";

            Material mat = new Material(Shader.Find(shader));

            if (setTexture)
            {
                mat.SetTexture("_MainTex", AssetDatabase.LoadAssetAtPath <Texture2DArray>(path));
            }
            mat.SetInt("_Cols", cols.intValue);
            mat.SetInt("_Rows", rows.intValue);

            AssetDatabase.CreateAsset(mat, matPath);

            return(AssetDatabase.LoadAssetAtPath <Material>(matPath));
        }
示例#2
0
        public override void OnInspectorGUI()
        {
            if (toolbarLabelStyle == null)
            {
                toolbarLabelStyle = new GUIStyle(EditorStyles.label)
                {
                    alignment = TextAnchor.MiddleCenter
                }
            }
            ;

            DrawToolbarGUI();

            DrawSize();
            DrawExtraSizeFields();

            compressed.boolValue = EditorGUILayout.Toggle("Compression", compressed.boolValue);
            EditorGUILayout.LabelField("or");
            compressed.boolValue = !EditorGUILayout.Toggle("Readability", !compressed.boolValue);

            if (compressed.boolValue)
            {
                EditorGUILayout.PropertyField(quality);
                if (quality.enumValueIndex > 1)
                {
                    EditorGUILayout.HelpBox("Importing with best quality can take VERY long time.", MessageType.Warning);
                }
            }

            EditorGUILayout.PropertyField(transparent);

            TextureFormat format = HugeImporter.GetTextureFormat(EditorUserBuildSettings.activeBuildTarget, compressed.boolValue, transparent.boolValue);

            EditorGUILayout.LabelField("Format", format.ToString());

            pageSize.intValue = EditorGUILayout.IntPopup("Page Size", pageSize.intValue, displayedPageSizes, pageSizes);

            int cx = originalWidth.intValue / pageSize.intValue;

            if (cx == 0)
            {
                cx = 1;
            }

            int cy = originalHeight.intValue / pageSize.intValue;

            if (cy == 0)
            {
                cy = 1;
            }

            cols.intValue = cx;
            rows.intValue = cy;

            EditorGUILayout.LabelField("Cols", cx.ToString());
            EditorGUILayout.LabelField("Rows", cy.ToString());
            EditorGUILayout.LabelField("Total Pages", (cx * cy).ToString());

            if (cx * cy > 2048)
            {
                EditorGUILayout.HelpBox("Total Pages (Cols * Rows) must be less or equal to 2048.\nPage Size will be automatically increased.", MessageType.Error);
            }

            serializedObject.ApplyModifiedProperties();
            bool hasErrors = !ValidateFields();

            if (hasErrors)
            {
                DrawWarnings();
            }
            using (new EditorGUI.DisabledScope(hasErrors))
            {
                ApplyRevertGUI();
            }

            EditorGUILayout.Separator();
            EditorGUILayout.LabelField("Actions:");
            if (GUILayout.Button("Create Material"))
            {
                if (UnityEngine.Rendering.GraphicsSettings.renderPipelineAsset == null)
                {
                    CreateMaterial("Huge Texture/Diffuse Array", true);
                }
                else
                {
                    CreateMaterial("Shader Graphs/HugeTexturePBR", true);
                }
            }

            if (GUILayout.Button("Create Huge Raw Image"))
            {
                HugeRawImage hugeRawImage = HugeRawImageCreator.Create();
                Material     mat          = CreateMaterial("Huge Texture/UI Array", false);
                hugeRawImage.material = mat;
                hugeRawImage.texture  = AssetDatabase.LoadAssetAtPath <Texture2DArray>((serializedObject.targetObject as HugeImporter).assetPath);
            }
        }