Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Assets/1.TeamWorkspace/MainMenu.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Assets/1.TeamWorkspace/MainMenu/Editor.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

183 changes: 183 additions & 0 deletions Assets/1.TeamWorkspace/MainMenu/Editor/ModuleSelectSceneBuilder.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
using System.Collections.Generic;
using System.IO;
using TMPro;
using UnityEditor;
using UnityEditor.SceneManagement;
using UnityEngine;
using UnityEngine.Rendering;

/// <summary>
/// Generates the Module Select scene, and puts the module scenes into the build list.
///
/// The scene is generated rather than hand-built because a serialized Unity scene is the worst
/// thing this repo can hold: Module 1's `Main Scene.unity` is ~100k lines and any two people editing
/// one conflict irreconcilably. This scene is small on purpose - a rig, a light, a floor and one
/// component - and everything visible is drawn from code by <see cref="ModuleSelectMenu"/>. If it
/// ever gets mangled by a merge, delete it and run this again.
///
/// Unity picks fresh object ids every time, so re-running this rewrites the whole file even when
/// nothing changed. That is fine here (nobody hand-edits it) but do not re-run it casually on a
/// branch you are about to merge, or you will hand the reviewer 450 lines of noise.
///
/// Menu: <b>AEDES > Rebuild Module Select Scene</b>.
/// Batchmode: <c>-executeMethod ModuleSelectSceneBuilder.Run</c>.
/// </summary>
public static class ModuleSelectSceneBuilder
{
const string SceneDir = "Assets/1.TeamWorkspace/MainMenu/Scene";
const string ScenePath = AppFlow.MenuScene;
const string GroundMatPath = SceneDir + "/M_MenuGround.mat";
// One in-game shot per module, named after its card (Module1.png, Module2.png, Module3.png).
// Every texture in the folder is wired in; a card with no match is text only.
const string PictureDir = "Assets/1.TeamWorkspace/MainMenu/Pictures";

const string RigPath = "Assets/Resources/Prefabs/Player/FPSPlayer.prefab";
const string LogoPath = "Assets/Images/SIMPLE_Logo.png";
const string SkyboxPath = "Assets/Packages/Fantasy Skybox FREE/Cubemaps/Classic/FS000_Day_03.mat";
// The project's shared Lao font: static atlas, the whole Lao block plus Basic Latin.
// Generated by LaoFontTool (AEDES > Regenerate Lao font asset); Module 2's HUD uses it too.
const string LaoFontPath = "Assets/Resources/Fonts/Lao_SomVang Full SDF.asset";

// Scenes the menu needs, in the order they get build indices. The menu goes first so the app
// starts on it.
static readonly string[] BuildScenes =
{
AppFlow.MenuScene,
AppFlow.Module1Scene,
AppFlow.Module1GameScene,
AppFlow.Module2Scene,
// Module 3 is not on main yet. UpdateBuildSettings skips paths that do not exist, so
// listing it is harmless now and correct the moment that branch lands.
AppFlow.Module3Scene,
AppFlow.Module2TutorialScene,
// The IP Menu's buttons go on to Module 1's start screen, which is already listed.
AppFlow.IpMenuScene,
};

[MenuItem("AEDES/Rebuild Module Select Scene")]
public static void Run()
{
Directory.CreateDirectory(SceneDir);

var font = AssetDatabase.LoadAssetAtPath<TMP_FontAsset>(LaoFontPath);
if (font == null)
Debug.LogWarning($"[ModuleSelectSceneBuilder] {LaoFontPath} not found; the menu falls back to the default TMP font (no Lao glyphs).");
BuildScene(font);
UpdateBuildSettings();

AssetDatabase.SaveAssets();
AssetDatabase.Refresh();
Debug.Log($"[ModuleSelectSceneBuilder] Wrote {ScenePath} and updated the build list.");
}

// ------------------------------------------------------------------ scene

static void BuildScene(TMP_FontAsset font)
{
var scene = EditorSceneManager.NewScene(NewSceneSetup.EmptyScene, NewSceneMode.Single);

// Sun. Nothing here is lightmapped, so realtime is both correct and cheap.
var lightGo = new GameObject("Directional Light");
lightGo.transform.rotation = Quaternion.Euler(48f, 150f, 0f);
var light = lightGo.AddComponent<Light>();
light.type = LightType.Directional;
light.color = new Color(1f, 0.96f, 0.88f);
light.intensity = 1.1f;
light.shadows = LightShadows.None;

var skybox = AssetDatabase.LoadAssetAtPath<Material>(SkyboxPath);
if (skybox != null) RenderSettings.skybox = skybox;
RenderSettings.ambientMode = AmbientMode.Skybox;
RenderSettings.sun = light;
RenderSettings.fog = false;

// A floor. Standing in a void is genuinely unpleasant in a headset, and the XR rig needs
// something under it if anyone ever re-enables locomotion here.
var ground = GameObject.CreatePrimitive(PrimitiveType.Plane);
ground.name = "Ground";
ground.transform.localScale = Vector3.one * 8f;
ground.isStatic = true;
ground.GetComponent<MeshRenderer>().sharedMaterial = EnsureGroundMaterial();

// The rig the rest of the project uses, minus locomotion: a menu is not somewhere to walk
// off to, and without it nobody can fall through the world while choosing a module.
var rigPrefab = AssetDatabase.LoadAssetAtPath<GameObject>(RigPath);
if (rigPrefab == null)
{
Debug.LogError($"[ModuleSelectSceneBuilder] Player rig not found at {RigPath}.");
}
else
{
var rig = (GameObject)PrefabUtility.InstantiatePrefab(rigPrefab);
rig.name = "Player";
rig.transform.position = Vector3.zero;
var locomotion = rig.transform.Find("Locomotion");
if (locomotion != null) locomotion.gameObject.SetActive(false);
}

var menuGo = new GameObject("Module Select Menu");
var menu = menuGo.AddComponent<ModuleSelectMenu>();
menu.font = font;
menu.logo = AssetDatabase.LoadAssetAtPath<Texture2D>(LogoPath);
var pictures = new List<Texture2D>();
foreach (var guid in AssetDatabase.FindAssets("t:Texture2D", new[] { PictureDir }))
pictures.Add(AssetDatabase.LoadAssetAtPath<Texture2D>(AssetDatabase.GUIDToAssetPath(guid)));
menu.pictures = pictures.ToArray();

EditorSceneManager.SaveScene(scene, ScenePath);
}

static Material EnsureGroundMaterial()
{
var existing = AssetDatabase.LoadAssetAtPath<Material>(GroundMatPath);
if (existing != null) return existing;

var shader = Shader.Find("Universal Render Pipeline/Lit") ?? Shader.Find("Standard");
var mat = new Material(shader) { name = "M_MenuGround" };
mat.color = new Color(0.16f, 0.36f, 0.34f);
if (mat.HasProperty("_Smoothness")) mat.SetFloat("_Smoothness", 0.1f);
AssetDatabase.CreateAsset(mat, GroundMatPath);
return mat;
}

// ------------------------------------------------------------------ build list

/// <summary>
/// Puts the menu at index 0 and every module behind it, enabled. Entries already in the list
/// keep their place after those, so nothing anyone else added is dropped - except that an
/// enabled scene sharing a <i>name</i> with one of ours is disabled. Module 1's game code loads
/// "Main Scene" and "Startup Menu_New" by name, and SIMPLE ships two other scenes called
/// "Main Scene"; if one of those were enabled, a name lookup could land in it instead.
/// </summary>
static void UpdateBuildSettings()
{
var wanted = new List<EditorBuildSettingsScene>();
var seen = new HashSet<string>();
var names = new HashSet<string>();

foreach (var path in BuildScenes)
{
if (AssetDatabase.LoadAssetAtPath<SceneAsset>(path) == null)
{
Debug.LogWarning($"[ModuleSelectSceneBuilder] {path} does not exist; skipping it in the build list.");
continue;
}
wanted.Add(new EditorBuildSettingsScene(path, true));
seen.Add(path);
names.Add(Path.GetFileNameWithoutExtension(path));
}

foreach (var s in EditorBuildSettings.scenes)
{
if (seen.Contains(s.path)) continue;
if (s.enabled && names.Contains(Path.GetFileNameWithoutExtension(s.path)))
{
Debug.LogWarning($"[ModuleSelectSceneBuilder] Disabling {s.path}: its name clashes with a module scene.");
s.enabled = false;
}
wanted.Add(s);
}

EditorBuildSettings.scenes = wanted.ToArray();
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Assets/1.TeamWorkspace/MainMenu/Pictures.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
130 changes: 130 additions & 0 deletions Assets/1.TeamWorkspace/MainMenu/Pictures/Module1.png.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading