Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
JLChnToZ committed Nov 5, 2023
1 parent 90993f3 commit 6a1e23b
Showing 1 changed file with 32 additions and 29 deletions.
61 changes: 32 additions & 29 deletions Packages/idv.jlchntoz.vvmw/Editor/VVMW/MenuUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,18 @@
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEditor;
using JLChnToZ.VRC.VVMW.Designer;
using JLChnToZ.VRC.VVMW.Editors;
using VVMW.ThirdParties.Yttl;

using UnityObject = UnityEngine.Object;
using static UnityEngine.Object;
using JLChnToZ.VRC.VVMW.Designer;
using JLChnToZ.VRC.VVMW.Editors;

namespace JLChnToZ.VRC.VVMW {
public static class MenuUtil {
const string createMenuRoot = "GameObject/VizVid/";
const string packageRoot = "Packages/idv.jlchntoz.vvmw/";
const string prefabRoot = packageRoot + "Prefabs/";

static readonly Dictionary<(Type, string), FieldInfo> fieldCache = new Dictionary<(Type, string), FieldInfo>();

static GameObject SpawnPrefab(string path, bool spawnOnRoot = false) {
Expand Down Expand Up @@ -64,70 +67,70 @@ static FieldInfo GetField(Type type, string fieldName) {
return result;
}

[MenuItem("GameObject/VizVid/Video Player (Core only)", false, 49)]
static void CreateNoControls() => SpawnPrefab("Packages/idv.jlchntoz.vvmw/VVMW (No Controls).prefab");
[MenuItem(createMenuRoot + "Video Player (Core only)", false, 49)]
static void CreateNoControls() => SpawnPrefab(packageRoot + "VVMW (No Controls).prefab");

[MenuItem("GameObject/VizVid/Video Player (Separated Controls)", false, 49)]
static void CreateSeparateControls() => SpawnPrefab("Packages/idv.jlchntoz.vvmw/VVMW (Separated Controls).prefab");
[MenuItem(createMenuRoot + "Video Player (Separated Controls)", false, 49)]
static void CreateSeparateControls() => SpawnPrefab(packageRoot + "VVMW (Separated Controls).prefab");

[MenuItem("GameObject/VizVid/Video Player (On-Screen Controls)", false, 49)]
static void CreateOnScreenControls() => SpawnPrefab("Packages/idv.jlchntoz.vvmw/VVMW (On-Screen Controls).prefab");
[MenuItem(createMenuRoot + "Video Player (On-Screen Controls)", false, 49)]
static void CreateOnScreenControls() => SpawnPrefab(packageRoot + "VVMW (On-Screen Controls).prefab");

[MenuItem("GameObject/VizVid/YTTL", false, 49)]
[MenuItem(createMenuRoot + "YTTL", false, 49)]
static void CreateYTTL() {
SpawnSingletonPrefab<YttlManager>("Packages/idv.jlchntoz.vvmw/Prefabs/Third-Parties/YTTL/YTTL Manager.prefab");
SpawnSingletonPrefab<YttlManager>(prefabRoot + "Third-Parties/YTTL/YTTL Manager.prefab");
foreach (var core in SceneManager.GetActiveScene().IterateAllComponents<Core>(true))
LocatableAttributeDrawer.Locate(core, GetField(typeof(Core), "yttl"), true, true);
}

[MenuItem("GameObject/VizVid/Additional Controls/Screen", false, 49)]
[MenuItem(createMenuRoot + "Additional Controls/Screen", false, 49)]
static void CreateScreen() {
var go = SpawnPrefab("Packages/idv.jlchntoz.vvmw/Prefabs/Default Screen.prefab");
var go = SpawnPrefab(prefabRoot + "Default Screen.prefab");
var core = Utils.FindClosestComponentInHierarchy<Core>(go.transform);
if (core != null) CoreEditor.AddTarget(core, go.GetComponent<Renderer>());
}

[MenuItem("GameObject/VizVid/Additional Controls/Pickupable Screen", false, 49)]
[MenuItem(createMenuRoot + "Additional Controls/Pickupable Screen", false, 49)]
static void CreatePickupScreen() {
var go = SpawnPrefab("Packages/idv.jlchntoz.vvmw/Prefabs/Pickup Screen.prefab");
var go = SpawnPrefab(prefabRoot + "Pickup Screen.prefab");
var core = Utils.FindClosestComponentInHierarchy<Core>(go.transform);
if (core != null) CoreEditor.AddTarget(core, go.transform.Find("Pickup_ScalingPanel/ScreenScaling/Screen").GetComponent<Renderer>());
}

[MenuItem("GameObject/VizVid/Additional Controls/Audio Source", false, 49)]
[MenuItem(createMenuRoot + "Additional Controls/Audio Source", false, 49)]
static void CreateAudioSource() {
var go = SpawnPrefab("Packages/idv.jlchntoz.vvmw/Prefabs/Default Audio Source.prefab");
var go = SpawnPrefab(prefabRoot + "Default Audio Source.prefab");
var core = Utils.FindClosestComponentInHierarchy<Core>(go.transform);
if (core != null) CoreEditor.AddTarget(core, go.GetComponent<AudioSource>());
}

[MenuItem("GameObject/VizVid/Additional Controls/Separated Controls", false, 49)]
static void CreateSeparateContols() => SpawnPrefab("Packages/idv.jlchntoz.vvmw/Prefabs/Default UI.prefab");
[MenuItem(createMenuRoot + "Additional Controls/Separated Controls", false, 49)]
static void CreateSeparateContols() => SpawnPrefab(prefabRoot + "Default UI.prefab");

[MenuItem("GameObject/VizVid/Additional Controls/Separated Controls (Narrow)", false, 49)]
static void CreateSeparateNarrowContols() => SpawnPrefab("Packages/idv.jlchntoz.vvmw/Prefabs/Default UI (Narrow).prefab");
[MenuItem(createMenuRoot + "Additional Controls/Separated Controls (Narrow)", false, 49)]
static void CreateSeparateNarrowContols() => SpawnPrefab(prefabRoot + "Default UI (Narrow).prefab");

[MenuItem("GameObject/VizVid/Additional Controls/On-Screen Controls With Screen", false, 49)]
[MenuItem(createMenuRoot + "Additional Controls/On-Screen Controls With Screen", false, 49)]
static void CreateOnScreenContols() {
var go = SpawnPrefab("Packages/idv.jlchntoz.vvmw/Prefabs/Screen With Overlay.prefab");
var go = SpawnPrefab(prefabRoot + "Screen With Overlay.prefab");
var core = Utils.FindClosestComponentInHierarchy<Core>(go.transform);
if (core != null) CoreEditor.AddTarget(core, go.transform.Find("Screen").GetComponent<Renderer>());
}

[MenuItem("GameObject/VizVid/Additional Controls/Overlay Controls", false, 49)]
[MenuItem(createMenuRoot + "Additional Controls/Overlay Controls", false, 49)]
static void CreateOverlayControls() {
if (FindObjectOfType<OverlayControl>() != null && !EditorUtility.DisplayDialog(
"Warning",
"You already have an Overlay Control in scene, adding another one may cause unexpected behavior, are you sure to continue?",
"Yes", "No"
)) return;
SpawnPrefab("Packages/idv.jlchntoz.vvmw/Prefabs/Overlay Control.prefab");
SpawnPrefab(prefabRoot + "Overlay Control.prefab");
}

[MenuItem("GameObject/VizVid/Additional Controls/Resync Button", false, 49)]
static void CreateResyncButton() => SpawnPrefab("Packages/idv.jlchntoz.vvmw/Prefabs/Re-Sync Button.prefab");
[MenuItem(createMenuRoot + "Additional Controls/Resync Button", false, 49)]
static void CreateResyncButton() => SpawnPrefab(prefabRoot + "Re-Sync Button.prefab");

[MenuItem("GameObject/VizVid/Additional Controls/Global Resync Button", false, 49)]
static void CreateGlobalSyncButton() => SpawnPrefab("Packages/idv.jlchntoz.vvmw/Prefabs/Global Sync Button.prefab");
[MenuItem(createMenuRoot + "Additional Controls/Global Resync Button", false, 49)]
static void CreateGlobalSyncButton() => SpawnPrefab(prefabRoot + "Global Sync Button.prefab");
}
}

0 comments on commit 6a1e23b

Please sign in to comment.