148 lines
4.2 KiB
C#
148 lines
4.2 KiB
C#
using UnityEditor;
|
|
using UnityEditor.SceneManagement;
|
|
using UnityEngine;
|
|
using System.Collections.Generic;
|
|
|
|
public class SectionLoaderWindow : EditorWindow
|
|
{
|
|
private Vector2 scrollPos;
|
|
private List<SectionData> sections;
|
|
private string searchQuery = "";
|
|
private Dictionary<SectionData, bool> foldouts = new Dictionary<SectionData, bool>();
|
|
|
|
private SceneAsset baseSceneAsset; // Επιλογή βασικής σκηνής
|
|
|
|
[MenuItem("Tools/Section Loader")]
|
|
public static void ShowWindow()
|
|
{
|
|
GetWindow<SectionLoaderWindow>("Section Loader");
|
|
}
|
|
|
|
private void OnEnable()
|
|
{
|
|
LoadAllSections();
|
|
}
|
|
|
|
private void LoadAllSections()
|
|
{
|
|
string[] guids = AssetDatabase.FindAssets("t:SectionData");
|
|
sections = new List<SectionData>();
|
|
foldouts = new Dictionary<SectionData, bool>();
|
|
|
|
foreach (string guid in guids)
|
|
{
|
|
string path = AssetDatabase.GUIDToAssetPath(guid);
|
|
SectionData section = AssetDatabase.LoadAssetAtPath<SectionData>(path);
|
|
if (section != null)
|
|
{
|
|
sections.Add(section);
|
|
foldouts[section] = false;
|
|
}
|
|
}
|
|
}
|
|
|
|
private void OnGUI()
|
|
{
|
|
GUILayout.Space(10);
|
|
DrawBaseScenePicker();
|
|
GUILayout.Space(10);
|
|
DrawToolbar();
|
|
GUILayout.Space(10);
|
|
|
|
if (sections == null)
|
|
{
|
|
LoadAllSections();
|
|
}
|
|
|
|
scrollPos = EditorGUILayout.BeginScrollView(scrollPos);
|
|
|
|
foreach (var section in sections)
|
|
{
|
|
if (!string.IsNullOrEmpty(searchQuery) &&
|
|
!section.sectionName.ToLower().Contains(searchQuery.ToLower()))
|
|
{
|
|
continue;
|
|
}
|
|
|
|
EditorGUILayout.BeginVertical("box");
|
|
foldouts[section] = EditorGUILayout.Foldout(foldouts[section], section.sectionName, true);
|
|
|
|
if (foldouts[section])
|
|
{
|
|
EditorGUI.indentLevel++;
|
|
foreach (var sceneAsset in section.scenes)
|
|
{
|
|
if (sceneAsset != null)
|
|
{
|
|
EditorGUILayout.ObjectField(sceneAsset, typeof(SceneAsset), false);
|
|
}
|
|
}
|
|
|
|
GUILayout.Space(5);
|
|
|
|
if (GUILayout.Button("Load Section", GUILayout.Height(30)))
|
|
{
|
|
LoadSection(section);
|
|
}
|
|
EditorGUI.indentLevel--;
|
|
}
|
|
EditorGUILayout.EndVertical();
|
|
GUILayout.Space(5);
|
|
}
|
|
|
|
EditorGUILayout.EndScrollView();
|
|
}
|
|
|
|
private void DrawBaseScenePicker()
|
|
{
|
|
GUILayout.Label("Base Scene Settings", EditorStyles.boldLabel);
|
|
baseSceneAsset = (SceneAsset)EditorGUILayout.ObjectField("Base Scene", baseSceneAsset, typeof(SceneAsset), false);
|
|
}
|
|
|
|
private void DrawToolbar()
|
|
{
|
|
EditorGUILayout.BeginHorizontal();
|
|
|
|
GUIStyle searchField = GUI.skin.FindStyle("ToolbarSearchTextField") ?? GUI.skin.textField;
|
|
searchQuery = GUILayout.TextField(searchQuery, searchField);
|
|
|
|
if (GUILayout.Button("X", GUILayout.Width(20)))
|
|
{
|
|
searchQuery = "";
|
|
GUI.FocusControl(null);
|
|
}
|
|
|
|
if (GUILayout.Button("Reload Sections", GUILayout.Width(120)))
|
|
{
|
|
LoadAllSections();
|
|
}
|
|
|
|
EditorGUILayout.EndHorizontal();
|
|
}
|
|
|
|
private void LoadSection(SectionData section)
|
|
{
|
|
if (EditorSceneManager.SaveCurrentModifiedScenesIfUserWantsTo())
|
|
{
|
|
if (baseSceneAsset != null)
|
|
{
|
|
string baseScenePath = AssetDatabase.GetAssetPath(baseSceneAsset);
|
|
EditorSceneManager.OpenScene(baseScenePath, OpenSceneMode.Single);
|
|
}
|
|
else
|
|
{
|
|
EditorSceneManager.NewScene(NewSceneSetup.EmptyScene, NewSceneMode.Single);
|
|
}
|
|
|
|
foreach (var sceneAsset in section.scenes)
|
|
{
|
|
if (sceneAsset != null)
|
|
{
|
|
string scenePath = AssetDatabase.GetAssetPath(sceneAsset);
|
|
EditorSceneManager.OpenScene(scenePath, OpenSceneMode.Additive);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|