Ejemplo n.º 1
0
        public void Reload()
        {
            switch (source)
            {
            case MatrixAsset.Source.Raw:
                if (rawPath != null)
                {
                    MatrixAsset.ImportRaw(ref matrix, rawPath);
                }
                break;

            case MatrixAsset.Source.Texture:
                if (textureSource != null)
                {
                    MatrixAsset.ImportTexture(ref matrix, textureSource, channelSource);
                }
                break;

            case MatrixAsset.Source.New:
                if (matrix == null || matrix.rect.size.x != newRes || matrix.rect.size.z != newRes)
                {
                    matrix = new Matrix(new CoordRect(0, 0, newRes, newRes));
                }
                else
                {
                    matrix.Fill(0);
                }
                matrix.rect.offset = newOffset;
                break;
            }

            RefreshPreview();
            RefreshGizmos();
        }
        private void DrawGUI()
        {
            matrixAsset = (MatrixAsset)target;

            using (Cell.LinePx(32))
                Draw.Label("WARNING: Serializing this asset when selected in \nInspector can slow down editor GUI performance.", style: UI.current.styles.helpBox);

            Cell.EmptyLinePx(5);

            if (matrixAsset.matrix != null && matrixAsset.preview == null)
            {
                matrixAsset.RefreshPreview();
            }

            if (matrixAsset.preview != null)
            {
                using (Cell.LinePx(256))
                {
                    Cell.EmptyRowRel(1);
                    using (Cell.RowPx(256))
                    {
                        //Draw.Texture(matrixAsset.preview);
                        Draw.MatrixPreviewTexture(matrixAsset.preview, colorize: colorize, relief: relief, min: 0, max: 1);
                        Draw.MatrixPreviewReliefSwitch(ref colorize, ref relief);
                    }
                    Cell.EmptyRowRel(1);
                }

                if (matrixAsset.rawPath != null)
                {
                    using (Cell.LineStd) Draw.Label(matrixAsset.rawPath);
                }

                if (matrixAsset.matrix != null)
                {
                    using (Cell.LineStd) Draw.Label(matrixAsset.matrix.rect.size.x + ", " + matrixAsset.matrix.rect.size.z);
                }
            }

            Cell.EmptyLinePx(5);

            using (Cell.LineStd) Draw.Field(ref matrixAsset.source, "Map Source");

            if (matrixAsset.source == MatrixAsset.Source.Raw)
            {
                using (Cell.LinePx(22)) Draw.Label("Square gray 16bit RAW, PC byte order", style: UI.current.styles.helpBox);

                using (Cell.LineStd) if (Draw.Button("Load RAW"))
                    {
                        matrixAsset.ImportRaw();
                        EditorUtility.SetDirty(matrixAsset);
                    }
            }

            else             //texture
            {
                using (Cell.LineStd)
                {
                    Texture2D newTexture = Draw.ObjectField(matrixAsset.textureSource, "Texture");                     //

                    if (newTexture != matrixAsset.textureSource)
                    {
                        matrixAsset.ImportTexture(newTexture, matrixAsset.channelSource);
                    }

                    matrixAsset.textureSource = newTexture;

                    EditorUtility.SetDirty(matrixAsset);
                }

                using (Cell.LineStd)
                {
                    MatrixAsset.Channel newChannel = (MatrixAsset.Channel)Draw.Field(matrixAsset.channelSource, "Channel");                     //

                    if (newChannel != matrixAsset.channelSource)
                    {
                        matrixAsset.ImportTexture(matrixAsset.textureSource, newChannel);
                    }

                    matrixAsset.channelSource = newChannel;

                    EditorUtility.SetDirty(matrixAsset);
                }
            }

            using (Cell.LineStd)
            {
                Cell.current.disabled =
                    (matrixAsset.source == MatrixAsset.Source.Raw && matrixAsset.rawPath == null) ||
                    (matrixAsset.source == MatrixAsset.Source.Texture && matrixAsset.textureSource == null);
                if (Draw.Button("Reload"))
                {
                    matrixAsset.Reload();
                    EditorUtility.SetDirty(matrixAsset);
                }
            }
        }