Skip to content
This repository was archived by the owner on May 21, 2026. It is now read-only.

Commit 753eb46

Browse files
committed
Bugfix: Can't edit character messages outside scene.
Bugfix: Is necessary setting the Resources path manually. Messages Manager is now scrolling!
1 parent 56b7c2f commit 753eb46

6 files changed

Lines changed: 52 additions & 36 deletions

File tree

Diplomata/Character.cs

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -31,19 +31,22 @@ public class CharacterEditor : Editor {
3131
SerializedProperty attributes;
3232
SerializedProperty description;
3333
SerializedProperty startOnPlay;
34-
35-
public static void SetCharacter(Character character) {
36-
CharacterEditor.character = character;
37-
}
34+
SerializedProperty path;
3835

3936
public void OnEnable() {
37+
attributes = serializedObject.FindProperty("attributes");
38+
description = serializedObject.FindProperty("description");
39+
startOnPlay = serializedObject.FindProperty("startOnPlay");
40+
path = serializedObject.FindProperty("characterPath");
41+
4042
if (GameObject.Find(serializedObject.targetObject.name) != null) {
4143
GameObject obj = GameObject.Find(serializedObject.targetObject.name);
4244
character = obj.GetComponent<Character>();
4345
}
44-
attributes = serializedObject.FindProperty("attributes");
45-
description = serializedObject.FindProperty("description");
46-
startOnPlay = serializedObject.FindProperty("startOnPlay");
46+
47+
else {
48+
character = (Character)AssetDatabase.LoadAssetAtPath(path.stringValue,typeof(Character));
49+
}
4750
}
4851

4952
public override void OnInspectorGUI() {
@@ -103,22 +106,17 @@ public class Character : MonoBehaviour {
103106
private Message currentMessage;
104107
private List<Message> currentChoices = new List<Message>();
105108
private Events events;
109+
public string characterPath;
106110

107111
public void Awake() {
108112
InstantiateManager();
109113
SetAttributes();
110-
#if (UNITY_EDITOR)
111-
CharacterEditor.SetCharacter(this);
112-
#endif
113114
}
114115

115116
public void Start() {
116117
events = GetComponent<Events>();
117118
events.SetCharacter(this);
118-
#if (UNITY_EDITOR)
119-
CharacterEditor.SetCharacter(this);
120-
#endif
121-
119+
122120
InstantiateManager();
123121

124122
talking = false;
@@ -302,5 +300,16 @@ public void SetInfluence() {
302300
influence = (byte)tempInfluence;
303301
}
304302

303+
public void Update() {
304+
#if (UNITY_EDITOR)
305+
if (characterPath == "" || characterPath == null) {
306+
if (System.IO.File.Exists(AssetDatabase.GetAssetPath(PrefabUtility.GetPrefabParent(this)))) {
307+
characterPath = AssetDatabase.GetAssetPath(PrefabUtility.GetPrefabParent(this));
308+
PrefabUtility.ReplacePrefab(gameObject, PrefabUtility.GetPrefabParent(this), ReplacePrefabOptions.ConnectToPrefab);
309+
}
310+
}
311+
#endif
312+
}
313+
305314
}
306315
}

Diplomata/Editor/Preferences.cs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,14 @@ static public void Init() {
3030
GetPrefsStrings();
3131

3232
Preferences window = (Preferences)GetWindow(typeof(Preferences), false, "Preferences");
33+
window.minSize = new Vector2(455,250);
3334
window.Show();
3435
}
3536

3637
public void OnGUI() {
3738

3839
int margin = 15;
3940

40-
GUILayout.Space(margin);
41-
GUILayout.Label(Diplomata.Manager.logo, GUILayout.Width(Screen.width - 30), GUILayout.Height(30));
42-
4341
GUILayout.Space(margin);
4442
GUILayout.BeginHorizontal();
4543
GUILayout.BeginVertical(GUILayout.Width(Screen.width / 3 - 5));
@@ -94,11 +92,6 @@ public void OnGUI() {
9492
SetPrefsStrings();
9593
Diplomata.Manager.UpdatePreferences();
9694
}
97-
GUILayout.Space(margin);
98-
GUILayout.Label("Diplomata Resources path: ");
99-
resPath = GUILayout.TextField(resPath);
100-
101-
GUILayout.Space(margin);
10295
}
10396

10497
public string[] ListToStringArray(List<string> list) {
@@ -113,12 +106,13 @@ public string[] ListToStringArray(List<string> list) {
113106

114107
public static void LoadJson() {
115108
TextAsset json = (TextAsset)Resources.Load("preferences");
109+
resPath = AssetDatabase.GetAssetPath(json);
116110
preferences = JsonUtility.FromJson<Diplomata.Preferences>(json.text);
117111
}
118112

119113
public void SaveJson() {
120114
string json = JsonUtility.ToJson(preferences);
121-
using (FileStream fs = new FileStream(resPath + "preferences.json", FileMode.Create)) {
115+
using (FileStream fs = new FileStream(resPath, FileMode.Create)) {
122116
using (StreamWriter writer = new StreamWriter(fs)) {
123117
writer.Write(json);
124118
}

Diplomata/Example/Example.prefab

0 Bytes
Binary file not shown.

Diplomata/MessageManager.cs

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,29 @@ namespace Diplomata {
99

1010
public class MessageManager : EditorWindow {
1111

12+
public readonly static int headerSize = 62;
13+
private readonly static int colunmLimit = 100;
14+
private readonly static int rowLimit = 100;
15+
private readonly static int windowContentWidth = colunmLimit * 170;
16+
private readonly static int windowContentHeight = headerSize + (rowLimit * 135);
17+
1218
public static Character character;
1319
private readonly Color bgColor1 = new Color(0.085f, 0.085f, 0.085f);
1420
private readonly Color bgColor2 = new Color(0.125f, 0.125f, 0.125f);
1521
private GUIStyle bgStyle;
1622
public static List<List<Node>> colunms;
17-
public static int headerSize = 62;
1823
public static List<string> languages;
1924
public static string[] languagesArray;
2025
public static int languageIndex;
2126
public static GUIStyle style;
2227
public static bool close;
28+
public Vector2 scrollPos;
2329

2430
static public void Init(Character character) {
2531
close = false;
2632
style = new GUIStyle();
2733
MessageManager.character = character;
2834
Manager.UpdatePreferences();
29-
//character.messages = new List<Message>();
3035
SetLanguages();
3136
ResetColunms();
3237
MessageManager window = (MessageManager)GetWindow(typeof(MessageManager), false, "Messages", true);
@@ -104,13 +109,17 @@ public static void ResetColunms() {
104109

105110
// Last add node in every colunm
106111
for (int i = 0; i <= colunmsMax; i++) {
107-
colunms[i].Add(new Node(i,colunms[i].Count,character));
112+
if (colunms[i].Count < rowLimit) {
113+
colunms[i].Add(new Node(i, colunms[i].Count, character));
114+
}
108115
}
109116

110117
// Add node in last colunm
111118
if (character.messages.Count > 0) {
112-
colunms.Add(new List<Node>());
113-
colunms[colunms.Count - 1].Add(new Node(colunmsMax + 1, 0, character));
119+
if (colunms.Count < colunmLimit) {
120+
colunms.Add(new List<Node>());
121+
colunms[colunms.Count - 1].Add(new Node(colunmsMax + 1, 0, character));
122+
}
114123
}
115124

116125
// Add node in first colunm
@@ -123,14 +132,14 @@ public static void ResetColunms() {
123132
public void DrawBG() {
124133
bool turn = false;
125134
Color textColor;
126-
for (int i = 0; i < 1700; i += 170) {
135+
for (int i = 0; i < windowContentWidth; i += 170) {
127136
if (turn) {
128-
EditorGUI.DrawRect(new Rect(i, headerSize - 30, 170, Screen.height), bgColor2);
137+
EditorGUI.DrawRect(new Rect(i, headerSize - 30, 170, windowContentHeight), bgColor2);
129138
textColor = new Color(0.325f, 0.325f, 0.325f);
130139
turn = false;
131140
}
132141
else {
133-
EditorGUI.DrawRect(new Rect(i, headerSize - 30, 170, Screen.height), bgColor1);
142+
EditorGUI.DrawRect(new Rect(i, headerSize - 30, 170, windowContentHeight), bgColor1);
134143
textColor = new Color(0.285f, 0.285f, 0.285f);
135144
turn = true;
136145
}
@@ -155,11 +164,15 @@ public void DrawHeader() {
155164
public void OnGUI() {
156165
Character characterTemp = character;
157166
int indexTemp = languageIndex;
158-
159-
EditorGUILayout.BeginScrollView(new Vector2(0,0));
160167

161-
DrawBG();
162168
DrawHeader();
169+
170+
scrollPos = GUI.BeginScrollView(
171+
new Rect(0, headerSize - 30, Screen.width, Screen.height - headerSize + 8),
172+
scrollPos,
173+
new Rect(0, headerSize - 30, windowContentWidth, windowContentHeight));
174+
175+
DrawBG();
163176

164177
if (languageIndex != indexTemp) {
165178
Manager.UpdatePreferences();
@@ -193,7 +206,7 @@ public void OnGUI() {
193206
}
194207
}
195208

196-
EditorGUILayout.EndScrollView();
209+
GUI.EndScrollView();
197210

198211
if (close) {
199212
this.Close();
0 Bytes
Binary file not shown.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"attributes":["fear","politeness","argumentation","insistence","charm","confidence"],"subLanguages":["en-US"],"dubLanguages":["en-US"]}
1+
{"attributes":["fear","politeness","argumentation","insistence","charm","confidence"],"subLanguages":["pt-BR","en-US"],"dubLanguages":["Dibberish"]}

0 commit comments

Comments
 (0)