public static HugeRawImage Create()
        {
            Canvas     canvas = CanvasUtils.GetCanvas();
            GameObject go     = new GameObject("Huge Raw Image");

            go.AddComponent <RectTransform>();
            go.AddComponent <CanvasRenderer>();
            HugeRawImage hugeRawImage = go.AddComponent <HugeRawImage>();

            go.transform.SetParent(canvas.transform);
            go.transform.localPosition = Vector3.zero;

            return(hugeRawImage);
        }
Beispiel #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);
            }
        }