void RefreshDictionaries() { CharacterTemplateDatabase database = (CharacterTemplateDatabase)target; foreach (var editor in cachedEditors.Values) { Editor.Destroy(editor); } cachedEditors.Clear(); for (int i = 0; i < database.commonCharacters.Count; i++) { if (!itemFolds.ContainsKey(database.commonCharacters[i])) { itemFolds[database.commonCharacters[i]] = false; } CharacterEditor newEdit = EditorWindow.CreateInstance <CharacterEditor>(); newEdit.Do(database.commonCharacters[i], null, database, true); cachedEditors[database.commonCharacters[i]] = newEdit; } for (int i = 0; i < database.uniqueCharacters.Count; i++) { if (!itemFolds.ContainsKey(database.uniqueCharacters[i])) { itemFolds[database.uniqueCharacters[i]] = false; } CharacterEditor newEdit = EditorWindow.CreateInstance <CharacterEditor>(); newEdit.Do(database.uniqueCharacters[i], null, database, true); cachedEditors[database.uniqueCharacters[i]] = newEdit; } }
public void Do(Team team, Mission mission) { this.team = team; this.mission = mission; if (this.team.members.Count != 0) { int last = SessionState.GetInt("CharacterEditor_LastCharacterIndex", 0); if (last > team.members.Count - 1) { last = 0; } CharacterEditor newEditor = EditorWindow.CreateInstance <CharacterEditor>(); newEditor.Do(team.members[last], mission, mission, false); } }
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); }
public override bool Render() { if (this.team == null) { return(false); } bool delete = false; bool close = false; EditorGUILayout.ScrollViewScope scrollScope = new EditorGUILayout.ScrollViewScope(scroll); using (scrollScope) { scroll = scrollScope.scrollPosition; EditorGUILayout.BeginVertical(EditorStyles.helpBox); EditorGUILayout.BeginHorizontal(EditorStyles.toolbar); if (GUILayout.Button("X", EditorStyles.toolbarButton, GUILayout.Width(20))) { Undo.RecordObject(mission, "Remove Team"); mission.Teams.Remove(this.team); mission.RefreshCharacterDictionary(); close = true; } EditorGUILayout.LabelField("Team: " + mission.GetTeamIndex(this.team)); if (GUILayout.Button("Close", EditorStyles.toolbarButton, GUILayout.Width(55))) { close = true; } EditorGUILayout.EndHorizontal(); EditorGUI.BeginChangeCheck(); EditorGUILayout.BeginHorizontal(); string _name = EditorGUILayout.TextField("Team Name: ", team.TeamName); Color tColor = EditorGUILayout.ColorField(team.TeamColor); if (EditorGUI.EndChangeCheck()) { Undo.RegisterCompleteObjectUndo(mission, "Modify Team"); team.TeamName = _name; team.TeamColor = tColor; } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); EditorGUI.indentLevel++; EditorGUILayout.LabelField("Members", EditorStyles.miniBoldLabel); List <Character> characters = team.members; if (GUILayout.Button("+", GUILayout.Width(30))) { Undo.RecordObject(mission, "Add Character"); GenericMenu CreateMenu = new GenericMenu(); CreateMenu.AddItem(new GUIContent("Add new"), false, CreateNewCharacter); foreach (Character chara in EditorTools.CharaDatabase.commonCharacters) { CreateMenu.AddItem(new GUIContent("Common/" + chara._Name), false, GetCharacter, chara); } foreach (Character chara in EditorTools.CharaDatabase.uniqueCharacters) { CreateMenu.AddItem(new GUIContent("Unique/" + chara._Name), false, GetCharacter, chara); } CreateMenu.ShowAsContext(); } EditorGUILayout.EndHorizontal(); EditorGUI.indentLevel++; for (int q = 0; q < characters.Count; q++) { Character chara = characters[q]; var v = new EditorGUILayout.HorizontalScope(); using (v) { GUILayout.Space(20 * EditorGUI.indentLevel); if (GUILayout.Button(chara._Name, EditorStyles.label, GUILayout.Width(150))) { CharacterEditor newEditor = EditorWindow.CreateInstance <CharacterEditor>(); newEditor.Do(chara, mission, mission, false); SessionState.SetInt("CharacterEditor_LastCharacterIndex", q); if (this.parent != null) { this.parent.auxWindow = newEditor; newEditor.SetParent(this.parent); } else { newEditor.Show(); } } if (this.parent != null) { if (GUILayout.Button("Pop", EditorStyles.miniButtonLeft)) { CharacterEditor newEditor = EditorWindow.CreateInstance <CharacterEditor>(); newEditor.Do(chara, mission, mission, false); newEditor.Show(); parent.auxWindow = null; this.parent = null; } } if (GUILayout.Button("X", EditorStyles.miniButtonRight)) { Undo.RecordObject(mission, "Remove Character"); characters.Remove(chara); mission.attatchedObjects.Remove(chara.SpawnCondition); string path = AssetDatabase.GetAssetPath(chara.SpawnCondition); AssetDatabase.DeleteAsset(path); SessionState.EraseInt("CharacterEditor_LastCharacterIndex"); } } if (Event.current.button == 1 && v.rect.Contains(Event.current.mousePosition)) { CharacterContextMenu(v.rect, chara); } // EditorGUILayout.EndHorizontal(); } EditorGUI.indentLevel--; EditorGUI.indentLevel--; EditorGUILayout.EndVertical(); } return(delete || close); }