diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5feb59b --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +src/bin/ +src/obj +test/ +ref/ +build.sh diff --git a/src/ModTaker/Global.cs b/src/ModTaker/Global.cs new file mode 100644 index 0000000..b68d773 --- /dev/null +++ b/src/ModTaker/Global.cs @@ -0,0 +1,7 @@ +namespace ModTaker +{ + public static class Global + { + public static bool EnableSteam = false; + } +} diff --git a/src/ModTaker/MainMenu.cs b/src/ModTaker/MainMenu.cs new file mode 100644 index 0000000..d5dfff9 --- /dev/null +++ b/src/ModTaker/MainMenu.cs @@ -0,0 +1,40 @@ +using UnityEngine; + +namespace ModTaker +{ + public class MainMenu + { + public enum MenuState + { + Main, + ChapterSelect, + Settings, + Credits, + Dialog, + SceneTransition, + Loading, + Quit + } + + public MenuState CurrentMenuState = MenuState.Main; + public GameObject go = new GameObject(); + public void toMainMenu() + { + CurrentMenuState = MenuState.Main; + go = MainMenuObject; + go.name = "MainMenu"; + } + + public GameObject MainMenuObject = UI.Build(new UIItem[] + { + new UIButton() { + Name = "TestButton", + Position = new Vector2(100, 200), + Size = new Vector2(150, 150), + Text = "Test", + FontSize = 30, + Sprite = Resources.Load("Button") + } + }); + } +} diff --git a/src/ModTaker/UIBuilder.cs b/src/ModTaker/UIBuilder.cs new file mode 100644 index 0000000..62117b0 --- /dev/null +++ b/src/ModTaker/UIBuilder.cs @@ -0,0 +1,128 @@ +using UnityEngine; +using UnityEngine.UI; + +namespace ModTaker +{ + public class UI + { + public static GameObject Build(UIItem[] uiItems) + { + var g = new GameObject(); + + var c = g.AddComponent(); + c.renderMode = RenderMode.ScreenSpaceOverlay; + c.pixelPerfect = true; + c.sortingOrder = 1; + + var cs = g.AddComponent(); + cs.uiScaleMode = CanvasScaler.ScaleMode.ScaleWithScreenSize; + cs.referenceResolution = new Vector2(1920, 1080); + cs.screenMatchMode = CanvasScaler.ScreenMatchMode.MatchWidthOrHeight; + + var cr = g.AddComponent(); + + foreach (UIItem uiItem in uiItems) + { + var i = uiItem.Build(); + i.transform.SetParent(g.transform); + } + + return g; + } + } + + public class UIItem + { + public string Name = String.Empty; + public GameObject GO = new GameObject(); + + public Vector2 Position = Vector2.zero; + public Vector2 Size = Vector2.zero; + public Vector2 Anchor = Vector2.zero; + public Vector2 Pivot = Vector2.zero; + public Vector2 Offset = Vector2.zero; + public Vector2 Rotation = Vector2.zero; + public Vector2 Scale = Vector2.one; + + public virtual GameObject Build() + { + GO.name = Name; + var RT = GO.AddComponent(); + RT.anchorMin = Anchor; + RT.anchorMax = Anchor; + RT.pivot = Pivot; + RT.anchoredPosition = Position + Offset; + RT.sizeDelta = Size; + RT.localScale = Scale; + RT.localPosition = Position; + RT.localRotation = Quaternion.Euler(Rotation); + + return GO; + } + } + + public class UIText : UIItem + { + public string Text = String.Empty; + public Font Font = Resources.GetBuiltinResource("Arial.ttf"); + public Color Color = Color.white; + public TextAnchor TextAnchor = TextAnchor.UpperLeft; + public TextAlignment TextAlignment = TextAlignment.Left; + public int FontSize = 12; + public bool RichText = false; + public bool RaycastTarget = false; + + public override GameObject Build() + { + GO = base.Build(); + + Text text = GO.AddComponent(); + text.text = Text; + text.font = Font; + text.color = Color; + text.alignment = TextAnchor; + text.alignment = (TextAnchor)TextAlignment; + text.fontSize = FontSize; + text.supportRichText = RichText; + text.raycastTarget = RaycastTarget; + + return GO; + } + } + + public class UIButton : UIItem + { + // Text + public string Text = String.Empty; + public Font Font = Resources.GetBuiltinResource("Arial.ttf"); + public Color Color = Color.white; + public TextAnchor TextAnchor = TextAnchor.UpperLeft; + public TextAlignment TextAlignment = TextAlignment.Left; + public int FontSize = 12; + public bool RichText = false; + public bool RaycastTarget = false; + + // Image + public Sprite Sprite = null; + + public override GameObject Build() + { + GO = base.Build(); + + var b = GO.AddComponent