/// <summary> /// Draws the icon in a square rect, with a custom shader that makes the icon look better when down-scaled. /// This also handles mouseover effects, and linier color spacing. /// </summary> //[Obsolete("Draw the texture like you normally would instead.")] public void Draw(Rect rect, float drawSize) { if (Event.current.type != EventType.Repaint) { return; } Texture iconTex; if (!GUI.enabled) { iconTex = this.Inactive; } else if (rect.Contains(Event.current.mousePosition)) { GUIHelper.RequestRepaint(); iconTex = this.Highlighted; } else { iconTex = this.Active; } rect = rect.AlignCenter(drawSize, drawSize); this.Draw(rect, iconTex); }
public Bullet CreateBullet() { GameObject obj = new GameObject("Bullet"); Transform transform = obj.AddComponent <Transform>(); RigidBody body = obj.AddComponent <RigidBody>(); SpriteRenderer sprite = obj.AddComponent <SpriteRenderer>(); Bullet bullet = obj.AddComponent <Bullet>(); Material spriteMaterial = this.spriteMaterial.Res ?? Material.SolidWhite.Res; Vector2 spriteSize = spriteMaterial.MainTexture.IsAvailable ? spriteMaterial.MainTexture.Res.Size : new Vector2(5, 5); float spriteRadius = MathF.Max(spriteSize.X, spriteSize.Y) * 0.25f; body.ClearShapes(); CircleShapeInfo circleShape = new CircleShapeInfo(spriteRadius, Vector2.Zero, 1.0f); circleShape.IsSensor = true; body.AddShape(circleShape); body.CollisionCategory = CollisionCategory.Cat3; body.CollidesWith &= ~CollisionCategory.Cat3; sprite.SharedMaterial = this.spriteMaterial; sprite.Rect = Rect.AlignCenter(0.0f, 0.0f, spriteSize.X * 0.5f, spriteSize.Y * 0.5f); bullet.InitFrom(this); return(bullet); }
/// <summary> /// Creates a GameObject covering the entirety of the Camera's viewport and applies a ColorizeSprite /// Command going from one Color to another /// </summary> /// <param name="inCamera">The Camera</param> /// <param name="inTime">The time, in milliseconds, that the transition will take</param> /// <param name="inStartColor">The starting color</param> /// <param name="inEndColor">The ending color</param> public static void Fade(this Camera inCamera, float inTime, ColorRgba inStartColor, ColorRgba inEndColor) { GameObject fader = new GameObject("Fader", inCamera.GameObj); Transform t = new Transform(); fader.AddComponent <Transform>(t); SpriteRenderer sr = new SpriteRenderer(); fader.AddComponent <SpriteRenderer>(sr); Commander cmd = new Commander(); fader.AddComponent <Commander>(cmd); t.RelativePos = new Vector3(0, 0, inCamera.FocusDist); sr.Rect = Rect.AlignCenter(0, 0, DualityApp.TargetResolution.X, DualityApp.TargetResolution.Y); sr.SharedMaterial = new ContentRef <Material>(new Material(DrawTechnique.Alpha, Colors.White, Texture.White)); sr.ColorTint = inStartColor; cmd.ColorizeSprite(inEndColor).Timed(inTime); cmd.Destroy(); inCamera.GameObj.ParentScene.AddObject(fader); }
public override bool Convert(ConvertOperation convert) { List <object> results = new List <object>(); List <Material> availData = convert.Perform <Material>().ToList(); // Generate objects foreach (Material mat in availData) { if (convert.IsObjectHandled(mat)) { continue; } Texture mainTex = mat.MainTexture.Res; GameObject gameobj = convert.Result.OfType <GameObject>().FirstOrDefault(); if (mainTex == null || mainTex.AnimFrames == 0) { SpriteRenderer sprite = convert.Result.OfType <SpriteRenderer>().FirstOrDefault(); if (sprite == null && gameobj != null) { sprite = gameobj.GetComponent <SpriteRenderer>(); } if (sprite == null) { sprite = new SpriteRenderer(); } sprite.SharedMaterial = mat; if (mainTex != null) { sprite.Rect = Rect.AlignCenter(0.0f, 0.0f, mainTex.PixelWidth, mainTex.PixelHeight); } convert.SuggestResultName(sprite, mat.Name); results.Add(sprite); } else { AnimSpriteRenderer sprite = convert.Result.OfType <AnimSpriteRenderer>().FirstOrDefault(); if (sprite == null && gameobj != null) { sprite = gameobj.GetComponent <AnimSpriteRenderer>(); } if (sprite == null) { sprite = new AnimSpriteRenderer(); } sprite.SharedMaterial = mat; sprite.Rect = Rect.AlignCenter(0.0f, 0.0f, mainTex.PixelWidth / mainTex.AnimCols, mainTex.PixelHeight / mainTex.AnimRows); sprite.AnimDuration = 5.0f; sprite.AnimFrameCount = mainTex.AnimFrames; convert.SuggestResultName(sprite, mat.Name); results.Add(sprite); } convert.MarkObjectHandled(mat); } convert.AddResult(results); return(false); }
internal ParticleMaterial(ContentRef <Material> inMaterial) { Material = inMaterial; Texture mainTex = inMaterial.Res.MainTexture.Res; Center = mainTex.Size / 2f; Rectangle = Rect.AlignCenter(0, 0, mainTex.Size.X, mainTex.Size.Y); }
protected override void DrawPropertyLayout(GUIContent label) { Rect rect = EditorGUILayout.GetControlRect(); Color tempColor = this.ValueEntry.SmartValue; string hexCode = ColorUtility.ToHtmlStringRGB(tempColor); if (label != null) { rect = EditorGUI.PrefixLabel(rect, label); } rect = EditorGUILayout.GetControlRect(); tempColor = SirenixEditorFields.ColorField(rect.AlignLeft(rect.width * 0.75f), tempColor); //hexcode hexCode = SirenixEditorFields.TextField(rect.AlignRight(rect.width * 0.25f), "#" + hexCode); if (ColorUtility.TryParseHtmlString(hexCode, out tempColor)) { this.ValueEntry.SmartValue = tempColor; } //rgb values rect = EditorGUILayout.GetControlRect(); GUIHelper.PushLabelWidth(15); tempColor.r = EditorGUI.Slider(rect.AlignLeft(rect.width * 0.3f), "R", tempColor.r, 0f, 1f); tempColor.g = EditorGUI.Slider(rect.AlignCenter(rect.width * 0.3f), "G", tempColor.g, 0f, 1f); tempColor.b = EditorGUI.Slider(rect.AlignRight(rect.width * 0.3f), "B", tempColor.b, 0f, 1f); GUIHelper.PopLabelWidth(); //hsv values Color.RGBToHSV(tempColor, out float h, out float s, out float v); rect = EditorGUILayout.GetControlRect(); GUIHelper.PushLabelWidth(15); h = EditorGUI.Slider(rect.AlignLeft(rect.width * 0.3f), "H", h, 0f, 1f); s = EditorGUI.Slider(rect.AlignCenter(rect.width * 0.3f), "S", s, 0f, 1f); v = EditorGUI.Slider(rect.AlignRight(rect.width * 0.3f), "V", v, 0f, 1f); GUIHelper.PopLabelWidth(); tempColor = Color.HSVToRGB(h, s, v); this.ValueEntry.SmartValue = tempColor; }
/// <summary> /// Draws the graphics for a DropZone. /// </summary> public static void DrawDropZone(Rect rect, object value, GUIContent label, int id) { bool isDragging = IsDragging; if (Event.current.type == EventType.Repaint) { var objectToPaint = value as UnityEngine.Object; var objectFieldThumb = EditorStyles.objectFieldThumb; var on = GUI.enabled && hoveringAcceptedDropZone == id && rect.Contains(Event.current.mousePosition) && isDragging; objectFieldThumb.Draw(rect, GUIContent.none, id, on); if (EditorGUI.showMixedValue) { GUI.Label(rect, SirenixEditorGUI.MixedValueDashChar, SirenixGUIStyles.LabelCentered); } else if (objectToPaint) { Texture image = null; var rt = objectToPaint as RenderTexture; if (rt) { image = rt; } var img = objectToPaint as UnityEngine.UI.Image; if (img) { objectToPaint = img.sprite; } var rawImg = objectToPaint as UnityEngine.UI.RawImage; if (rawImg) { image = rawImg.texture; } if (image == null) { image = GUIHelper.GetAssetThumbnail(objectToPaint, objectToPaint.GetType(), true); } rect = rect.Padding(2); float size = Mathf.Min(rect.width, rect.height); EditorGUI.DrawTextureTransparent(rect.AlignCenter(size, size), image, ScaleMode.ScaleToFit); if (label != null) { rect = rect.AlignBottom(16); GUI.Label(rect, label, EditorStyles.label); } } } }
protected override bool DrawElement(Rect rect, bool value) { if (Event.current.type == EventType.Repaint) { return(EditorGUI.Toggle(rect.AlignCenter(16, 16), value)); } else { return(EditorGUI.Toggle(rect, value)); } }
private void RenderSinglePass(Rect viewportRect, Pass p) { this.drawDevice.VisibilityMask = this.visibilityMask & p.VisibilityMask; this.drawDevice.RenderMode = p.MatrixMode; this.drawDevice.Target = p.Output; this.drawDevice.ViewportRect = p.Output.IsAvailable ? new Rect(p.Output.Res.Width, p.Output.Res.Height) : viewportRect; if (p.Input == null) { // Render Scene this.drawDevice.BeginRendering(p.ClearFlags, p.ClearColor, p.ClearDepth); try { this.CollectDrawcalls(); p.NotifyCollectDrawcalls(this.drawDevice); } catch (Exception e) { Log.Core.WriteError("There was an error while {0} was collecting drawcalls: {1}", this.ToString(), Log.Exception(e)); } this.drawDevice.EndRendering(); } else { Profile.TimePostProcessing.BeginMeasure(); this.drawDevice.BeginRendering(p.ClearFlags, p.ClearColor, p.ClearDepth); Texture mainTex = p.Input.MainTexture.Res; Vector2 uvRatio = mainTex != null ? mainTex.UVRatio : Vector2.One; Vector2 inputSize = mainTex != null ? new Vector2(mainTex.PixelWidth, mainTex.PixelHeight) : Vector2.One; Rect targetRect; if (DualityApp.ExecEnvironment == DualityApp.ExecutionEnvironment.Editor && !this.drawDevice.Target.IsAvailable) { targetRect = Rect.AlignCenter(this.drawDevice.TargetSize.X * 0.5f, this.drawDevice.TargetSize.Y * 0.5f, inputSize.X, inputSize.Y); } else { targetRect = new Rect(this.drawDevice.TargetSize); } IDrawDevice device = this.drawDevice; device.AddVertices(p.Input, VertexMode.Quads, new VertexC1P3T2(targetRect.MinimumX, targetRect.MinimumY, 0.0f, 0.0f, 0.0f), new VertexC1P3T2(targetRect.MaximumX, targetRect.MinimumY, 0.0f, uvRatio.X, 0.0f), new VertexC1P3T2(targetRect.MaximumX, targetRect.MaximumY, 0.0f, uvRatio.X, uvRatio.Y), new VertexC1P3T2(targetRect.MinimumX, targetRect.MaximumY, 0.0f, 0.0f, uvRatio.Y)); this.drawDevice.EndRendering(); Profile.TimePostProcessing.EndMeasure(); } }
[Test] public void Alignment() { Assert.AreEqual(new Rect(-5, -5, 10, 10), Rect.AlignCenter(0, 0, 10, 10)); Assert.AreEqual(new Rect(0, -5, 10, 10), Rect.AlignLeft(0, 0, 10, 10)); Assert.AreEqual(new Rect(-10, -5, 10, 10), Rect.AlignRight(0, 0, 10, 10)); Assert.AreEqual(new Rect(-5, 0, 10, 10), Rect.AlignTop(0, 0, 10, 10)); Assert.AreEqual(new Rect(-5, -10, 10, 10), Rect.AlignBottom(0, 0, 10, 10)); Assert.AreEqual(new Rect(0, 0, 10, 10), Rect.AlignTopLeft(0, 0, 10, 10)); Assert.AreEqual(new Rect(-10, 0, 10, 10), Rect.AlignTopRight(0, 0, 10, 10)); Assert.AreEqual(new Rect(0, -10, 10, 10), Rect.AlignBottomLeft(0, 0, 10, 10)); Assert.AreEqual(new Rect(-10, -10, 10, 10), Rect.AlignBottomRight(0, 0, 10, 10)); }
private void AddScrollCursor() { _cursor = new GameObject("cursor", this.GameObj); Transform t = _cursor.AddComponent <Transform>(); t.RelativePos = new Vector3(Rect.W / 2, Rect.H / 2, 0); t.RelativeAngle = 0; ScrollCursor sc = new ScrollCursor(); sc.VisibilityGroup = this.VisibilityGroup; sc.Skin = CursorSkin; sc.Rect = Rect.AlignCenter(0, 0, CursorSize.X, CursorSize.Y); _cursor.AddComponent <ScrollCursor>(sc); Scene.Current.AddObject(_cursor); }
/// <summary> /// Draws the graphics for a DropZone. /// </summary> public static void DrawDropZone(Rect rect, object value, GUIContent label, int id) { bool isDragging = IsDragging; if (Event.current.type == EventType.Repaint) { var unityObject = value as UnityEngine.Object; var objectFieldThumb = EditorStyles.objectFieldThumb; var on = GUI.enabled && isHoveringAcceptedDropZone && rect.Contains(Event.current.mousePosition) && isDragging; objectFieldThumb.Draw(rect, GUIContent.none, id, on); if (EditorGUI.showMixedValue) { GUI.Label(rect, "—", SirenixGUIStyles.LabelCentered); } else if (unityObject) { if (unityObject is Component) { unityObject = (unityObject as Component).gameObject; } Texture image; image = AssetPreview.GetAssetPreview(unityObject); if (image == null) { image = AssetPreview.GetMiniThumbnail(unityObject); } rect = rect.Padding(2); float size = Mathf.Min(rect.width, rect.height); EditorGUI.DrawTextureTransparent(rect.AlignCenter(size, size), image, ScaleMode.ScaleToFit); if (label != null) { rect = rect.AlignBottom(16); GUI.Label(rect, label, EditorStyles.label); } } } }
private void AddScrollIncreaseButton() { _increaseButton = new GameObject("increaseButton", this.GameObj); Transform t = _increaseButton.AddComponent <Transform>(); t.RelativePos = new Vector3(Rect.W / 2, Rect.H - ButtonsSize.Y / 2, 0); t.RelativeAngle = 0; ScrollIncreaseButton sib = new ScrollIncreaseButton(); sib.VisibilityGroup = this.VisibilityGroup; sib.Skin = IncreaseButtonSkin; sib.Rect = Rect.AlignCenter(0, 0, ButtonsSize.X, ButtonsSize.Y); sib.LeftClickArgument = _scrollSpeed; _increaseButton.AddComponent <ScrollIncreaseButton>(sib); Scene.Current.AddObject(_increaseButton); }
public static bool DropDown(Rect position, GUIContent content, GUIStyle style, float allowWidth, Action buttonAction, Action allowAction) { lastRect = position; lastRect.width = allowWidth; lastRect.x += position.width; lastRect.x -= lastRect.width; if (EditorHelper.HasMouseClick(lastRect)) { allowAction?.Invoke(); Event.current.Use(); } if (GUI.Button(position, content, style)) { buttonAction?.Invoke(); } var rr = lastRect.AlignCenter(12, 12); //rr.y -= 1; GUI.DrawTexture(rr, SharedModule.Icon.icondropdown_, ScaleMode.ScaleToFit); //EditorGUI.DrawRect( lastRect, new Color( 0, 0, 1, 0.5f ) ); return(false); }
private void AddCaret() { _fText.SourceText = "Wq"; _caret = new GameObject("caret", this.GameObj); Transform t = _caret.AddComponent <Transform>(); t.RelativePos = new Vector3(Rect.W / 2, Rect.H / 2, DELTA_Z); t.RelativeAngle = 0; SpriteRenderer sr = new SpriteRenderer(); sr.VisibilityGroup = this.VisibilityGroup; sr.Rect = Rect.AlignCenter(0, 0, 3, _fText.TextMetrics.Size.Y); sr.SharedMaterial = Material.InvertWhite; _caret.AddComponent <SpriteRenderer>(sr); _caret.Active = false; Scene.Current.AddObject(_caret); _fText.SourceText = _text; }
public override bool Convert(ConvertOperation convert) { List <object> results = new List <object>(); List <Material> availData = convert.Perform <Material>().ToList(); // Generate objects foreach (Material mat in availData) { if (convert.IsObjectHandled(mat)) { continue; } DrawTechnique tech = mat.Technique.Res; LightingTechnique lightTech = tech as LightingTechnique; if (tech == null) { continue; } bool isDynamicLighting = lightTech != null || tech.PreferredVertexFormat == VertexC1P3T2A4.VertexTypeIndex || tech.PreferredVertexFormat == VertexC1P3T4A4A1.VertexTypeIndex; if (!isDynamicLighting) { continue; } Texture mainTex = mat.MainTexture.Res; GameObject gameobj = convert.Result.OfType <GameObject>().FirstOrDefault(); if (mainTex == null || mainTex.AnimFrames == 0) { LightingSpriteRenderer sprite = convert.Result.OfType <LightingSpriteRenderer>().FirstOrDefault(); if (sprite == null && gameobj != null) { sprite = gameobj.GetComponent <LightingSpriteRenderer>(); } if (sprite == null) { sprite = new LightingSpriteRenderer(); } sprite.SharedMaterial = mat; if (mainTex != null) { sprite.Rect = Rect.AlignCenter(0.0f, 0.0f, mainTex.PixelWidth, mainTex.PixelHeight); } convert.SuggestResultName(sprite, mat.Name); results.Add(sprite); } else { LightingAnimSpriteRenderer sprite = convert.Result.OfType <LightingAnimSpriteRenderer>().FirstOrDefault(); if (sprite == null && gameobj != null) { sprite = gameobj.GetComponent <LightingAnimSpriteRenderer>(); } if (sprite == null) { sprite = new LightingAnimSpriteRenderer(); } sprite.SharedMaterial = mat; sprite.Rect = Rect.AlignCenter(0.0f, 0.0f, mainTex.PixelWidth / mainTex.AnimCols, mainTex.PixelHeight / mainTex.AnimRows); sprite.AnimDuration = 5.0f; sprite.AnimFrameCount = mainTex.AnimFrames; convert.SuggestResultName(sprite, mat.Name); results.Add(sprite); } convert.MarkObjectHandled(mat); } convert.AddResult(results); return(false); }
/// <summary> /// Draws the graphics for a DropZone. /// </summary> public static void DrawDropZone(Rect rect, object value, GUIContent label, int id) { bool isDragging = IsDragging; if (Event.current.type == EventType.Repaint) { var objectToPaint = value as UnityEngine.Object; var objectFieldThumb = EditorStyles.objectFieldThumb; var on = GUI.enabled && hoveringAcceptedDropZone == id && rect.Contains(Event.current.mousePosition) && isDragging; objectFieldThumb.Draw(rect, GUIContent.none, id, on); if (EditorGUI.showMixedValue) { GUI.Label(rect, SirenixEditorGUI.MixedValueDashChar, SirenixGUIStyles.LabelCentered); } else if (objectToPaint) { Texture image = null; var rt = objectToPaint as RenderTexture; if (rt) { image = rt; } // Weakly typed, check if it's a UnityEngine.UI.Image instance and paint its sprite, if so. // This is weakly typed because we can no longer safely reference the UnityEngine.UI assembly. { if (Type_UnityEngine_UI_Image != null && Property_UnityEngine_UI_Image_Sprite != null && Type_UnityEngine_UI_Image.IsAssignableFrom(objectToPaint.GetType())) { objectToPaint = (UnityEngine.Object)Property_UnityEngine_UI_Image_Sprite.GetValue(objectToPaint, null); } // This was the old code for the above section: //var img = objectToPaint as UnityEngine.UI.Image; //if (img) //{ // objectToPaint = img.sprite; //} } // Weakly typed, check if it's a UnityEngine.UI.RawImage instance and paint its texture, if so. // This is weakly typed because we can no longer safely reference the UnityEngine.UI assembly. { if (Type_UnityEngine_UI_RawImage != null && Property_UnityEngine_UI_RawImage_Texture != null && Type_UnityEngine_UI_RawImage.IsAssignableFrom(objectToPaint.GetType())) { image = (Texture)Property_UnityEngine_UI_RawImage_Texture.GetValue(objectToPaint, null); } // This was the old code for the above section: //var rawImg = objectToPaint as UnityEngine.UI.RawImage; //if (rawImg) //{ // image = rawImg.texture; //} } if (image == null) { image = GUIHelper.GetAssetThumbnail(objectToPaint, objectToPaint.GetType(), true); } rect = rect.Padding(2); float size = Mathf.Min(rect.width, rect.height); EditorGUI.DrawTextureTransparent(rect.AlignCenter(size, size), image, ScaleMode.ScaleToFit); if (label != null) { rect = rect.AlignBottom(16); GUI.Label(rect, label, EditorStyles.label); } } } }
public override void DrawMenuItem(int indentLevel) { base.DrawMenuItem(indentLevel); if (!this.MenuItemIsBeingRendered || Event.current.type != EventType.Repaint) { return; } var totalRect = this.Rect; int columnIndex = 0; float currentX = totalRect.xMin; for (int i = 0; i < AllDisplayOptions.Length; i++) { var option = AllDisplayOptions[i]; if ((this.DisplayOptions & option) == option) { var width = this.Columns[columnIndex].ColWidth; var rect = new Rect(currentX, totalRect.yMin, width, totalRect.height); if (option == DisplayOptions.Category) { rect = rect.AlignCenter(16, 16); switch (this.ValidationResult.ResultType) { case ValidationResultType.Valid: GUIHelper.PushColor(Color.green); GUI.DrawTexture(rect, EditorIcons.Checkmark.Highlighted, ScaleMode.ScaleToFit); GUIHelper.PopColor(); break; case ValidationResultType.Error: GUI.DrawTexture(rect, EditorIcons.UnityErrorIcon, ScaleMode.ScaleToFit); break; case ValidationResultType.Warning: GUI.DrawTexture(rect, EditorIcons.UnityWarningIcon, ScaleMode.ScaleToFit); break; default: break; } } else { rect.y = this.LabelRect.y; rect.yMax = this.LabelRect.yMax; rect.x += 5; rect.width -= 10; var labelStyle = this.IsSelected ? this.Style.SelectedLabelStyle : this.Style.DefaultLabelStyle; GUI.Label(rect, GUIHelper.TempContent(this.GetDisplayString(option)), labelStyle); } currentX += width; columnIndex++; } } }
protected override void DrawPropertyLayout(GUIContent label) { // Save menuTreeWidth. this.menuTreeWidth.Value = this.columns[0].ColWidth; // Bottom Slide Toggle Bits: var overviewSlideRect = new Rect(); var toggleOverviewBtnRect = new Rect(); Rect topRect; GUILayout.BeginHorizontal(GUILayoutOptions.ExpandHeight()); { topRect = GUIHelper.GetCurrentLayoutRect(); GUITableUtilities.ResizeColumns(topRect, this.columns); // Bottom Slide Toggle Bits: // The bottom slide-rect toggle needs to be drawn above, but is placed below. overviewSlideRect = topRect.AlignBottom(4).AddY(4); overviewSlideRect.width += 4; toggleOverviewBtnRect = overviewSlideRect.AlignCenter(100).AlignBottom(14); EditorGUIUtility.AddCursorRect(toggleOverviewBtnRect, MouseCursor.Arrow); if (SirenixEditorGUI.IconButton(toggleOverviewBtnRect.AddY(-2), this.overviewToggle.Value ? EditorIcons.TriangleDown : EditorIcons.TriangleUp)) { this.overviewToggle.Value = !this.overviewToggle.Value; } if (this.overviewToggle.Value) { this.overviewHeight -= SirenixEditorGUI.SlideRect(overviewSlideRect.SetXMax(toggleOverviewBtnRect.xMin), MouseCursor.SplitResizeUpDown).y; this.overviewHeight -= SirenixEditorGUI.SlideRect(overviewSlideRect.SetXMin(toggleOverviewBtnRect.xMax), MouseCursor.SplitResizeUpDown).y; } // Left menu tree GUILayout.BeginVertical(GUILayoutOptions.Width(this.columns[0].ColWidth).ExpandHeight()); { EditorGUI.DrawRect(GUIHelper.GetCurrentLayoutRect(), SirenixGUIStyles.EditorWindowBackgroundColor); this.validationProfileTree.Draw(); } GUILayout.EndVertical(); // Draw selected GUILayout.BeginVertical(); { this.DrawTopBarButtons(); this.DrawSelectedTests(); } GUILayout.EndVertical(); GUITableUtilities.DrawColumnHeaderSeperators(topRect, this.columns, SirenixGUIStyles.BorderColor); } GUILayout.EndHorizontal(); // Bottom Slide Toggle Bits: if (this.overviewToggle.Value) { GUILayoutUtility.GetRect(0, 4); // Slide Area. } EditorGUI.DrawRect(overviewSlideRect, SirenixGUIStyles.BorderColor); EditorGUI.DrawRect(toggleOverviewBtnRect.AddY(-overviewSlideRect.height), SirenixGUIStyles.BorderColor); SirenixEditorGUI.IconButton(toggleOverviewBtnRect.AddY(-2), this.overviewToggle.Value ? EditorIcons.TriangleDown : EditorIcons.TriangleUp); // Overview if (this.overviewToggle.Value) { GUILayout.BeginVertical(GUILayout.Height(this.overviewHeight)); { this.overview.DrawOverview(); } GUILayout.EndVertical(); if (Event.current.type == EventType.Repaint) { this.overviewHeight = Mathf.Max(50, this.overviewHeight); var height = GUIHelper.CurrentWindow.position.height - overviewSlideRect.yMax; this.overviewHeight = Mathf.Min(this.overviewHeight, height); } } }
private void Game(GameContext game) { Rect rect = EditorGUILayout.GetControlRect(true, TileSize * BoardSize + 20); rect = rect.AlignCenter(TileSize * BoardSize); // Toolbar { SirenixEditorGUI.DrawSolidRect(rect.AlignTop(20), new Color(0.5f, 0.5f, 0.5f, 1f)); SirenixEditorGUI.DrawBorders(rect.AlignTop(20).SetHeight(21).SetWidth(rect.width + 1), 1); if (Event.current.type == EventType.Repaint && !game.GameOver) { double t = EditorApplication.timeSinceStartup; game.Time += t - game.PrevTime; game.PrevTime = t; } var time = GUIHelper.TempContent(((int)game.Time).ToString()); GUIHelper.PushContentColor(Color.black); GUI.Label(rect.AlignTop(20).HorizontalPadding(4).AlignMiddle(18).AlignRight(EditorStyles.label.CalcSize(time).x), time); GUIHelper.PopContentColor(); GUI.Label(rect.AlignTop(20).AlignCenter(20), EditorIcons.PacmanGhost.ActiveGUIContent); if (game.GameOver) { GUIHelper.PushContentColor(game.FlaggedBombs == game.NumberOfBombs ? Color.green : Color.red); GUI.Label(rect.AlignTop(20).HorizontalPadding(4).AlignMiddle(18), game.FlaggedBombs == game.NumberOfBombs ? "You win!" : "Game over!"); GUIHelper.PopContentColor(); } } rect = rect.AlignBottom(rect.height - 20); SirenixEditorGUI.DrawSolidRect(rect, new Color(0.7f, 0.7f, 0.7f, 1f)); for (int i = 0; i < BoardSize * BoardSize; i++) { Rect tileRect = rect.SplitGrid(TileSize, TileSize, i); SirenixEditorGUI.DrawBorders(tileRect.SetWidth(tileRect.width + 1).SetHeight(tileRect.height + 1), 1); int x = i % BoardSize; int y = i / BoardSize; var tile = game.Tiles[x, y]; var visible = game.VisibleTiles[x, y]; if (game.GameOver || visible == Tile.Open) { SirenixEditorGUI.DrawSolidRect(new Rect(tileRect.x + 1, tileRect.y + 1, tileRect.width - 1, tileRect.height - 1), new Color(0.3f, 0.3f, 0.3f, 1f)); } if ((game.GameOver || visible == Tile.Open) && tile == Tile.Bomb) { GUIHelper.PushColor(visible == Tile.Flag ? Color.black : Color.white); GUI.Label(tileRect.AlignCenter(18).AlignMiddle(18), EditorIcons.SettingsCog.ActiveGUIContent); GUIHelper.PopColor(); } if (visible == Tile.Flag) { GUIHelper.PushColor(Color.red); GUI.Label(tileRect.AlignCenter(18).AlignMiddle(18), EditorIcons.Flag.ActiveGUIContent); GUIHelper.PopColor(); } if ((game.GameOver || visible == Tile.Open) && (int)tile >= 1 && (int)tile <= 8) { GUIHelper.PushColor(this.NumberColors[(int)tile - 1]); GUI.Label(tileRect.AlignCenter(18).AlignCenter(18).AddX(2).AddY(2), ((int)tile).ToString(), EditorStyles.boldLabel); GUIHelper.PopColor(); } if (!game.GameOver && tileRect.Contains(Event.current.mousePosition)) { SirenixEditorGUI.DrawSolidRect(new Rect(tileRect.x + 1, tileRect.y + 1, tileRect.width - 1, tileRect.height - 1), new Color(0f, 1f, 0f, 0.3f)); // Input // Reveal if (Event.current.type == EventType.MouseDown && Event.current.button == 0) { if (visible != Tile.Flag) { if (tile == Tile.Bomb) { // LOSE game.GameOver = true; SirenixEditorGUI.StartShakingGroup(game.Key, 3f); } else { this.Reveal(game, x, y); } } Event.current.Use(); } // Place flag else if (Event.current.type == EventType.MouseDown && Event.current.button == 1) { if (visible == Tile.None) { game.VisibleTiles[x, y] = Tile.Flag; if (tile == Tile.Bomb) { game.FlaggedBombs++; if (game.FlaggedBombs == game.NumberOfBombs) { game.GameOver = true; } } } else if (visible == Tile.Flag) { game.VisibleTiles[x, y] = Tile.None; if (tile == Tile.Bomb) { game.FlaggedBombs--; } } Event.current.Use(); } } } GUIHelper.RequestRepaint(); }