-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathModeSelection.cs
More file actions
88 lines (75 loc) · 3.37 KB
/
Copy pathModeSelection.cs
File metadata and controls
88 lines (75 loc) · 3.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
public class ModeSelection : MonoBehaviour
{
void Awake()
{
SetupCamera();
CreateModeSelectionUI();
}
void SetupCamera()
{
// 기존 카메라 모두 제거
Camera[] allCameras = FindObjectsOfType<Camera>();
foreach (Camera existingCam in allCameras)
{
Destroy(existingCam.gameObject);
}
// 새로운 메인 카메라 생성
GameObject camObj = new GameObject("Main Camera");
Camera cam = camObj.AddComponent<Camera>();
cam.tag = "MainCamera";
cam.transform.position = new Vector3(0, 0, -10);
cam.orthographic = true;
cam.orthographicSize = 5;
cam.backgroundColor = Color.black;
cam.cullingMask = ~0; // 모든 레이어 렌더링
}
void CreateModeSelectionUI()
{
GameObject canvasObj = new GameObject("Canvas");
Canvas canvas = canvasObj.AddComponent<Canvas>();
canvas.renderMode = RenderMode.ScreenSpaceOverlay;
canvasObj.AddComponent<CanvasScaler>();
canvasObj.AddComponent<GraphicRaycaster>();
if (FindAnyObjectByType<UnityEngine.EventSystems.EventSystem>() == null)
{
GameObject eventSystemObj = new GameObject("EventSystem");
eventSystemObj.AddComponent<UnityEngine.EventSystems.EventSystem>();
eventSystemObj.AddComponent<UnityEngine.EventSystems.StandaloneInputModule>();
}
CreateText("TitleText", "Select Game Mode", new Vector2(0, 150), canvas.transform, 36, Color.white);
CreateButton("PendulumGameButton", "1. Mouse Control Game", new Vector2(0, 50), canvas.transform, "PendulumGame");
CreateButton("PendulumSim3DButton", "2. 3D Pendulum Simulation", new Vector2(0, 0), canvas.transform, "PendulumSim3D");
CreateButton("PendulumSim2DMultiButton", "3. 2D Multi Pendulum Sim", new Vector2(0, -50), canvas.transform, "PendulumSim2DMulti");
}
Text CreateText(string name, string content, Vector2 anchoredPos, Transform parent, int fontSize, Color color)
{
GameObject textObj = new GameObject(name);
textObj.transform.SetParent(parent);
Text text = textObj.AddComponent<Text>();
text.font = Resources.GetBuiltinResource<Font>("LegacyRuntime.ttf");
text.text = content;
text.fontSize = fontSize;
text.color = color;
text.alignment = TextAnchor.MiddleCenter;
RectTransform rect = text.GetComponent<RectTransform>();
rect.sizeDelta = new Vector2(400, 60);
rect.anchoredPosition = anchoredPos;
return text;
}
Button CreateButton(string name, string buttonText, Vector2 anchoredPos, Transform parent, string sceneToLoad)
{
GameObject buttonObj = new GameObject(name);
buttonObj.transform.SetParent(parent);
buttonObj.AddComponent<Image>().color = new Color(0.2f, 0.2f, 0.2f, 1f);
Button button = buttonObj.AddComponent<Button>();
button.onClick.AddListener(() => SceneManager.LoadScene(sceneToLoad));
RectTransform rect = buttonObj.GetComponent<RectTransform>();
rect.sizeDelta = new Vector2(300, 50);
rect.anchoredPosition = anchoredPos;
CreateText("ButtonText", buttonText, Vector2.zero, buttonObj.transform, 28, Color.white);
return button;
}
}