public static Color GetPixel(this Texture2DArray srcArr, int x, int y, int ch)
        /// Debug purpose only
        {
            Texture2D tmp = srcArr.GetTexture(ch);

            return(tmp.GetPixel(x, y));
        }
        static public void Switch(this Texture2DArray texArr, int num1, int num2)
        {
            if (num1 < 0 || num1 >= texArr.depth || num2 < 0 || num2 >= texArr.depth)
            {
                return;
            }

            Texture2D temp = texArr.GetTexture(num1);

            CopyTexture(texArr, num2, texArr, num1);
            texArr.SetTexture(temp, num2);
        }
        public Texture2D GetPreview(int ch)
        {
                        #if UNITY_EDITOR
            if (srcArr[ch].preview == null)
            {
                srcArr[ch].preview = texArr.GetTexture(ch);
            }

            return(srcArr[ch].preview);
                        #else
            return(null);
                        #endif
        }
        public static void FillTexture(this Texture2DArray srcArr, Texture2D dst, int srcCh)
        {
            if (srcArr.depth <= srcCh)
            {
                throw new System.IndexOutOfRangeException("Trying to get channel (" + srcCh + ") >= depth (" + srcArr.depth + ")");
            }

            //format and size match
            if (srcArr.format == dst.format && srcArr.width == dst.width && srcArr.height == dst.height)
            {
                Graphics.CopyTexture(srcArr, srcCh, dst, 0);
                dst.Apply(updateMipmaps: false);
                return;
            }

            Texture2D tmpTex = srcArr.GetTexture(srcCh, readable: true);

            if (tmpTex.format.IsCompressed())
            {
                tmpTex = tmpTex.UncompressedClone();                                            //uncompress to change format
            }
            if (tmpTex.width != dst.width || tmpTex.height != dst.height)
            {
                tmpTex = tmpTex.ResizedClone(dst.width, dst.height);
            }

                        #if UNITY_EDITOR
                        #if UNITY_2018_3_OR_NEWER
            UnityEditor.EditorUtility.CompressTexture(tmpTex, dst.format, 100);                            //de-compress and compress to change the format
                        #else
            UnityEditor.EditorUtility.CompressTexture(tmpTex, dst.format, TextureCompressionQuality.Best); //de-compress and compress to change the format
                        #endif
                        #else
            if (dst.format.IsCompressed())
            {
                tmpTex.Compress(true);
            }
                        #endif
            tmpTex.Apply(updateMipmaps: false);

            Graphics.CopyTexture(tmpTex, dst);
            dst.Apply(updateMipmaps: false);
        }
Ejemplo n.º 5
0
        private static void DrawMicroSplatLayer(Generator tgen, int num)
        {
            MicroSplatOutput200 gen = (MicroSplatOutput200)tgen;

            MicroSplatOutput200.MicroSplatLayer layer = gen.layers[num];
            if (layer == null)
            {
                return;
            }

            Material microSplatMat = null;

            if (GraphWindow.current.mapMagic != null)
            {
                microSplatMat = GraphWindow.current.mapMagic.terrainSettings.material;
            }

            Cell.EmptyLinePx(3);
            using (Cell.LinePx(28))
            {
                //Cell.current.margins = new Padding(0,0,0,1); //1-pixel more padding from the bottom since layers are 1 pixel overlayed

                if (num != 0)
                {
                    using (Cell.RowPx(0)) GeneratorDraw.DrawInlet(layer, gen);
                }
                else
                //disconnecting last layer inlet
                if (GraphWindow.current.graph.IsLinked(layer))
                {
                    GraphWindow.current.graph.UnlinkInlet(layer);
                }

                Cell.EmptyRowPx(10);

                //icon
                Texture2DArray iconsArr = null;
                if (microSplatMat != null && microSplatMat.HasProperty("_Diffuse"))
                {
                    iconsArr = (Texture2DArray)microSplatMat?.GetTexture("_Diffuse");
                }

                using (Cell.RowPx(28))
                {
                    if (iconsArr != null)
                    {
                        Draw.TextureIcon(iconsArr, layer.channelNum);
                    }
                }

                Cell.EmptyRowPx(10);

                //index
                using (Cell.Row)
                {
                    Cell.EmptyLine();
                    using (Cell.LineStd)
                    {
                        int newIndex = Draw.Field(layer.channelNum, "Index");
                        if (newIndex >= 0 && (iconsArr == null || newIndex < iconsArr.depth))
                        {
                            layer.channelNum = newIndex;
                            layer.prototype  = null;
                        }
                    }
                    Cell.EmptyLine();
                }

                //terrain layer (if enabled)
                if (GraphWindow.current.mapMagic != null && GraphWindow.current.mapMagic.globals.microSplatApplyType != Globals.MicroSplatApplyType.Textures)               //no need to create layers for textures-only mode
                {
                    TerrainLayer tlayer = layer.prototype;
                    if (tlayer == null)
                    {
                        tlayer = new TerrainLayer(); layer.prototype = tlayer;
                    }
                    if (tlayer.diffuseTexture == null)
                    {
                        tlayer.diffuseTexture = iconsArr.GetTexture(num);
                    }
                }

                Cell.EmptyRowPx(10);
                using (Cell.RowPx(0)) GeneratorDraw.DrawOutlet(layer);
            }
            Cell.EmptyLinePx(3);
        }