public static Rect GetSquareOnGUICoordinate(RectPosition position, float edgeLength, Vector2 offset) { Rect rect; switch (position) { case RectPosition.BottomLeft: rect = new Rect(0 + offset.x, Screen.height - offset.y - edgeLength, edgeLength, edgeLength); //Left bottom button break; case RectPosition.BottomRight: rect = new Rect(Screen.width + offset.x - edgeLength, Screen.height + offset.y - edgeLength, edgeLength, edgeLength); break; case RectPosition.TopLeft: rect = new Rect(0 + offset.x, 0 + offset.y, edgeLength, edgeLength); break; case RectPosition.TopRight: rect = new Rect(Screen.width + offset.x - edgeLength, 0 + offset.y, edgeLength, edgeLength); break; case RectPosition.Center: default: rect = new Rect(Screen.width / 2 - edgeLength / 2 + offset.x, Screen.height / 2 - edgeLength / 2 + offset.y, edgeLength, edgeLength); break; } return(rect); }
private Rect GetNextRect(int line, float startPosition, RectPosition rectPosition, float width, int height = 0) { var rect = new Rect(); rect.y = 5f + line * 18f + line * 5f; rect.height = height == 0f ? 18f : height; switch (rectPosition) { case RectPosition.Start: rect.x = _margin; rect.width = position.width * width - _margin * 1.5f; break; case RectPosition.End: rect.x = position.width * startPosition + _margin * 0.5f; rect.width = position.width - (position.width * startPosition) - _margin * 1.5f; break; case RectPosition.Image: rect.height = position.height - rect.y - _margin; rect.x = _margin; rect.width = position.width - _margin * 2f; break; case RectPosition.Full: rect.x = _margin; rect.width = position.width - _margin * 2f; break; } return(rect); }
//<summary> перезагружаем метод OnGUI, в котором мы верстаем поле редактора </summary> public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { //EditorGUI.BeginProperty(position, GUIContent.none, property); if (_objs == null) { var target = property.serializedObject.targetObject; _objs = fieldInfo.GetValue(target) as BaseChildClassesSerializable <BaseClass>; if (_objs == null) { _objs = new BaseChildClassesSerializable <BaseClass>(); fieldInfo.SetValue(target, _objs); } } _position = new RectPosition(position, 22); GUIContent l = new GUIContent(label.text + " (" + _objs.Count.ToString() + ")"); EditorGUI.LabelField(this._position + 0, l, EditorStyles.centeredGreyMiniLabel); _indexClass = EditorGUI.Popup(this._position, "", _indexClass, _objs.GetSubclassTypes.Select(t => t.ToString()).ToArray()); if (GUI.Button(this._position, new GUIContent("Добавить"))) { AddItem(_indexClass); } if (GUI.Button(this._position, new GUIContent("Очистить"))) { ClearItems(); } //EditorGUI.EndProperty(); //EditorGUI.LabelField(this._position, ""); foreach (BaseClass obj in _objs) { ShowItems(obj); } }
public override void Update(GameTime gameTime) { int moveBy = random.Next(3, 10); if (Direction == Direction.LeftToRight) { RectPosition.X += moveBy; } else { RectPosition.X -= moveBy; } if (RectPosition.Intersects(RectStart)) { Direction = Direction.LeftToRight; } else if (RectPosition.Intersects(RectEnd)) { Direction = Direction.RightToLeft; } }
public static Rect GetSquareOnGUICoordinate(RectPosition position, float edgeLength, Vector2 offset) { Rect rect; switch (position) { case RectPosition.BottomLeft: rect = new Rect(0 + offset.x, Screen.height - offset.y - edgeLength, edgeLength, edgeLength); //Left bottom button break; case RectPosition.BottomRight: rect = new Rect(Screen.width + offset.x - edgeLength, Screen.height + offset.y - edgeLength, edgeLength, edgeLength); break; case RectPosition.TopLeft: rect = new Rect(0 + offset.x, 0 + offset.y, edgeLength, edgeLength); break; case RectPosition.TopRight: rect = new Rect(Screen.width + offset.x - edgeLength, 0 + offset.y, edgeLength, edgeLength); break; case RectPosition.Center: default: rect = new Rect(Screen.width / 2 - edgeLength / 2 + offset.x, Screen.height / 2 - edgeLength / 2 + offset.y, edgeLength, edgeLength); break; } return rect; }
public override void Update(GameTime gameTime) { if (RectEnd != new Rectangle(1, 1, 1, 1)) { int moveBy = 1; if (Direction == Direction.LeftToRight) { RectPosition.X += moveBy; } else { RectPosition.X -= moveBy; } if (RectPosition.Intersects(RectStart)) { Direction = Direction.LeftToRight; } else if (RectPosition.Intersects(RectEnd)) { Direction = Direction.RightToLeft; } } elapsed += (float)gameTime.ElapsedGameTime.TotalSeconds; for (int i = 0; i < Bullets.Length; i++) { Bullets[i].Update(gameTime); } if (isActive) { Fire(); } }
public static void MoveMouseInsideHwnd(int hwnd, int xPos, int yPos, RectPosition rctPos) { int xPixel = xPos; //10; int yPixel = yPos; //10; if (!rctPos.Equals(RectPosition.AnySpot)) { xPixel = 4; yPixel = 4; } CenterMouseOn(hwnd); int width = 0; int height = 0; POINTAPI pa = new POINTAPI(); GetWindowSize(hwnd, ref width, ref height); GetCursorPos(ref pa); switch (rctPos) { case RectPosition.LeftTop: xPixel = (pa.x - width / 2) + xPixel % width; yPixel = (pa.y - height / 2) + yPixel % height; break; case RectPosition.LeftBottom: xPixel = (pa.x - width / 2) + xPixel % width; yPixel = (pa.y + height / 2) - yPixel % height; break; case RectPosition.RightTop: xPixel = (pa.x + width / 2) - xPixel % width; yPixel = (pa.y - height / 2) + yPixel % height; break; case RectPosition.RightBottom: xPixel = (pa.x + width / 2) - xPixel % width; yPixel = (pa.y + height / 2) - yPixel % height; break; case RectPosition.MiddleTop: xPixel = (pa.x); yPixel = (pa.y - height / 2) + yPixel % height; break; case RectPosition.MiddleBottom: xPixel = (pa.x); yPixel = (pa.y + height / 2) - yPixel % height; break; case RectPosition.AnySpot: xPixel = (pa.x - width / 2) + xPixel % width; yPixel = (pa.y - height / 2) + yPixel % height; break; } //if (rC>0) //{ MoveMouse(hwnd, xPixel, yPixel); //} }
/// <summary> /// Default offset = 10 /// </summary> /// <param name="position"></param> /// <param name="edgeLength"></param> /// <returns></returns> public static Rect GetSquareOnGUICoordinate(RectPosition position, float edgeLength) { float offset = 10f; return GetSquareOnGUICoordinate(position, edgeLength, offset); }
public static Rect GetSquareOnGUICoordinate(RectPosition position, float edgeLength, float offset) { return GetSquareOnGUICoordinate(position, edgeLength, new Vector2(offset, offset)); }
protected override void OnUpdateFrame(FrameEventArgs e) { if (Alive) { Score += (float)e.Time; ScoreText.Text = "Score: " + ((int)Score).ToString(); if (Jump) { acel += 0.025f; } if (Jump == false && Player.transform.position.Y >= 540) { OnFloor = true; acel = 0; } if (Jump == true && Player.transform.position.Y > 540 - JumpHeight) { Player.transform.position.Y -= 10; } if (Jump == true && Player.transform.position.Y <= 540 - JumpHeight) { Jump = false; } if (Jump == false && OnFloor == false) { Player.transform.position.Y += 4 + acel; } for (int i = 0; i < Floor.Count; i++) { var f = Floor[i]; f.position.X -= velocidade; if (f.position.X <= -50) { f.position.X = 19 * 50; } Floor[i] = f; } distLast += velocidade; if (distLast > 250) { distLast = 0; int n = new Random().Next() % 100; if (n < 15) { Cactos.Add(new RectPosition(new Vector2(850, 540), new Vector2(50, 50))); } else if (n < 20) { Cactos.Add(new RectPosition(new Vector2(850, 540), new Vector2(50, 50))); Cactos.Add(new RectPosition(new Vector2(900, 540), new Vector2(50, 50))); distLast -= 50; } else if (n < 23) { Cactos.Add(new RectPosition(new Vector2(850, 540), new Vector2(50, 50))); Cactos.Add(new RectPosition(new Vector2(900, 540), new Vector2(50, 50))); Cactos.Add(new RectPosition(new Vector2(950, 540), new Vector2(50, 50))); distLast -= 75; } } for (int i = 0; i < Cactos.Count; i++) { var f = Cactos[i]; f.position.X -= velocidade; if (f.position.X <= -50) { Cactos.Remove(f); } else { Cactos[i] = f; } } foreach (var c in Cactos) { if (RectPosition.Hit(Player.transform, c)) { HowPlay.Text = "Press any button to restart!\n You Loose!"; Alive = false; HowPlayPos.Y = 300; HowPlayPos.X = 400 - HowPlay.MeasureSize().X / 2; } } } }
public static Rect GetSquareOnGUICoordinate(RectPosition position, float edgeLength, float offset) { return(GetSquareOnGUICoordinate(position, edgeLength, new Vector2(offset, offset))); }
/// <summary> /// Default offset = 10 /// </summary> /// <param name="position"></param> /// <param name="edgeLength"></param> /// <returns></returns> public static Rect GetSquareOnGUICoordinate(RectPosition position, float edgeLength) { float offset = 10f; return(GetSquareOnGUICoordinate(position, edgeLength, offset)); }
public static int GetXInDiv(this MouseEventArgs e, RectPosition div) { return((int)e.ClientX - div.Left); }
public static int GetYInDiv(this MouseEventArgs e, RectPosition div) { return((int)e.ClientY - div.Top); }