Ejemplo n.º 1
0
        public CanvasPanel AddPanel(string name, Texture2D tex, Vector2 pos, Vector2 sz, Rect bgSubSection)
        {
            CanvasPanel panel = new CanvasPanel(canvas, tex, position + pos, sz, bgSubSection);

            panels.Add(name, panel);

            return(panel);
        }
Ejemplo n.º 2
0
        public CanvasButton(GameObject parent, string name, Texture2D tex, Vector2 pos, Vector2 size, Rect bgSubSection, CanvasPanel panel, Font font = null, string text = null, int fontSize = 13)
        {
            if (size.x == 0 || size.y == 0)
            {
                size = new Vector2(bgSubSection.width, bgSubSection.height);
            }

            _canvas = panel;

            buttonName = name;

            buttonObj = new GameObject("Canvas Button - " + name);
            buttonObj.AddComponent <CanvasRenderer>();
            RectTransform buttonTransform = buttonObj.AddComponent <RectTransform>();

            buttonTransform.sizeDelta = new Vector2(bgSubSection.width, bgSubSection.height);
            buttonObj.AddComponent <Image>().sprite = Sprite.Create(tex, new Rect(bgSubSection.x, tex.height - bgSubSection.height, bgSubSection.width, bgSubSection.height), Vector2.zero);
            button = buttonObj.AddComponent <Button>();

            buttonObj.transform.SetParent(parent.transform, false);

            buttonTransform.SetScaleX(size.x / bgSubSection.width);
            buttonTransform.SetScaleY(1.0f);//size.y / bgSubSection.height);

            Vector2 position = new Vector2((pos.x + ((size.x / bgSubSection.width) * bgSubSection.width) / 2f) / Screen.width, (Screen.height - (pos.y + ((size.y / bgSubSection.height) * bgSubSection.height) / 2f)) / Screen.height);

            buttonTransform.anchorMin = position;
            buttonTransform.anchorMax = position;

            Object.DontDestroyOnLoad(buttonObj);

            if (font != null && text != null)
            {
                textObj = new GameObject("Canvas Button Text - " + name);
                textObj.AddComponent <RectTransform>().sizeDelta = new Vector2(bgSubSection.width, bgSubSection.height);
                Text t = textObj.AddComponent <Text>();
                t.text      = text;
                t.font      = font;
                t.fontSize  = fontSize;
                t.alignment = TextAnchor.MiddleCenter;
                Outline outline = textObj.AddComponent <Outline>();
                outline.effectColor = Color.black;
                textObj.transform.SetParent(buttonObj.transform, false);

                Object.DontDestroyOnLoad(textObj);
            }

            active = true;
        }
Ejemplo n.º 3
0
        public static void BuildMenu(GameObject canvas)
        {
            Texture2D buttonImg = GUIController.Instance.images["Button_BG"];
            Texture2D inputImg  = GUIController.Instance.images["Input_BG"];
            Texture2D panelImg  = GUIController.Instance.images["Panel_BG"];

            float x = Screen.width / 2.0f - inputImg.width / 2.0f - 30.0f;
            float y = 30.0f;

            EventSystem eventSystem = null;

            if (!GameObject.Find("EventSystem"))
            {
                GameObject eventSystemObj = new GameObject("EventSystem");

                eventSystem = eventSystemObj.AddComponent <EventSystem>();
                eventSystem.sendNavigationEvents = true;
                eventSystem.pixelDragThreshold   = 10;

                eventSystemObj.AddComponent <StandaloneInputModule>();

                Object.DontDestroyOnLoad(eventSystemObj);
            }

            Panel = new CanvasPanel(
                canvas,
                panelImg,
                new Vector2(x, y),
                Vector2.zero,
                new Rect(0, 0, panelImg.width, panelImg.height)
                );

            Panel.AddText(
                "Connection Text",
                "Connection",
                new Vector2(x, y),
                new Vector2(buttonImg.width, buttonImg.height),
                GUIController.Instance.trajanNormal,
                24,
                FontStyle.Bold,
                TextAnchor.MiddleCenter
                );
            y += buttonImg.height + 10;

            _ipInput = Panel.AddInput(
                "IP Input",
                inputImg,
                new Vector2(x, y),
                Vector2.zero,
                new Rect(0, y, inputImg.width, inputImg.height),
                GUIController.Instance.trajanNormal,
                MultiplayerClient.settings.host, "Address",
                16
                );
            y += inputImg.height + 5;

            _portInput = Panel.AddInput(
                "Port Input",
                inputImg,
                new Vector2(x, y),
                Vector2.zero,
                new Rect(0, y, inputImg.width, inputImg.height),
                GUIController.Instance.trajanNormal,
                MultiplayerClient.settings.port.ToString(), "Port",
                16
                );
            y += inputImg.height + 5;

            _usernameInput = Panel.AddInput(
                "Username Input",
                inputImg,
                new Vector2(x, y),
                Vector2.zero,
                new Rect(0, y, inputImg.width, inputImg.height),
                GUIController.Instance.trajanNormal,
                MultiplayerClient.settings.username, "Username",
                16
                );
            y += inputImg.height + 5;

            _connectButton = Panel.AddButton(
                "Connect Button",
                buttonImg,
                new Vector2(x, y),
                Vector2.zero,
                ToggleConnectToServer,
                new Rect(0, y, buttonImg.width, buttonImg.height),
                GUIController.Instance.trajanNormal,
                "Connect",
                16
                );
            y += buttonImg.height;


            _connectionInfo = new CanvasText(
                canvas,
                new Vector2(Screen.width / 2 - 500, Screen.height - 70),
                new Vector2(1000.0f, 50.0f),
                GUIController.Instance.trajanBold, "Disconnected.",
                fontSize: 42, alignment: TextAnchor.UpperCenter
                );

            if (eventSystem != null)
            {
                eventSystem.firstSelectedGameObject = _ipInput.InputObject;
            }

            _connectionInfo.SetActive(false);
            Panel.SetActive(false, true);

            On.HeroController.Pause   += OnPause;
            On.HeroController.UnPause += OnUnPause;
            UnityEngine.SceneManagement.SceneManager.activeSceneChanged += OnSceneChange;
        }
Ejemplo n.º 4
0
        public static void BuildMenu(GameObject canvas)
        {
            Texture2D buttonImg = GUIController.Instance.images["Button_BG"];
            Texture2D inputImg  = GUIController.Instance.images["Input_BG"];
            Texture2D panelImg  = GUIController.Instance.images["Panel_BG"];
            Texture2D teamImg   = GUIController.Instance.images["Team_BG"];
            Texture2D chatImg   = GUIController.Instance.images["Chat_BG"];
            Texture2D sendImg   = GUIController.Instance.images["Send_BG"];
            Texture2D toggleImg = GUIController.Instance.images["Toggle_BG"];
            Texture2D checkImg  = GUIController.Instance.images["Checkmark"];

            float x  = Screen.width / 2.0f - inputImg.width / 2.0f - 30.0f;
            float x2 = x - inputImg.width + 10f;
            float x3 = x - inputImg.width + 30f;
            float y  = 30.0f;
            float y2 = y;

            EventSystem eventSystem = null;

            if (!GameObject.Find("EventSystem"))
            {
                GameObject eventSystemObj = new GameObject("EventSystem");

                eventSystem = eventSystemObj.AddComponent <EventSystem>();
                eventSystem.sendNavigationEvents = true;
                eventSystem.pixelDragThreshold   = 10;

                eventSystemObj.AddComponent <StandaloneInputModule>();

                Object.DontDestroyOnLoad(eventSystemObj);
            }

            Panel = new CanvasPanel(
                canvas,
                panelImg,
                new Vector2(x, y),
                Vector2.zero,
                new Rect(0, 0, panelImg.width, panelImg.height)
                );

            Panel.AddText(
                "Connection Text",
                "Connection",
                new Vector2(x, y),
                new Vector2(buttonImg.width, buttonImg.height),
                GUIController.Instance.trajanNormal,
                24,
                FontStyle.Bold,
                TextAnchor.MiddleCenter
                );
            y += buttonImg.height + 10;

            _ipInput = Panel.AddInput(
                "IP Input",
                inputImg,
                new Vector2(x, y),
                Vector2.zero,
                new Rect(0, y, inputImg.width, inputImg.height),
                GUIController.Instance.trajanNormal,
                MultiplayerClient.settings.host, "Address",
                16
                );
            y += inputImg.height + 5;

            _portInput = Panel.AddInput(
                "Port Input",
                inputImg,
                new Vector2(x, y),
                Vector2.zero,
                new Rect(0, y, inputImg.width, inputImg.height),
                GUIController.Instance.trajanNormal,
                MultiplayerClient.settings.port.ToString(), "Port",
                16
                );
            y += inputImg.height + 5;

            _usernameInput = Panel.AddInput(
                "Username Input",
                inputImg,
                new Vector2(x, y),
                Vector2.zero,
                new Rect(0, y, inputImg.width, inputImg.height),
                GUIController.Instance.trajanNormal,
                MultiplayerClient.settings.username, "Username",
                16
                );
            y += inputImg.height + 5;

            /*Panel.AddText(
             *  "Team Text",
             *  "Teams",
             *  new Vector2(x, y),
             *  new Vector2(buttonImg.width, buttonImg.height),
             *  GUIController.Instance.trajanNormal,
             *  24,
             *  FontStyle.Bold,
             *  TextAnchor.MiddleCenter
             * );
             * y += buttonImg.height + 10;
             *
             * TeamButton = Panel.AddButton(
             *  "Team Button",
             *  teamImg,
             *  new Vector2(x, y),
             *  Vector2.zero,
             *  ToggleTeam,
             *  new Rect(0, y, teamImg.width, teamImg.height),
             *  GUIController.Instance.trajanNormal,
             *  "None",
             *  16
             * );
             * y += teamImg.height + 5;*/

            ConnectButton = Panel.AddButton(
                "Connect Button",
                buttonImg,
                new Vector2(x, y),
                Vector2.zero,
                ToggleConnectToServer,
                new Rect(0, y, buttonImg.width, buttonImg.height),
                GUIController.Instance.trajanNormal,
                "Connect",
                16
                );
            y += buttonImg.height;

            _chatInput = Panel.AddInput(
                "Chat Input",
                chatImg,
                new Vector2(x - 25, y),
                Vector2.zero,
                new Rect(0, y, chatImg.width, chatImg.height),
                GUIController.Instance.trajanNormal,
                "", "Chat",
                16
                );

            SendButton = Panel.AddButton(
                "Send Button",
                sendImg,
                new Vector2(x + chatImg.width - 23, y),
                Vector2.zero,
                SendMessage,
                new Rect(0, y, sendImg.width, sendImg.height),
                GUIController.Instance.trajanNormal,
                "",
                16
                );
            y += chatImg.height + 5;

            ConnectionInfo = new CanvasText(
                canvas,
                new Vector2(Screen.width / 2 - 500, Screen.height - 70),
                new Vector2(1000.0f, 50.0f),
                GUIController.Instance.trajanBold, "Disconnected.",
                fontSize: 42, alignment: TextAnchor.UpperCenter
                );

            WPanel = new CanvasPanel(
                canvas,
                panelImg,
                new Vector2(x2, y2),
                Vector2.zero,
                new Rect(0, 0, panelImg.width, panelImg.height)
                );

            WPanel.AddText(
                "World Text",
                "World Options",
                new Vector2(x2, y2),
                new Vector2(buttonImg.width, buttonImg.height),
                GUIController.Instance.trajanNormal,
                24,
                FontStyle.Bold,
                TextAnchor.MiddleCenter
                );
            y2 += buttonImg.height + 10;

            WOverwrite = WPanel.AddToggle(
                "Toggle Overwrite",
                toggleImg,
                checkImg,
                new Vector2(x2, y2),
                new Vector2(panelImg.width, 20),
                new Vector2(-60, 0),
                new Rect(0, 0, 150, 20),
                (bool b) => SessionManager.Instance.OverwriteSave = b,
                GUIController.Instance.trajanNormal,
                "Overwrite Save",
                16
                );
            y2 += buttonImg.height + 5;
            void Sync(bool b)
            {
                if (Client.Instance.isConnected)
                {
                    SessionManager.Instance.WSyncClientEnabled = b;
                    Log("WSync = " + SessionManager.Instance.WSyncClientEnabled);
                    //WSync.Remove();
                }
            }

            WSync = WPanel.AddToggle(
                "Toggle World Sync",
                toggleImg,
                checkImg,
                new Vector2(x2, y2),
                new Vector2(panelImg.width, 20),
                new Vector2(-60, 0),
                new Rect(0, 0, 150, 20),
                Sync,
                GUIController.Instance.trajanNormal,
                "World Sync",
                16
                );
            y2 += 30;

            void Download(string s)
            {
                if (Client.Instance.isConnected)
                {
                    ClientSend.DownloadSave();
                    SessionManager.Instance.WDownloadClientEnabled = true;
                    //WDownload.Remove();
                }
            }

            WDownload = WPanel.AddButton(
                "Download Button",
                teamImg,
                new Vector2(x2, y2),
                Vector2.zero,
                Download,
                new Rect(0, y2, teamImg.width, teamImg.height),
                GUIController.Instance.trajanNormal,
                "Download World",
                16
                );
            y2 += 40;


            PPanel = new CanvasPanel(
                canvas,
                panelImg,
                new Vector2(x3, y2),
                Vector2.zero,
                new Rect(0, 0, panelImg.width, panelImg.height)
                );

            PPanel.AddText(
                "Pins Text",
                "Pins",
                new Vector2(x3, y2),
                new Vector2(buttonImg.width, buttonImg.height),
                GUIController.Instance.trajanNormal,
                24,
                FontStyle.Bold,
                TextAnchor.MiddleCenter
                );
            y2 += buttonImg.height + 10;

            PSend = PPanel.AddToggle(
                "Toggle Pin Send",
                toggleImg,
                checkImg,
                new Vector2(x3, y2),
                new Vector2(panelImg.width, 20),
                new Vector2(-60, 0),
                new Rect(0, 0, 150, 20),
                ClientSend.DoSyncPins,
                GUIController.Instance.trajanNormal,
                "Sync Pin",
                16
                );
            y2 += 30;

            PSend = PPanel.AddToggle(
                "Toggle Pin Recieve",
                toggleImg,
                checkImg,
                new Vector2(x3, y2),
                new Vector2(panelImg.width, 20),
                new Vector2(-60, 0),
                new Rect(0, 0, 150, 20),
                (bool b) => SessionManager.Instance.RecievePins = b,
                GUIController.Instance.trajanNormal,
                "Show Pins",
                16
                );

            if (eventSystem != null)
            {
                eventSystem.firstSelectedGameObject = _ipInput.InputObject;
            }

            ConnectionInfo.SetActive(false);
            Panel.SetActive(false, true);
            WPanel.SetActive(false, true);
            PPanel.SetActive(false, true);

            On.HeroController.Pause   += OnPause;
            On.HeroController.UnPause += OnUnPause;
            UnityEngine.SceneManagement.SceneManager.activeSceneChanged += OnSceneChange;
        }