public static Vector2 GetHandlePosition(this Rectangle r, BoxHandle handle) { Vector2 res = Vector2.Zero; switch (handle) { default: case BoxHandle.TOPLEFT: res = new Vector2( (int)r.X, (int)r.Y ); break; case BoxHandle.TOPRIGHT: res = new Vector2( (int)r.X + r.Width, (int)r.Y ); break; case BoxHandle.BOTTOMLEFT: res = new Vector2( (int)r.X, (int)r.Y + r.Height ); break; case BoxHandle.BOTTOMRIGHT: res = new Vector2( (int)r.X + r.Width, (int)r.Y + r.Height ); break; case BoxHandle.CENTER: res = new Vector2( (int)(r.X + (r.Width / 2)), (int)(r.Y + (r.Height / 2)) ); break; } return(res); }
private void ReCreateVisual() { string rootName = "BoxRoot"; Transform existRoot = boundingBox.BoundingBoxContainer.Find(rootName); if (existRoot != null) { GameObject.Destroy(existRoot.gameObject); } this.boxHandle = new BoxHandle(); this.boxHandle.root = GameObject.CreatePrimitive(boundingBox.FlattenAxis != BoundingBox.FlattenModeType.DoNotFlatten ? PrimitiveType.Quad : PrimitiveType.Cube).transform; GameObject.Destroy(this.boxHandle.root.GetComponent <Collider>()); this.boxHandle.root.name = "BoxRoot"; this.boxHandle.root.localScale = boundingBox.CurrentBoundsExtents * 2f; this.boxHandle.root.parent = boundingBox.BoundingBoxContainer.transform; this.boxHandle.root.localPosition = Vector3.zero; this.boxHandle.root.localRotation = Quaternion.identity; }
public static Rectangle CopyAtPosition(this Rectangle r, Vector2 position, BoxHandle handle = BoxHandle.TOPLEFT) { int x = 0; int y = 0; switch (handle) { default: case BoxHandle.TOPLEFT: x = (int)position.X; y = (int)position.Y; break; case BoxHandle.TOPRIGHT: x = (int)(position.X - r.Width); y = (int)position.Y; break; case BoxHandle.BOTTOMLEFT: x = (int)(position.X); y = (int)(position.Y - r.Height); break; case BoxHandle.BOTTOMRIGHT: x = (int)(position.X - r.Width); y = (int)(position.Y - r.Height); break; case BoxHandle.CENTER: x = (int)(position.X) - (r.Width / 2); y = (int)(position.Y) - (r.Height / 2); break; } r = new Rectangle(x, y, r.Width, r.Height); return(r); }
public static Rectangle CopyAtPosition(this Rectangle r, int x, int y, BoxHandle handle = BoxHandle.TOPLEFT) => r.CopyAtPosition(new Vector2(x, y), handle);
public override void Attach(BoxHandle newOutput) { output = newOutput as BoxHandleOutput; }
public override void Attach(BoxHandle newInput) { input = newInput as BoxHandleInput; }