-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Teams added to database. - Teams script. - Team editor. - Window for teams.
- Loading branch information
Showing
14 changed files
with
439 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
%YAML 1.1 | ||
%TAG !u! tag:unity3d.com,2011: | ||
--- !u!114 &11400000 | ||
MonoBehaviour: | ||
m_ObjectHideFlags: 0 | ||
m_PrefabParentObject: {fileID: 0} | ||
m_PrefabInternal: {fileID: 0} | ||
m_GameObject: {fileID: 0} | ||
m_Enabled: 1 | ||
m_EditorHideFlags: 0 | ||
m_Script: {fileID: 11500000, guid: 4a7b1fcdece9778478b2575993f98a72, type: 3} | ||
m_Name: NewTeam | ||
m_EditorClassIdentifier: | ||
name: NewTeam | ||
id: 0 | ||
characters: | ||
- {fileID: 11400000, guid: caa5b8cc4b5205b4297289922d3b7e33, type: 2} | ||
- {fileID: 11400000, guid: 75942776545ea02418c221a9273f406b, type: 2} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using UnityEditor; | ||
using UnityEditorInternal; | ||
using UnityEngine; | ||
|
||
[CustomEditor(typeof(Team))] | ||
public class TeamEditor : Editor { | ||
|
||
private ReorderableList listCharacters; | ||
private Vector2 scrollPosition; | ||
|
||
private void OnEnable() | ||
{ | ||
|
||
// Get characters | ||
listCharacters = new ReorderableList(serializedObject, | ||
serializedObject.FindProperty("characters"), | ||
true, true, true, true); | ||
|
||
// Draw characters | ||
listCharacters.drawElementCallback = | ||
(Rect rect, int index, bool isActive, bool isFocused) => { | ||
var element = listCharacters.serializedProperty.GetArrayElementAtIndex(index); | ||
Character character = element.objectReferenceValue as Character; | ||
|
||
rect.y += 2; | ||
EditorGUI.LabelField( | ||
new Rect(rect.x, rect.y, rect.width, EditorGUIUtility.singleLineHeight), | ||
character.name); | ||
}; | ||
|
||
// Characters header | ||
listCharacters.drawHeaderCallback = (Rect rect) => { | ||
EditorGUI.LabelField(rect, "Characters"); | ||
}; | ||
|
||
// Add character | ||
listCharacters.onAddDropdownCallback = (Rect buttonRect, ReorderableList l) => { | ||
var menu = new GenericMenu(); | ||
foreach (Character character in Database.Instance.characters) | ||
{ | ||
menu.AddItem(new GUIContent(character.name), | ||
false, clickHandlerCharacters, | ||
character); | ||
} | ||
menu.ShowAsContext(); | ||
}; | ||
} | ||
|
||
public override void OnInspectorGUI() | ||
{ | ||
serializedObject.Update(); | ||
|
||
var customStyle = new GUIStyle(); | ||
customStyle.alignment = TextAnchor.UpperCenter; | ||
customStyle.fontSize = 17; | ||
GUI.Label(new Rect(EditorGUILayout.GetControlRect().x, EditorGUILayout.GetControlRect().y, EditorGUILayout.GetControlRect().width, 30), "Editing \"" + ((Team)target).name + "\" team:", customStyle); | ||
|
||
EditorGUILayout.BeginVertical(); | ||
scrollPosition = EditorGUILayout.BeginScrollView(scrollPosition); | ||
|
||
EditorGUILayout.PropertyField(serializedObject.FindProperty("id"), new GUIContent("Id: "), GUILayout.MinWidth(100)); | ||
EditorGUI.BeginChangeCheck(); | ||
EditorGUILayout.PropertyField(serializedObject.FindProperty("name"), new GUIContent("Name: "), GUILayout.MinWidth(100)); | ||
if (EditorGUI.EndChangeCheck()) | ||
{ | ||
AssetDatabase.RenameAsset(AssetDatabase.GetAssetPath((SpecializedClass)target), ((Team)target).name + ".asset"); | ||
} | ||
listCharacters.DoLayoutList(); | ||
serializedObject.ApplyModifiedProperties(); | ||
|
||
EditorGUILayout.EndScrollView(); | ||
EditorGUILayout.EndVertical(); | ||
} | ||
|
||
private void clickHandlerCharacters(object target) | ||
{ | ||
var data = (Character)target; | ||
((Team)this.target).characters.Add(data); | ||
serializedObject.ApplyModifiedProperties(); | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
171 changes: 171 additions & 0 deletions
171
Assets/TRPGMaker/Editor/Windows/Database/TeamsWindow.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,171 @@ | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using UnityEditor; | ||
using UnityEditorInternal; | ||
using UnityEngine; | ||
|
||
public class TeamsWindow : LayoutWindow { | ||
private ReorderableList listTeams; | ||
private Editor buttonEditor; | ||
private Vector2 scrollPosition; | ||
|
||
public override void Init() | ||
{ | ||
createButtonReorderableList(); | ||
} | ||
|
||
public override void Draw(Rect rect) | ||
{ | ||
if (editor == null) | ||
DrawMainView(); | ||
else | ||
editor.OnInspectorGUI(); | ||
} | ||
|
||
public void DrawMainView() | ||
{ | ||
var customStyle = new GUIStyle(); | ||
customStyle.alignment = TextAnchor.UpperCenter; | ||
customStyle.fontSize = 17; | ||
GUI.Label(new Rect(EditorGUILayout.GetControlRect().x, EditorGUILayout.GetControlRect().y, EditorGUILayout.GetControlRect().width, 30), "List of teams:", customStyle); | ||
|
||
// Create color for each line | ||
GUIStyle gsLinePair = new GUIStyle(); | ||
gsLinePair.normal.background = MakeTextureColor.MakeTexture(600, 1, new Color(0.5f, 0.5f, 0.5f, 0.5f)); | ||
GUIStyle gsLineOdd = new GUIStyle(); | ||
gsLineOdd.normal.background = MakeTextureColor.MakeTexture(600, 1, new Color(0.5f, 0.5f, 0.5f, 0.0f)); | ||
|
||
EditorGUILayout.BeginVertical(); | ||
scrollPosition = EditorGUILayout.BeginScrollView(scrollPosition); | ||
|
||
for (int i = 0; i < Database.Instance.teams.Count; i++) | ||
{ | ||
Team team = Database.Instance.teams[i]; | ||
|
||
// Changing line color | ||
if (i % 2 == 0) | ||
GUILayout.BeginHorizontal(gsLinePair); | ||
else | ||
GUILayout.BeginHorizontal(gsLineOdd); | ||
Rect rect = EditorGUILayout.GetControlRect(); | ||
GUI.Label(rect, team.id + ": " + team.name); | ||
if (GUILayout.Button(new GUIContent("Edit"), GUILayout.Width(50))) | ||
{ | ||
editor = Editor.CreateEditor(team); | ||
} | ||
else if (GUILayout.Button(new GUIContent("Remove"), GUILayout.Width(90))) | ||
{ | ||
removeTeam(team); | ||
} | ||
GUILayout.EndHorizontal(); | ||
} | ||
|
||
EditorGUILayout.EndScrollView(); | ||
EditorGUILayout.EndVertical(); | ||
} | ||
|
||
public override bool Button(Rect rect) | ||
{ | ||
var teamTexture = (Texture2D)Resources.Load("Menu/Buttons/teams", typeof(Texture2D)); | ||
GUIStyle myStyle = new GUIStyle("Button"); | ||
myStyle.padding = new RectOffset(0, 0, 10, 10); | ||
|
||
if (GUILayout.Button(new GUIContent("Teams", teamTexture), myStyle)) | ||
{ | ||
editor = null; | ||
Draw(rect); | ||
selected = true; | ||
} | ||
|
||
if (selected) | ||
DrawButton(); | ||
|
||
return selected; | ||
} | ||
|
||
private void DrawButton() | ||
{ | ||
buttonEditor.serializedObject.Update(); | ||
|
||
listTeams.DoLayoutList(); | ||
|
||
buttonEditor.serializedObject.ApplyModifiedProperties(); | ||
} | ||
|
||
private void createButtonReorderableList() | ||
{ | ||
buttonEditor = Editor.CreateEditor(Database.Instance); | ||
|
||
// Get teams | ||
listTeams = new ReorderableList(buttonEditor.serializedObject, | ||
buttonEditor.serializedObject.FindProperty("teams"), | ||
true, false, true, true); | ||
|
||
// Draw teams | ||
listTeams.drawElementCallback = | ||
(Rect rect, int index, bool isActive, bool isFocused) => { | ||
var element = listTeams.serializedProperty.GetArrayElementAtIndex(index); | ||
var team = element.objectReferenceValue as Team; | ||
rect.y += 2; | ||
EditorGUI.LabelField(rect, team.id + ": " + team.name); | ||
}; | ||
|
||
// On select team | ||
listTeams.onSelectCallback = (ReorderableList l) => { | ||
var team = l.serializedProperty.GetArrayElementAtIndex(l.index).objectReferenceValue as Team; | ||
editor = Editor.CreateEditor(team); | ||
}; | ||
|
||
// On new team | ||
listTeams.onAddDropdownCallback = (Rect buttonRect, ReorderableList l) => { | ||
Team team = (Team)ScriptableObject.CreateInstance(typeof(Team)); | ||
|
||
var _exists = AssetDatabase.LoadAssetAtPath("Assets/TRPGMaker/Database/Teams/NewTeam.asset", typeof(Team)); | ||
if (_exists == null) | ||
{ | ||
team.name = "NewTeam"; | ||
AssetDatabase.CreateAsset(team, "Assets/TRPGMaker/Database/Teams/NewTeam.asset"); | ||
} | ||
else | ||
{ | ||
string[] existAssets = AssetDatabase.FindAssets("NewTeam"); | ||
bool seted = false; | ||
int i = 0; | ||
while (i <= existAssets.Length && !seted) | ||
{ | ||
var _existsNumber = AssetDatabase.LoadAssetAtPath("Assets/TRPGMaker/Database/Teams/NewTeam(" + (i + 1) + ").asset", typeof(Team)); | ||
if (_existsNumber == null) | ||
{ | ||
team.name = "NewTeam(" + (i + 1) + ")"; | ||
AssetDatabase.CreateAsset(team, "Assets/TRPGMaker/Database/Teams/NewTeam(" + (i + 1) + ").asset"); | ||
seted = true; | ||
} | ||
i++; | ||
} | ||
} | ||
|
||
editor = Editor.CreateEditor(team); | ||
Database.Instance.teams.Add(team); | ||
listTeams.index = Database.Instance.teams.Count - 1; | ||
DrawButton(); | ||
}; | ||
|
||
// On remove team | ||
listTeams.onRemoveCallback = (ReorderableList l) => { | ||
var team = l.serializedProperty.GetArrayElementAtIndex(l.index).objectReferenceValue as Team; | ||
removeTeam(team); | ||
editor = null; | ||
DrawMainView(); | ||
DrawButton(); | ||
}; | ||
|
||
// No header | ||
listTeams.headerHeight = 0; | ||
} | ||
|
||
private void removeTeam(Team team) | ||
{ | ||
Database.Instance.teams.Remove(team); | ||
AssetDatabase.DeleteAsset(AssetDatabase.GetAssetPath(team)); | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
Assets/TRPGMaker/Editor/Windows/Database/TeamsWindow.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.