Skip to content

Commit ccd50ea

Browse files
committed
Merge remote-tracking branch 'tech-mkt/main' into pr-bash
2 parents 9b8eecc + fe9a967 commit ccd50ea

File tree

5 files changed

+163
-2
lines changed

5 files changed

+163
-2
lines changed
Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
using System.Collections;
2+
using System.Collections.Generic;
3+
using UnityEngine;
4+
using UnityEditor;
5+
6+
class SOsQuickAccessToolWindow : EditorWindow
7+
{
8+
[Header("Editor Window Related")]
9+
Vector2 scroll;
10+
int selected;
11+
12+
[Header("SOs related")]
13+
string[] assetSearchFolders;
14+
15+
List<string> SOTypes;
16+
string[] objectsGUIDs;
17+
string[] objectsPaths;
18+
ScriptableObject[] objects;
19+
20+
string[] displayObjectsGUIDs;
21+
List<string> displayObjectsPaths;
22+
List<ScriptableObject> displayObjects;
23+
24+
private void OnEnable()
25+
{
26+
assetSearchFolders = new string[1];
27+
assetSearchFolders[0] = "Assets/ScriptableObjects";
28+
29+
FindAllSOs();
30+
FindDisplaySOs();
31+
}
32+
33+
void OnFocus()
34+
{
35+
FindAllSOs();
36+
FindDisplaySOs();
37+
}
38+
39+
[MenuItem("Tools/SOs Quick Access Tool")]
40+
private static void ShowWindow()
41+
{
42+
GetWindow<SOsQuickAccessToolWindow>("SOs Quick Access Tool");
43+
}
44+
45+
void OnGUI()
46+
{
47+
GUILayout.Space(EditorGUIUtility.singleLineHeight * 0.5f);
48+
49+
GUILayout.BeginHorizontal();
50+
51+
DrawSOsPicker();
52+
if (GUILayout.Button("Refresh All"))
53+
{
54+
FindAllSOs();
55+
FindDisplaySOs();
56+
}
57+
58+
GUILayout.EndHorizontal();
59+
60+
DrawSOsList();
61+
}
62+
63+
void DrawSOsPicker()
64+
{
65+
EditorGUI.BeginChangeCheck();
66+
selected = EditorGUILayout.Popup(GUIContent.none, selected, SOTypes.ToArray());
67+
if (EditorGUI.EndChangeCheck())
68+
{
69+
FindDisplaySOs();
70+
}
71+
}
72+
73+
void DrawSOsList()
74+
{
75+
scroll = GUILayout.BeginScrollView(scroll);
76+
77+
for (int i = 0; i < displayObjectsGUIDs.Length; i++)
78+
{
79+
GUILayout.Label(i + 1 + ". " + displayObjects[i].name);
80+
81+
if (GUILayout.Button("Locate Quickly"))
82+
{
83+
EditorUtility.FocusProjectWindow();
84+
EditorGUIUtility.PingObject(displayObjects[i]);
85+
}
86+
87+
GUILayout.Space(EditorGUIUtility.singleLineHeight);
88+
}
89+
90+
GUILayout.EndScrollView();
91+
}
92+
93+
void FindAllSOs()
94+
{
95+
objectsGUIDs = AssetDatabase.FindAssets("t:ScriptableObject", assetSearchFolders) as string[];
96+
97+
objectsPaths = new string[objectsGUIDs.Length];
98+
objects = new ScriptableObject[objectsGUIDs.Length];
99+
100+
SOTypes = new List<string>();
101+
102+
for (int i = 0; i < objectsGUIDs.Length; i++)
103+
{
104+
objectsPaths[i] = AssetDatabase.GUIDToAssetPath(objectsGUIDs[i]);
105+
objects[i] = (ScriptableObject)AssetDatabase.LoadAssetAtPath(objectsPaths[i], typeof(ScriptableObject));
106+
//Debug.Log(objectsGUIDs[i] + ": " + objectsPaths[i] + " - " + i);
107+
}
108+
109+
for (int i = 0; i < objects.Length; i++)
110+
{
111+
if (SOTypes.IndexOf(objects[i].GetType().ToString()) == -1)
112+
{
113+
SOTypes.Add(objects[i].GetType().ToString());
114+
}
115+
}
116+
}
117+
118+
void FindDisplaySOs()
119+
{
120+
if (displayObjects != null)
121+
{
122+
displayObjects.Clear();
123+
}
124+
if (displayObjectsPaths != null)
125+
{
126+
displayObjectsPaths.Clear();
127+
}
128+
129+
string type = SOTypes[selected];
130+
string queryString = "t:" + type;
131+
132+
displayObjectsGUIDs = AssetDatabase.FindAssets(queryString);
133+
134+
displayObjectsPaths = new List<string>(displayObjectsGUIDs.Length);
135+
displayObjects = new List<ScriptableObject>(displayObjectsGUIDs.Length);
136+
137+
for (int i = 0; i < displayObjectsGUIDs.Length; i++)
138+
{
139+
displayObjectsPaths.Add(AssetDatabase.GUIDToAssetPath(displayObjectsGUIDs[i]));
140+
displayObjects.Add(AssetDatabase.LoadAssetAtPath(displayObjectsPaths[i], typeof(ScriptableObject)) as ScriptableObject);
141+
}
142+
}
143+
}

UOP1_Project/Assets/Scripts/Editor/SOsQuickAccessToolWindow.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

UOP1_Project/Assets/Scripts/SaveSystem/FileManager.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public static bool WriteToFile(string fileName, string fileContents)
1515
}
1616
catch (Exception e)
1717
{
18-
Debug.LogError($"Failed to write to {fullPath} with exception {e}");
18+
//Debug.LogError($"Failed to write to {fullPath} with exception {e}");
1919
return false;
2020
}
2121
}
@@ -31,7 +31,7 @@ public static bool LoadFromFile(string fileName, out string result)
3131
}
3232
catch (Exception e)
3333
{
34-
Debug.LogError($"Failed to read from {fullPath} with exception {e}");
34+
//Debug.LogError($"Failed to read from {fullPath} with exception {e}");
3535
result = "";
3636
return false;
3737
}

UOP1_Project/Assets/Scripts/SaveSystem/SaveSystem.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,4 +75,9 @@ public void SaveDataToDisk()
7575
}
7676
}
7777
}
78+
79+
public void WriteEmptySaveFile()
80+
{
81+
FileManager.WriteToFile(saveFilename, "");
82+
}
7883
}

UOP1_Project/Assets/Scripts/SceneManagement/StartGame.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ public class StartGame : MonoBehaviour
2323
private void Start()
2424
{
2525
_hasSaveData = saveSystem.LoadSaveDataFromDisk();
26+
2627
if (_hasSaveData)
2728
{
2829
startText.text = "Continue";
@@ -38,6 +39,7 @@ public void OnPlayButtonPress()
3839
{
3940
if (!_hasSaveData)
4041
{
42+
saveSystem.WriteEmptySaveFile();
4143
//Start new game
4244
onPlayButtonPress.RaiseEvent(locationsToLoad, showLoadScreen);
4345
}

0 commit comments

Comments
 (0)