Ejemplo n.º 1
0
        public static void DebugSplats(Matrix matrix, Color backColor, Color foreColor)
        /// Draws gray/red mask on the first terrain found
        {
            Terrain terrain = FindObjectOfType <Terrain>();

            if (terrain == null)
            {
                return;
            }

            TerrainData data = terrain.terrainData;

            data.terrainLayers    = new TerrainLayer[2];
            data.terrainLayers[0] = new TerrainLayer()
            {
                diffuseTexture = TextureExtensions.ColorTexture(2, 2, backColor)
            };
            data.terrainLayers[1] = new TerrainLayer()
            {
                diffuseTexture = TextureExtensions.ColorTexture(2, 2, foreColor)
            };

            Matrix invertedMatrix = new Matrix(matrix);

            invertedMatrix.InvertOne();

            data.alphamapResolution = matrix.rect.size.x;
            matrix.ExportTerrainData(data, 1);
            invertedMatrix.ExportTerrainData(data, 0);
        }
Ejemplo n.º 2
0
        public void Draw(Color color, Texture2D texture = null, Transform parent = null)
        {
            if (mesh == null)
            {
                return;
            }

            if (mat == null)
            {
                mat = new Material(Shader.Find("Standard"));
            }

            if (texture == null)
            {
                if (whiteTex == null)
                {
                    whiteTex = TextureExtensions.ColorTexture(4, 4, Color.white);
                }
                texture = whiteTex;
            }

            mat.SetColor("_Color", color);
            mat.SetTexture("_MainTex", texture);

            mat.SetPass(0);
            Graphics.DrawMeshNow(mesh, parent == null ? Matrix4x4.identity : parent.localToWorldMatrix);
        }
Ejemplo n.º 3
0
 public void RefreshPreview(int size = 128)
 {
     if (matrix != null)
     {
         Matrix previewMatrix = matrix;                // new Matrix( new CoordRect(0,0,size,size) );
         //MatrixOps.Resize(matrix, previewMatrix);
         preview = new Texture2D(previewMatrix.rect.size.x, previewMatrix.rect.size.z);
         previewMatrix.ExportTexture(preview, -1);
     }
     else
     {
         preview = TextureExtensions.ColorTexture(2, 2, Color.black);
     }
 }
        public static void DrawTextureInout(GeneratorsTester.TextureInout inout)
        {
            using (Cell.LineStd)
            {
                using (Cell.RowRel(1 - Cell.current.fieldWidth))
                    Draw.Label("Create New");

                using (Cell.RowRel(Cell.current.fieldWidth))
                    if (Draw.Button("Create"))
                    {
                        //GeneratorTesterWindow window = (GeneratorTesterWindow)GetWindow(typeof (GeneratorTesterWindow));
                        inout.texture            = TextureExtensions.ColorTexture(512, 512, new Color(0.2f, 0.2f, 0.2f, 1));
                        inout.texture.filterMode = FilterMode.Point;
                        inout.texture.Apply();
                    }
            }

            using (Cell.LineStd) Draw.Toggle(ref inout.previewInScene, "Preview In Scene");
            using (Cell.LineStd) Draw.Toggle(ref inout.preview, "Preview");

            if (inout.preview && inout.texture != null)
            {
                using (Cell.LinePx(256))
                {
                    ScrollZoom scrollZoom = new ScrollZoom();
                    scrollZoom.scroll = inout.previewScroll;
                    scrollZoom.zoom   = inout.previewZoom;

                    Draw.ScrollableTexture(inout.texture, scrollZoom);

                    using (Cell.Custom(5, 5, 20, 20))
                        if (Draw.Button("Z"))
                        {
                            scrollZoom.scroll = Vector2.zero; scrollZoom.zoom = 1;
                        }

                    inout.previewScroll = scrollZoom.scroll;
                    inout.previewZoom   = scrollZoom.zoom;
                }
            }
        }
Ejemplo n.º 5
0
        public static void DrawRTPComponentWarning()
        {
                        #if RTP
            if (GraphWindow.current.mapMagic == null)
            {
                return;
            }

            if (GraphWindow.current.mapMagic?.gameObject.GetComponent <ReliefTerrain>() == null || GraphWindow.current.mapMagic?.gameObject.GetComponent <Renderer>() == null)
            {
                using (Cell.LinePx(70))
                {
                    GUIStyle backStyle = UI.current.textures.GetElementStyle("DPUI/Backgrounds/Foldout");

                    using (Cell.Row)
                        Draw.Label("RTP or Renderer \ncomponents are \nnot assigned to \nMapMagic object");

                    using (Cell.RowPx(30))
                        if (Draw.Button("Fix"))
                        {
                            if (GraphWindow.current.mapMagic.gameObject.GetComponent <Renderer>() == null)
                            {
                                MeshRenderer renderer = GraphWindow.current.mapMagic.gameObject.AddComponent <MeshRenderer>();
                                renderer.enabled = false;
                            }
                            if (GraphWindow.current.mapMagic.gameObject.GetComponent <ReliefTerrain>() == null)
                            {
                                ReliefTerrain rtp = GraphWindow.current.mapMagic.gameObject.AddComponent <ReliefTerrain>();

                                //filling empty splats
                                Texture2D emptyTex = TextureExtensions.ColorTexture(4, 4, new Color(0.5f, 0.5f, 0.5f, 1f));
                                emptyTex.name = "Empty";
                                rtp.globalSettingsHolder.splats = new Texture2D[] { emptyTex, emptyTex, emptyTex, emptyTex };
                            }
                        }
                }
                Cell.EmptyLinePx(5);
            }
                        #endif
        }
			public static void DrawRTPComponentWarning ()
			{
				#if RTP
				if (MapMagic.instance.gameObject.GetComponent<ReliefTerrain>()==null || MapMagic.instance.gameObject.GetComponent<Renderer>()==null)
				{
					using (Cell.LinePx(70)))
					{
						Cell.current.margins = new Padding(4);

						GUIStyle backStyle = UI.current.textures.GetElementStyle("DPUI/Backgrounds/Foldout");
						Draw.Element(backStyle, Cell.current);
						Draw.Element(backStyle, Cell.current);

						Draw.Label("RTP or Renderer \ncomponents are \nnot assigned to \nMapMagic object", cell:UI.Empty(Size.row));

						if (Draw.Button("Fix", cell:UI.Empty(Size.RowPixels(30))))
						{
							if (MapMagic.instance.gameObject.GetComponent<Renderer>() == null)
							{
								MeshRenderer renderer = MapMagic.instance.gameObject.AddComponent<MeshRenderer>();
								renderer.enabled = false;
							}
							if (MapMagic.instance.gameObject.GetComponent<ReliefTerrain>() == null)
							{
								ReliefTerrain rtp = MapMagic.instance.gameObject.AddComponent<ReliefTerrain>();

								//filling empty splats
								Texture2D emptyTex = TextureExtensions.ColorTexture(4,4,new Color(0.5f, 0.5f, 0.5f, 1f));
								emptyTex.name = "Empty";
								rtp.globalSettingsHolder.splats = new Texture2D[] { emptyTex,emptyTex,emptyTex,emptyTex };
							}
							MapMagic.instance.OnSettingsChanged();
						}
					}
					UI.Empty(Size.LinePixels(5));
				}
				#endif
			}
Ejemplo n.º 7
0
        private static void DrawTexturesLayer(Generator tgen, int num)
        {
            TexturesOutput200 texOut = (TexturesOutput200)tgen;

            TexturesOutput200.TextureLayer layer = texOut.layers[num];
            if (layer == null)
            {
                return;
            }

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

                Cell.EmptyRowPx(10);

                Texture2D tex = layer.prototype != null ? layer.prototype.diffuseTexture : UI.current.textures.GetTexture("DPUI/Backgrounds/Empty");
                using (Cell.RowPx(28)) Draw.TextureIcon(tex);

                using (Cell.Row)
                {
                    Cell.current.trackChange = false;
                    Draw.EditableLabel(ref layer.name);
                }

                using (Cell.RowPx(20))
                {
                    Cell.current.trackChange = false;
                    Draw.LayerChevron(num, ref texOut.guiExpanded);
                }

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

            if (texOut.guiExpanded == num)
            {
                using (Cell.Line)
                {
                    Cell.EmptyRowPx(2);

                    using (Cell.Row)
                    {
                        using (Cell.LinePx(0))
                            using (Cell.Padded(1, 0, 0, 0))
                            {
                                //using (Cell.LineStd) layer.Opacity = Draw.Field(layer.Opacity, "Opacity");
                                //using (Cell.LineStd) Draw.ObjectField(ref layer.prototype, "Layer");

                                Draw.Class(layer, "Layer", addFieldsToCellObjs: true);
                                //this will add terrainlayer to exposed

                                if (layer.name == "Layer" && layer.prototype != null)
                                {
                                    layer.name = layer.prototype.name;
                                }
                            }

                        if (layer.prototype != null)
                        {
                            Cell.EmptyLinePx(2);

                            using (Cell.LineStd)
                                using (new Draw.FoldoutGroup(ref layer.guiProperties, "Properties"))
                                    if (layer.guiProperties)
                                    {
                                        //textures
                                        using (Cell.LineStd)
                                        {
                                            Texture2D tex = layer.prototype.diffuseTexture;
                                            Draw.Field(ref tex, "Diffuse");
                                            if (Cell.current.valChanged)
                                            {
                                                if (layer.prototype.diffuseTexture.name == "WrColorPlaceholder2x2")
                                                {
                                                    GameObject.DestroyImmediate(layer.prototype.diffuseTexture);                             // removing temporary color texture if assigned
                                                }
                                                layer.prototype.diffuseTexture = tex;
                                            }
                                        }

                                        using (Cell.LineStd)
                                        {
                                            Texture2D tex = layer.prototype.normalMapTexture;
                                            Draw.Field(ref tex, "Normal");
                                            if (Cell.current.valChanged)
                                            {
                                                layer.prototype.normalMapTexture = tex;
                                            }
                                        }

                                        using (Cell.LineStd)
                                        {
                                            Texture2D tex = layer.prototype.maskMapTexture;
                                            Draw.Field(ref tex, "Mask");
                                            if (Cell.current.valChanged)
                                            {
                                                layer.prototype.maskMapTexture = tex;
                                            }
                                        }

                                        //color (after texture)
                                        if (layer.prototype.diffuseTexture == null)
                                        {
                                            layer.prototype.diffuseTexture      = TextureExtensions.ColorTexture(2, 2, layer.color);
                                            layer.prototype.diffuseTexture.name = "WrColorPlaceholder2x2";
                                        }

                                        if (layer.prototype.diffuseTexture.name == "WrColorPlaceholder2x2")
                                        {
                                            using (Cell.LineStd)
                                            {
                                                using (Cell.LineStd) Draw.Field(ref layer.color, "Color");
                                                if (Cell.current.valChanged)
                                                {
                                                    layer.prototype.diffuseTexture.Colorize(layer.color);
                                                }
                                            }
                                        }


                                        using (Cell.LineStd) layer.prototype.specular = Draw.Field(layer.prototype.specular, "Specular");
                                        using (Cell.LineStd) layer.prototype.smoothness = Draw.Field(layer.prototype.smoothness, "Smooth");
                                        using (Cell.LineStd) layer.prototype.metallic = Draw.Field(layer.prototype.metallic, "Metallic");
                                        using (Cell.LineStd) layer.prototype.normalScale = Draw.Field(layer.prototype.normalScale, "N. Scale");
                                    }

                            using (Cell.LineStd)
                                using (new Draw.FoldoutGroup(ref layer.guiTileSettings, "Tile Settings"))
                                    if (layer.guiTileSettings)
                                    {
                                        using (Cell.LineStd) layer.prototype.tileSize = Draw.Field(layer.prototype.tileSize, "Size");
                                        using (Cell.LineStd) layer.prototype.tileOffset = Draw.Field(layer.prototype.tileOffset, "Offset");
                                    }

                            if (layer.guiTileSettings)
                            {
                                Cell.EmptyLinePx(3);
                            }
                        }
                    }

                    /*using (UI.FoldoutGroup(ref layer.guiRemapping, "Remapping", inspectorOffset:0, margins:0))
                     * if (layer.guiTileSettings)
                     * {
                     *      using (Cell.LineStd)
                     *      {
                     *              Draw.Label("Red", cell:UI.Empty(Size.row));
                     *              layer.prototype.diffuseRemapMin.x = Draw.Field(layer.prototype.diffuseRemapMin.x, cell:UI.Empty(Size.row));
                     *      }
                     * }*/

                    Cell.EmptyRowPx(2);
                }
            }
        }
Ejemplo n.º 8
0
        public override void OnGUI(Rect rect)
        {
            //showing window next frame
            Action tmp = nextFrameShow;

            nextFrameShow = null;                     //because we can't null it after it has been called (new window will be started)
            tmp?.Invoke();

            //preparing textures
            if (background == null)
            {
                background = new Texture2D(1, 1, TextureFormat.RGBA32, false);
                background.SetPixel(0, 0, new Color(0.98f, 0.98f, 0.98f));
                background.Apply();
            }

            if (highlight == null)
            {
                highlight = new Texture2D(1, 1, TextureFormat.RGBA32, false);
                highlight.SetPixel(0, 0, new Color(0.6f, 0.7f, 0.9f));
                highlight.Apply();
            }

            Vector2 size = GetWindowSize();
            Vector2 pos  = new Vector2(0, verticalOffset);

            //background
            //if (Event.current.type == EventType.repaint) GUI.skin.box.Draw(fullRect, false, true, true, false);
            UnityEngine.GUI.DrawTexture(new Rect(pos, size), background, ScaleMode.StretchToFill);

            //list
            float currentHeight = verticalOffsetTmp;
            int   itemsCount    = items.Count;

            for (int i = 0; i < itemsCount; i++)
            {
                Item currentItem = items[i];

                //rects
                Rect lineRect = new Rect(1, currentHeight + 1, size.x - 2, currentItem.height - 2);
                currentHeight += currentItem.height;

                Rect offsetRect = new Rect(lineRect.x, lineRect.y, Item.lineHeight * currentItem.offset, lineRect.height);
                Rect labelRect  = new Rect(lineRect.x + offsetRect.width + 3, lineRect.y + 1, lineRect.width - offsetRect.width - 3, lineRect.height - 1);

                //background
                bool highlighted = lineRect.Contains(Event.current.mousePosition);
                if (currentItem.disabled)
                {
                    highlighted = false;
                }
                if (highlighted)
                {
                    UnityEngine.GUI.DrawTexture(lineRect, highlight);
                }

                /*{
                 *      //GUIStyle style = texturesCache.GetElementStyle(tex);
                 *      //if (Event.current.type == EventType.Repaint) style.Draw(leftRect, false, false, false ,false);
                 *
                 *      GUIStyle style = new GUIStyle();
                 *      style.normal.background = highlight;
                 *      style.border = new RectOffset(highlight.width/2, highlight.width/2, highlight.height/2, highlight.height/2);
                 *
                 *      if (Event.current.type == EventType.Repaint) style.Draw(lineRect, false, false, false ,false);
                 * }*/

                //clicking
                bool clicked = Event.current.rawType == EventType.MouseUp && Event.current.button == 0;
                if (highlighted && clicked && currentItem.onClick != null)
                {
                    currentItem.onClick();
                    CloseRecursive();
                    Event.current.Use();
                }

                //label
                UnityEditor.EditorGUI.BeginDisabledGroup(currentItem.disabled);
                //if (blackLabel == null) { blackLabel = new GUIStyle(UnityEditor.EditorStyles.label); blackLabel.normal.textColor = Color.black; }
                if (currentItem.onDraw != null)
                {
                    currentItem.onDraw(currentItem, lineRect);
                }
                else
                {
                    EditorGUI.LabelField(labelRect, currentItem.name);
                }
                UnityEditor.EditorGUI.EndDisabledGroup();

                //separator
                if (currentItem.isSeparator)
                {
                    if (currentItem.onDraw == null)
                    {
                        Rect separatorRect = new Rect(lineRect.x + 3, lineRect.y, lineRect.width - 6, 1);
                        if (separator == null)
                        {
                            separator = TextureExtensions.ColorTexture(2, 2, new Color(0.3f, 0.3f, 0.3f, 1));
                        }
                        UnityEngine.GUI.DrawTexture(separatorRect, separator, ScaleMode.ScaleAndCrop);
                    }
                    else
                    {
                        currentItem.onDraw(currentItem, lineRect);
                    }
                }

                //chevron
                if (currentItem.hasSubs)
                {
                    Rect rightRect = lineRect; rightRect.width = 10; rightRect.height = 10;
                    rightRect.x = lineRect.x + lineRect.width - rightRect.width; rightRect.y = lineRect.y + lineRect.height / 2 - rightRect.height / 2;
                    //UnityEditor.EditorGUI.LabelField(rightRect, "\u25B6");
                    //	if (triangle == null) triangle = Resources.Load("DPUI/Chevrons/SmallRight") as Texture2D;
                    //	UnityEngine.GUI.DrawTexture(GetIconRect(rightRect, triangle), triangle, ScaleMode.ScaleAndCrop);

                    //opening subsmenus
                    if (highlighted)
                    {
                        //starting timer on selected item change
                        if (currentItem != lastItem)
                        {
                            lastTimestart = System.DateTime.Now;
                            lastItem      = currentItem;
                        }

                        //when holding for too long
                        double highlightTime = (System.DateTime.Now - lastTimestart).TotalMilliseconds;
                        if ((highlightTime > 150 && expandedItem != currentItem) || clicked)
                        {
                            //re-opening expanded window
                            if (expandedWindow != null && expandedWindow.editorWindow != null)
                            {
                                expandedWindow.editorWindow.Close();
                            }

                            expandedWindow = new PopupMenu()
                            {
                                items    = currentItem.subItems,
                                minWidth = minWidth,
                                parent   = this
                            };
                            expandedItem = currentItem;

                            //nextFrameShow = () => expandedWindow.Show(lineRect.max-new Vector2(0,currentItem.height));
                            expandedWindow.Show(lineRect.max - new Vector2(0, currentItem.height));
                            editorWindow.Focus();

                            //if (currentItem.subItems != null) PopupWindow.Show(new Rect(lineRect.max-new Vector2(0,currentItem.height), Vector2.zero), expandedWindow);
                        }
                    }
                }
            }

            //#if (!UNITY_EDITOR_LINUX)
            this.editorWindow.Repaint();
            //#endif
        }