コード例 #1
0
ファイル: MatrixInitial.cs プロジェクト: AJ213/Awitu
        public static void OnMatrixAssetReloaded_ReGenerate(MatrixAsset ma)
        /// If this matrixAsset is used then clearing this node in all related mapmagics and starting generate
        {
            MapMagicObject[] mapMagics = GameObject.FindObjectsOfType <MapMagicObject>();
            foreach (MapMagicObject mapMagic in mapMagics)
            {
                bool containsMa = false;
                if (mapMagic.graph != null)
                {
                    foreach (Import200 gen in mapMagic.graph.GeneratorsOfType <Import200>())
                    {
                        if (gen.matrixAsset == ma)
                        {
                            mapMagic.Clear(gen);

                            containsMa = true;
                            break;
                        }
                    }
                }

                if (containsMa)
                {
                    mapMagic.StartGenerate();
                }
            }
        }
コード例 #2
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();
        }
コード例 #3
0
        //public static WeakEvent<Texture2D> OnTextureImported = new WeakEvent<Texture2D>();
        //In MatrixAsset since it should work in non-editors

        //public void OnPostprocessTexture(Texture2D tex)  //using OnPostprocessAllAssets because tex here is not the same tex as the changed one

        static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths)
        {
            for (int a = 0; a < importedAssets.Length; a++)
            {
                if (AssetDatabase.GetMainAssetTypeAtPath(importedAssets[a]) != typeof(Texture2D))
                {
                    continue;
                }
                Texture2D tex = AssetDatabase.LoadAssetAtPath <Texture2D>(importedAssets[a]);

                if (MatrixAsset.OnTextureImported != null)
                {
                    MatrixAsset.OnTextureImported(tex);
                }
            }
        }
コード例 #4
0
        public void DrawInspector(Matrix matrix, BaseMatrixWindow window)
        {
            if (matrix == null)
            {
                return;
            }

            using (Cell.LineStd) Draw.Field(ref margins, "Margins");

            using (Cell.LineStd)
            {
                using (Cell.RowPx(50)) Draw.Label("Asset");
                using (Cell.Row) Draw.ObjectField(ref exportAsset, allowSceneObject: true);
                using (Cell.RowPx(60))
                    if (Draw.Button("Save..."))
                    {
                        MatrixAsset matrixAsset = new MatrixAsset();
                        matrixAsset.matrix = matrix;
                        matrixAsset.RefreshPreview();
                        ScriptableAssetExtensions.SaveAsset(matrixAsset);
                    }


                Cell.EmptyRowPx(10);
                using (Cell.RowPx(60))
                {
                    //if (Draw.Button("Save...")) {}
                }
            }

            using (Cell.LineStd)
            {
                using (Cell.RowPx(50)) Draw.Label("Texture");
                using (Cell.Row) Draw.ObjectField(ref exportTexture, allowSceneObject: true);
                using (Cell.RowPx(60))
                    if (Draw.Button("Export") && exportTexture != null)
                    {
                        MatrixToTexture(matrix, ref exportTexture);
                    }

                Cell.EmptyRowPx(10);
                using (Cell.RowPx(60))
                    if (Draw.Button("Save..."))
                    {
                        Texture2D texture = null;
                        MatrixToTexture(matrix, ref texture);
                        ScriptableAssetExtensions.SaveTexture(texture);
                    }
            }

            using (Cell.LineStd)
            {
                using (Cell.RowPx(50)) Draw.Label("Terrain");
                using (Cell.Row) Draw.ObjectField(ref exportTerrain, allowSceneObject: true);
                using (Cell.RowPx(60))
                    if (Draw.Button("Export") && exportTerrain != null)
                    {
                        MatrixToTerrain(matrix, exportTerrain);
                    }

                Cell.EmptyRowPx(10);
                using (Cell.RowPx(60))
                {
                    //if (Draw.Button("Save...")) {}
                }
            }
        }
コード例 #5
0
        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);
                }
            }
        }