Esempio n. 1
0
        public void CreateConsoleUI()
        {
            AssetBundle ab = AssetBundle.CreateFromMemoryImmediate(Properties.Resources.console);

            UI      = ab.LoadAsset <GameObject>("MSCLoader Console.prefab");
            UI      = Object.Instantiate(UI);
            UI.name = "MSCLoader Console";

            Texture2D cursor = ab.LoadAsset <Texture2D>("resizeCur.png");

            ab.Unload(false);

            console = UI.AddComponent <ConsoleView>();
            console.viewContainer = UI.transform.GetChild(0).gameObject;
            console.inputField    = console.viewContainer.transform.GetChild(0).gameObject.GetComponent <InputField>();
            console.viewContainer.transform.GetChild(1).gameObject.GetComponent <Button>().onClick.AddListener(() => console.runCommand());
            console.logTextArea = console.viewContainer.transform.GetChild(2).GetChild(0).gameObject.GetComponent <Text>();

            ConsoleUIResizer consoleResizer = console.viewContainer.transform.GetChild(4).gameObject.AddComponent <ConsoleUIResizer>();

            consoleResizer.logview   = console.viewContainer.transform.GetChild(2).gameObject;
            consoleResizer.scrollbar = console.viewContainer.transform.GetChild(3).gameObject;
            consoleResizer.cursor    = cursor;

            EventTrigger trigger = console.viewContainer.transform.GetChild(4).gameObject.GetComponent <EventTrigger>();

            EventTrigger.Entry entry = new EventTrigger.Entry {
                eventID = EventTriggerType.PointerEnter
            };
            entry.callback.AddListener((eventData) => { consoleResizer.OnMouseEnter(); });
            trigger.delegates.Add(entry);

            entry = new EventTrigger.Entry {
                eventID = EventTriggerType.PointerExit
            };
            entry.callback.AddListener((eventData) => { consoleResizer.OnMouseExit(); });
            trigger.delegates.Add(entry);

            UI.transform.SetParent(ModUI.GetCanvas().transform, false);
        }
Esempio n. 2
0
        public void CreateConsoleUI()
        {
            //Create parent gameobject for console.
            consoleObj = ModUI.CreateParent("MSCLoader Console", false);
            consoleObj.GetComponent <RectTransform>().anchorMin = new Vector2(0, 0);
            consoleObj.GetComponent <RectTransform>().anchorMax = new Vector2(0, 0);
            consoleObj.GetComponent <RectTransform>().pivot     = new Vector2(0, 0);
            consoleObj.GetComponent <RectTransform>().sizeDelta = new Vector2(346, 150);
            console = consoleObj.AddComponent <ConsoleView>();

            //Create console container
            GameObject consoleObjc = ModUI.CreateUIBase("MSCLoader ConsoleContainer", consoleObj);

            consoleObjc.GetComponent <RectTransform>().anchorMin = new Vector2(0, 0);
            consoleObjc.GetComponent <RectTransform>().anchorMax = new Vector2(1, 1);
            consoleObjc.GetComponent <RectTransform>().pivot     = new Vector2(0.5f, 0.5f);
            consoleObjc.GetComponent <RectTransform>().sizeDelta = new Vector2(0, 0);

            consoleObj.GetComponent <ConsoleView>().viewContainer = consoleObjc; //set viewContainer in ConsoleView.cs
            //console = consoleObj.GetComponent<ConsoleView>();

            //Create input field
            GameObject consoleInput = ModUI.CreateInputField("InputField", "Enter command...", consoleObjc, 322, 30);

            consoleInput.GetComponent <RectTransform>().anchorMin = new Vector2(0, 0);
            consoleInput.GetComponent <RectTransform>().anchorMax = new Vector2(0, 0);
            consoleInput.GetComponent <RectTransform>().pivot     = new Vector2(0, 0);
            consoleInput.GetComponent <InputField>().onEndEdit.AddListener(delegate { consoleObj.GetComponent <ConsoleView>().runCommand(); });

            consoleObj.GetComponent <ConsoleView>().inputField = consoleInput.GetComponent <InputField>();

            //Submit button
            GameObject enterBtn = ModUI.CreateButton("SubmitBtn", ">", consoleObjc, 24, 30);

            enterBtn.GetComponent <RectTransform>().anchorMin = new Vector2(1, 0);
            enterBtn.GetComponent <RectTransform>().anchorMax = new Vector2(1, 0);
            enterBtn.GetComponent <RectTransform>().pivot     = new Vector2(1, 0);
            enterBtn.GetComponent <Button>().onClick.AddListener(() => consoleObj.GetComponent <ConsoleView>().runCommand());

            //Log view text
            logView = ModUI.CreateUIBase("LogView", consoleObjc);
            logView.GetComponent <RectTransform>().anchorMin = new Vector2(0, 1);
            logView.GetComponent <RectTransform>().anchorMax = new Vector2(0, 1);
            logView.GetComponent <RectTransform>().pivot     = new Vector2(0, 1);
            logView.GetComponent <RectTransform>().sizeDelta = new Vector2(333, 120);
            logView.AddComponent <Image>().color             = Color.black;
            logView.AddComponent <Mask>().showMaskGraphic    = true;

            GameObject logViewTxt = ModUI.CreateTextBlock("LogText", ">", logView, TextAnchor.LowerLeft, Color.white, false);

            logViewTxt.GetComponent <RectTransform>().anchorMin       = new Vector2(0, 0);
            logViewTxt.GetComponent <RectTransform>().anchorMax       = new Vector2(1, 0);
            logViewTxt.GetComponent <RectTransform>().pivot           = new Vector2(0.5f, 0);
            logViewTxt.GetComponent <RectTransform>().sizeDelta       = new Vector2(0, 1425);
            logViewTxt.AddComponent <ContentSizeFitter>().verticalFit = ContentSizeFitter.FitMode.PreferredSize;

            consoleObj.GetComponent <ConsoleView>().logTextArea   = logViewTxt.GetComponent <Text>();
            logView.AddComponent <ScrollRect>().content           = logViewTxt.GetComponent <RectTransform>();
            logView.GetComponent <ScrollRect>().horizontal        = false;
            logView.GetComponent <ScrollRect>().inertia           = false;
            logView.GetComponent <ScrollRect>().movementType      = ScrollRect.MovementType.Clamped;
            logView.GetComponent <ScrollRect>().scrollSensitivity = 30f;

            //Scrollbar
            scrollbar = ModUI.CreateScrollbar(consoleObjc, 13, 120, Scrollbar.Direction.BottomToTop);
            scrollbar.GetComponent <RectTransform>().anchorMin        = new Vector2(1, 1);
            scrollbar.GetComponent <RectTransform>().anchorMax        = new Vector2(1, 1);
            scrollbar.GetComponent <RectTransform>().pivot            = new Vector2(0, 1);
            scrollbar.GetComponent <RectTransform>().anchoredPosition = new Vector2(-13, 0);

            logView.GetComponent <ScrollRect>().verticalScrollbar = scrollbar.GetComponent <Scrollbar>();
        }
Esempio n. 3
0
        public void CreateConsoleUI()
        {
            AssetBundle ab = LoadAssets.LoadBundle(this, "console.unity3d");

            UI = ab.LoadAsset <GameObject>("MSCLoader Console.prefab");
            Texture2D cursor  = ab.LoadAsset <Texture2D>("resizeCur.png");
            Texture2D cursorX = ab.LoadAsset <Texture2D>("resizeCurX.png");

            ab.Unload(false);
            UI      = Object.Instantiate(UI);
            UI.name = "MSCLoader Console";
            console = UI.AddComponent <ConsoleView>();
            console.viewContainer = UI.transform.GetChild(0).gameObject;
            console.inputField    = console.viewContainer.transform.GetChild(0)
                                    .gameObject.GetComponent <InputField>();
            console.viewContainer.transform.GetChild(1)
            .gameObject.GetComponent <Button>()
            .onClick.AddListener(() => console.runCommand());
            console.logTextArea = console.viewContainer.transform.GetChild(2)
                                  .GetChild(0)
                                  .gameObject.GetComponent <Text>();
            console.viewContainer.transform.GetChild(4)
            .gameObject.AddComponent <ConsoleUIResizer>()
            .logview = console.viewContainer.transform.GetChild(2).gameObject;
            console.viewContainer.transform.GetChild(4)
            .gameObject.GetComponent <ConsoleUIResizer>()
            .scrollbar = console.viewContainer.transform.GetChild(3).gameObject;
            console.viewContainer.transform.GetChild(4)
            .gameObject.GetComponent <ConsoleUIResizer>()
            .otherResizer = console.viewContainer.transform.GetChild(5).gameObject;
            console.viewContainer.transform.GetChild(4)
            .gameObject.GetComponent <ConsoleUIResizer>()
            .cursor = cursor;
            console.viewContainer.transform.GetChild(5)
            .gameObject.AddComponent <ConsoleUIResizer>()
            .inputField = console.viewContainer.transform.GetChild(0).gameObject;
            console.viewContainer.transform.GetChild(5)
            .gameObject.GetComponent <ConsoleUIResizer>()
            .submitBtn = console.viewContainer.transform.GetChild(1).gameObject;
            console.viewContainer.transform.GetChild(5)
            .gameObject.GetComponent <ConsoleUIResizer>()
            .logview = console.viewContainer.transform.GetChild(2).gameObject;
            console.viewContainer.transform.GetChild(5)
            .gameObject.GetComponent <ConsoleUIResizer>()
            .scrollbar = console.viewContainer.transform.GetChild(3).gameObject;
            console.viewContainer.transform.GetChild(5)
            .gameObject.GetComponent <ConsoleUIResizer>()
            .otherResizer = console.viewContainer.transform.GetChild(4).gameObject;
            console.viewContainer.transform.GetChild(5)
            .gameObject.GetComponent <ConsoleUIResizer>()
            .cursor = cursorX;
            console.viewContainer.transform.GetChild(5)
            .gameObject.GetComponent <ConsoleUIResizer>()
            .Xresizer = true;
            EventTrigger trigger = console.viewContainer.transform.GetChild(4)
                                   .gameObject.GetComponent <EventTrigger>();

            EventTrigger.Entry entry = new EventTrigger.Entry();
            entry.eventID = EventTriggerType.PointerEnter;
            entry.callback.AddListener((eventData) => {
                console.viewContainer.transform.GetChild(4)
                .gameObject.GetComponent <ConsoleUIResizer>()
                .OnMouseEnter();
            });
            trigger.delegates.Add(entry);
            entry         = new EventTrigger.Entry();
            entry.eventID = EventTriggerType.PointerExit;
            entry.callback.AddListener((eventData) => {
                console.viewContainer.transform.GetChild(4)
                .gameObject.GetComponent <ConsoleUIResizer>()
                .OnMouseExit();
            });
            trigger.delegates.Add(entry);
            trigger = console.viewContainer.transform.GetChild(5)
                      .gameObject.GetComponent <EventTrigger>();
            entry         = new EventTrigger.Entry();
            entry.eventID = EventTriggerType.PointerEnter;
            entry.callback.AddListener((eventData) => {
                console.viewContainer.transform.GetChild(5)
                .gameObject.GetComponent <ConsoleUIResizer>()
                .OnMouseEnter();
            });
            trigger.delegates.Add(entry);
            entry         = new EventTrigger.Entry();
            entry.eventID = EventTriggerType.PointerExit;
            entry.callback.AddListener((eventData) => {
                console.viewContainer.transform.GetChild(5)
                .gameObject.GetComponent <ConsoleUIResizer>()
                .OnMouseExit();
            });
            trigger.delegates.Add(entry);
            UI.transform.SetParent(ModUI.GetCanvas().transform, false);
        }