private void RefershSelection() { foreach (GridPosition pos in ((PointReachedCondition)target).Positions) { GameTile tile = EditorTools.CurrentInspectedGrid.GetTile(pos); if (tile) { ObjectHilighter.Add(tile.GetComponent <SpriteRenderer>(), this); } } }
void OnSceneGUI() { // get the chosen game object GameTile t = target as GameTile; if (t == null) { return; } // grab the center of the parent Vector3 center = GameGrid.BlockDirections.UP + t.transform.position + GameGrid.BlockDirections.SW - verticalOffset; Handles.DrawLine(center + Vector3.zero, center + GameGrid.BlockDirections.SE); Handles.DrawLine(center + Vector3.zero, center + GameGrid.BlockDirections.NE); Handles.DrawLine(center + GameGrid.BlockDirections.SE, center + GameGrid.BlockDirections.SE + GameGrid.BlockDirections.NE); Handles.DrawLine(center + GameGrid.BlockDirections.NE, center + GameGrid.BlockDirections.NE + GameGrid.BlockDirections.SE); ObjectHilighter.Add(t.GetComponent <SpriteRenderer>(), this); /* * center += GameGrid.BlockDirections.Down; * * Handles.DrawLine(center + Vector3.zero, center + GameGrid.BlockDirections.SE); * Handles.DrawLine(center + Vector3.zero, center + GameGrid.BlockDirections.NE); * * Handles.DrawLine(center + GameGrid.BlockDirections.SE, center + GameGrid.BlockDirections.SE + GameGrid.BlockDirections.NE); * Handles.DrawLine(center + GameGrid.BlockDirections.NE, center + GameGrid.BlockDirections.NE + GameGrid.BlockDirections.SE); * * Handles.DrawLine(center, center + GameGrid.BlockDirections.UP); * Handles.DrawLine(center + GameGrid.BlockDirections.SE, center + GameGrid.BlockDirections.SE+GameGrid.BlockDirections.UP); * * Handles.DrawLine(center + GameGrid.BlockDirections.SE + GameGrid.BlockDirections.NE, center + GameGrid.BlockDirections.SE + GameGrid.BlockDirections.NE + GameGrid.BlockDirections.UP); * // Handles.DrawLine(center + GameGrid.BlockDirections.NE, center + GameGrid.BlockDirections.NE+GameGrid.BlockDirections.UP); */ Color orgColor = Handles.color; orgColor = Handles.color; Handles.color = Color.red; Handles.color = orgColor; center = GameGrid.BlockDirections.UP + t.transform.position + GameGrid.BlockDirections.SW + GameGrid.BlockDirections.SE / 2 - verticalOffset + GameGrid.BlockDirections.NE / 2; //Handles.DrawLine(center + Vector3.zero, center + GameGrid.BlockDirections.SE); }
void OnSceneGUI(SceneView sceneView) { if (EditorTools.CurrentInspectedGrid == null) { return; } Mission selectedMission = target as Mission; int i = 0; for (i = 0; i < selectedMission.Teams.Count; i++) { for (int q = 0; q < selectedMission.Teams[i].Members.Count; q++) { Vector3 position = EditorTools.CurrentInspectedGrid.CenterPointOnGrid(selectedMission.Teams[i].Members[q].SpawnPositon); Handles.DrawLine(position, position + Vector3.up); GameGrid.BlockDirections.FaceDirections facedir = selectedMission.Teams[i].Members[q].SpawnDirection; Handles.DrawSolidRectangleWithOutline(CreateArrow(facedir, position), teamColors[i], Color.red); // grab the center of the parent Vector3 center = position + GameGrid.BlockDirections.NW / 2 + GameGrid.BlockDirections.SW / 2; Handles.DrawLine(center + Vector3.zero, center + GameGrid.BlockDirections.SE); Handles.DrawLine(center + Vector3.zero, center + GameGrid.BlockDirections.NE); Handles.DrawLine(center + GameGrid.BlockDirections.SE, center + GameGrid.BlockDirections.SE + GameGrid.BlockDirections.NE); Handles.DrawLine(center + GameGrid.BlockDirections.NE, center + GameGrid.BlockDirections.NE + GameGrid.BlockDirections.SE); center += GameGrid.BlockDirections.Down; /* * Handles.DrawLine(center + Vector3.zero, center + GameGrid.BlockDirections.SE); * Handles.DrawLine(center + Vector3.zero, center + GameGrid.BlockDirections.NE); * * Handles.DrawLine(center + GameGrid.BlockDirections.SE, center + GameGrid.BlockDirections.SE + GameGrid.BlockDirections.NE); * Handles.DrawLine(center + GameGrid.BlockDirections.NE, center + GameGrid.BlockDirections.NE + GameGrid.BlockDirections.SE); * * Handles.DrawLine(center, center + GameGrid.BlockDirections.UP); * Handles.DrawLine(center + GameGrid.BlockDirections.SE, center + GameGrid.BlockDirections.SE + GameGrid.BlockDirections.UP); * * Handles.DrawLine(center + GameGrid.BlockDirections.SE + GameGrid.BlockDirections.NE, center + GameGrid.BlockDirections.SE + GameGrid.BlockDirections.NE + GameGrid.BlockDirections.UP); * */ if (selectedMission.Teams.Count < selectedCharacterIndex[0] || selectedMission.Teams[selectedCharacterIndex[0]].members.Count < selectedCharacterIndex[1]) { selectedCharacterIndex[0] = 0; selectedCharacterIndex[1] = 0; characterSelected = false; } center = selectedMission.Teams[selectedCharacterIndex[0]].Members[selectedCharacterIndex[1]].SpawnPositon.z * GameGrid.BlockDirections.UP + EditorTools.CurrentInspectedGrid.transform.position - GameGrid.BlockDirections.SE + GridEditor.verticalOffset; Handles.DrawLine(center + Vector3.zero, center + GameGrid.BlockDirections.SE * EditorTools.CurrentInspectedGrid.rows); Handles.DrawLine(center + Vector3.zero, center + GameGrid.BlockDirections.NE * EditorTools.CurrentInspectedGrid.columns); if (PreferenceWindow.ShowCrosshair) { Handles.DrawLine(center + GameGrid.BlockDirections.SE * EditorTools.CurrentInspectedGrid.rows / 2, center + GameGrid.BlockDirections.SE * EditorTools.CurrentInspectedGrid.rows / 2 + GameGrid.BlockDirections.NE * EditorTools.CurrentInspectedGrid.columns); Handles.DrawLine(center + GameGrid.BlockDirections.NE * EditorTools.CurrentInspectedGrid.columns / 2, center + GameGrid.BlockDirections.NE * EditorTools.CurrentInspectedGrid.columns / 2 + GameGrid.BlockDirections.SE * EditorTools.CurrentInspectedGrid.rows); } Handles.DrawLine(center + GameGrid.BlockDirections.SE * EditorTools.CurrentInspectedGrid.rows, center + GameGrid.BlockDirections.SE * EditorTools.CurrentInspectedGrid.rows + GameGrid.BlockDirections.NE * EditorTools.CurrentInspectedGrid.columns); Handles.DrawLine(center + GameGrid.BlockDirections.NE * EditorTools.CurrentInspectedGrid.columns, center + GameGrid.BlockDirections.NE * EditorTools.CurrentInspectedGrid.columns + GameGrid.BlockDirections.SE * EditorTools.CurrentInspectedGrid.rows); } } if (characterSelected && selectedMission.Teams.Count != 0) { if (ObjectHilighter.currentEditor == this) { GameTile tile = EditorTools.CurrentInspectedGrid.GetTile(selectedMission.Teams[selectedCharacterIndex[0]].Members[selectedCharacterIndex[1]].SpawnPositon); if (tile) { ObjectHilighter.Clear(); ObjectHilighter.Add(tile.GetComponent <SpriteRenderer>(), this); } else { ObjectHilighter.Clear(); } } Vector3 spawnPos = EditorTools.CurrentInspectedGrid.CenterPointOnGrid(selectedMission.Teams[selectedCharacterIndex[0]].Members[selectedCharacterIndex[1]].SpawnPositon); if (Event.current.type == EventType.MouseDrag) { float closestDist = Mathf.Infinity; int closestDir = 0; Vector3[] positions = new Vector3[] { spawnPos, spawnPos + GameGrid.BlockDirections.NW, spawnPos + GameGrid.BlockDirections.NE, spawnPos + GameGrid.BlockDirections.SE, spawnPos + GameGrid.BlockDirections.SW, spawnPos + GameGrid.BlockDirections.UP, spawnPos + GameGrid.BlockDirections.Down }; for (int c = 0; c < positions.Length; c++) { if (Vector3.Distance(selectedCharacterDragPosition, positions[c]) < closestDist) { closestDir = c; closestDist = Vector3.Distance(selectedCharacterDragPosition, positions[c]); } } if (Event.current.modifiers == EventModifiers.Control) { if (closestDir == 5 || closestDir == 6) { closestDir = 0; } } if (closestDir != 0) { GridPosition future = selectedMission.Teams[selectedCharacterIndex[0]].Members[selectedCharacterIndex[1]].SpawnPositon.Clone() + InputHandlerer.GetMovement(closestDir); if (EditorTools.CurrentInspectedGrid.isInBounds(future)) { Undo.RecordObject(target, "Move"); selectedMission.Teams[selectedCharacterIndex[0]].Members[selectedCharacterIndex[1]].SpawnPositon += InputHandlerer.GetMovement(closestDir); } } } if (Event.current.type == EventType.MouseUp) { selectedCharacterDragPosition = EditorTools.CurrentInspectedGrid.CenterPointOnGrid(selectedMission.Teams[selectedCharacterIndex[0]].Members[selectedCharacterIndex[1]].SpawnPositon); sceneView.Repaint(); } selectedCharacterDragPosition = Handles.PositionHandle(selectedCharacterDragPosition, Quaternion.Euler(-60, 0, 45)); } for (i = 0; i < selectedMission.Teams.Count; i++) { for (int q = 0; q < selectedMission.Teams[i].Members.Count; q++) { Vector3 position = EditorTools.CurrentInspectedGrid.CenterPointOnGrid(selectedMission.Teams[i].Members[q].SpawnPositon); Vector3 buttonPosition = position + Vector3.up; float size = 0.25f; float pickSize = size * 2f; Vector2 screenPos = HandleUtility.WorldToGUIPoint(buttonPosition); Rect areaRect = new Rect(screenPos.x - 120 / 2, screenPos.y, 120, 50); GUILayout.BeginArea(areaRect); EditorGUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); if (GUILayout.Button(selectedMission.Teams[i].Members[q]._Name, EditorStyles.miniButtonMid)) { SessionState.SetInt("MissionEditor_LastTeamIndex", i); SessionState.SetInt("CharacterEditor_LastCharacterIndex", q); CharacterEditor newEditor = EditorWindow.CreateInstance <CharacterEditor>(); newEditor.Do(selectedMission.Teams[i].Members[q], selectedMission, selectedMission, false); newEditor.SetParent(this); auxWindow = newEditor; EditorWindow.FocusWindowIfItsOpen <MissionEditor>(); selectedCharacterIndex = new int[] { i, q }; characterSelected = true; selectedCharacterDragPosition = position; ObjectHilighter.Clear(); ObjectHilighter.currentEditor = this; Selection.activeGameObject = null; } GUILayout.FlexibleSpace(); EditorGUILayout.EndHorizontal(); GUILayout.EndArea(); } } Handles.Label(Vector3.up, "", EditorStyles.boldLabel); }