public static VectorT WorldToGrid(Vector3 wPos) { VectorT gPos = new VectorT(); /// ( gp.x * 2 ) + ( gp.y * -2 ) = x /// gp.x + gp.y = y // // / gp.x * 2 = x - (gp.y * -2 ) // // / gp.x = ( x - (gp.y * -2 )) / 2 /// gp.y = y - gp.x /// substitute!!! /// ( gp.x * 2 ) + ( (y - gp.x) * -2 ) = x /// gp.x + ( (y - gp.x) * -2 ) / 2 = x / 2 /// gp.x - (y - gp.x) = x / 2 /// (gp.x * 2) - y = x / 2 /// gp.x * 2 = (x / 2) + y /// gp.x = ((x / 2) + y ) / 2 gPos.x = (int)Mathf.Round(((wPos.x / 2) + wPos.y) / 2); gPos.y = (int)Mathf.Round(wPos.y - gPos.x); return(gPos); }
public void SetPosition(VectorT vt) { gPosition = vt; this.transform.localPosition = vt.ToWorld(); sr.sortingOrder = (int)Mathf.Round(-this.transform.localPosition.y + gPosition.z); }
public bool isEqualTo(VectorT t) { if (this.x == t.x && this.y == t.y && this.z == t.z) { return(true); } else { return(false); } }
public static Vector3 GridToWorld(VectorT gridPos) { Vector3 wPos = new Vector3(); /// ( gp.x * 2 ) + ( gp.y * -2 ) = x /// gp.x + gp.y = y Vector2 xp = gridPos.x * new Vector2(2, 1); Vector2 yp = gridPos.y * new Vector2(-2, 1); wPos = xp + yp; wPos.y += gridPos.z; wPos.z = gridPos.z * -0.001f; return(wPos); }
void OnSceneGUI() { Event e = Event.current; if (e.type == EventType.KeyDown) { if (e.keyCode == KeyCode.G) { editing = true; Tools.current = Tool.None; } } if (Tools.current != Tool.None) { editing = false; } if (editing == false) { return; } HandleUtility.AddDefaultControl(GUIUtility.GetControlID(FocusType.Passive)); switch (e.type) { // case EventType. case EventType.MouseDrag: if (e.button == 0) { targetTile = (Tile)target; VectorT newPos = VectorT.WorldToGrid(SceneViewToWorld(e.mousePosition)); newPos.z = targetTile.gPosition.z; targetTile.SetPosition(newPos); } break; } }
// void SnapToGrid(){ // float yPos = Mathf.Round( this.transform.localPosition.y - gPosition.z ); // float xPos = Mathf.Round( this.transform.localPosition.x /4 ) * 4; // if( yPos % 2 == 0 ){ // /// Evens // if( xPos % 2 != 0 ){ // if( this.transform.localPosition.x > xPos ){ // xPos += 1; // } else { // xPos -= 1; // } // } // } else { // /// Odds // if( xPos % 2 == 0 ){ // if( this.transform.localPosition.x > xPos ){ // xPos += 2; // } else { // xPos -= 2; // } // } // } // // this.transform.localPosition = new Vector3( xPos, yPos + gPosition.z, this.transform.localPosition.z ); // this.transform.localPosition = new Vector3( xPos, yPos + gPosition.z, gPosition.z * -0.001f ); // VectorT gp = VectorT.WorldToGrid( this.transform.localPosition ); // gPosition.x = gp.x; // gPosition.y = gp.y; // sr.sortingOrder = (int)Mathf.Round( -this.transform.localPosition.y + gPosition.z ); // } void OnDrawGizmos() { if (!Selection.Contains(this.gameObject) || TileEditor.editing == false) { return; } // if( !( Selection.Contains(this.gameObject) && Tools.current == Tool.Move ) ){ // return; // } Gizmos.color = new Color(0.2f, 0.5f, 1, 0.15f); int drawRange = 2; VectorT basePos = gPosition; basePos.z = 0; for (int u = -drawRange * 2; u < drawRange * 2; u++) { for (int v = -drawRange * 2; v < drawRange * 2; v++) { Gizmos.DrawLine(new VectorT(u + basePos.x, v + basePos.y).ToWorld(), new VectorT(u + basePos.x, -v + basePos.y).ToWorld()); Gizmos.DrawLine(new VectorT(u + basePos.x, v + basePos.y).ToWorld(), new VectorT(-u + basePos.x, v + basePos.y).ToWorld()); } } // // Gizmos.Draw Handles.color = Handles.xAxisColor; Handles.ArrowHandleCap(0, basePos.ToWorld(), Quaternion.Euler(27, 90, 0), 2, EventType.Repaint); Handles.color = Handles.yAxisColor; Handles.ArrowHandleCap(0, basePos.ToWorld(), Quaternion.Euler(27, -90, 0), 2, EventType.Repaint); Handles.color = Handles.zAxisColor; Handles.ArrowHandleCap(0, basePos.ToWorld(), Quaternion.Euler(-90, 0, 0), 2, EventType.Repaint); }
public async Task SendBallPosition(VectorT pos) { await Clients.Others.SendAsync(ServerClient.ReceiveBallPosition, pos); }
public void OnSceneGUI(SceneView sceneView) { if (Tools.current != Tool.None && addTiles == true) { addTiles = false; SceneView.onSceneGUIDelegate -= OnSceneGUI; } HandleUtility.AddDefaultControl(GUIUtility.GetControlID(FocusType.Passive)); Event e = Event.current; switch (e.type) { case EventType.MouseDown: if (e.button != 0) { break; } selectionStart = VectorT.WorldToGrid(SceneViewToWorld(e.mousePosition)); selectionSet = true; selectionEnd = selectionStart; break; case EventType.MouseDrag: if (e.button != 0) { break; } selectionEnd = VectorT.WorldToGrid(SceneViewToWorld(e.mousePosition)); break; case EventType.MouseUp: if (e.button != 0) { break; } if (selectionSet == true) { selectionEnd = VectorT.WorldToGrid(SceneViewToWorld(e.mousePosition)); AddTiles(); selectionSet = false; } break; } if (selectionSet == false) { return; } Vector3[] verts = new Vector3[4]; verts[0] = selectionStart.ToWorld(); verts[1] = new VectorT(selectionStart.x, selectionEnd.y).ToWorld(); verts[2] = selectionEnd.ToWorld(); verts[3] = new VectorT(selectionEnd.x, selectionStart.y).ToWorld(); Handles.DrawSolidRectangleWithOutline(verts, new Color(0, 0.25f, 1, 0.25f), new Color(0, 0, 0.25f, 0.5f)); HandleUtility.Repaint(); }