示例#1
0
        //======================
        //Vector3
        //======================
        public UIVector3 CreateVector3(float posX, float posY, Transform parent, string name = "")
        {
            GameObject uiParent = new GameObject("ModVector3");

            uiParent.transform.SetParent(parent, false);
            uiParent.transform.localPosition = new Vector3(posX, posY, 0f);
            UIListExplorer explorer = UIFactory.Instance.CreateListExplorer(0f, 0.75f, uiParent.transform, name); //Create the UIElement

            explorer.ExplorerArray = new string[] { "All directions", "X", "Y", "Z" };                            //Create a string[] for the explorer
            explorer.ScaleBackground(0.8f);
            explorer.name         = "Vector3Explorer";
            explorer.AllowLooping = true;

            UISlider slider = UIFactory.Instance.CreateSlider(0f, 0f, uiParent.transform, ""); //Create the slider

            slider.name = "Vector3Slider";
            slider.SetSlider(0.01f, 10f, 0.01f, 1f, true, 1f);

            //Assign component
            UIVector3 output = uiParent.AddComponent <UIVector3>();

            output.Initialize();

            return(output);
        }
示例#2
0
 public void Initialize()
 {
     _value = Vector3.one;
     //Set TextMesh, slidable and textframe
     _slider                  = gameObject.GetComponentInChildren <UISlider>();
     _explorer                = gameObject.GetComponentInChildren <UIListExplorer>();
     nameTextMesh             = _slider.NameTextMesh;
     _slider.onInteraction   += SliderActivated;
     _explorer.onInteraction += ExplorerActivated;
 }
示例#3
0
        //======================
        //Utility functions
        //======================
        //Popup frame
        //Only works with UIButton, UIGfxButton, UICheckbox, UISlider and UIListExplorer
        public UITextFrame CreatePopupFrame(float x, float y, UIElement hover, Transform parent, string text)
        {
            if (!(hover is UIButton) && !(hover is UIGFXButton) && !(hover is UICheckBox) && !(hover is UISlider) && !(hover is UIListExplorer))
            {
                return(null);
            }

            UITextFrame textFrame = UIFactory.Instance.CreateTextFrame(x, y, parent.transform, text);

            textFrame.gameObject.SetActive(false);
            List <UIElement> applyTo = new List <UIElement>();

            if (hover is UIListExplorer)
            {
                UIListExplorer explorer = (UIListExplorer)hover;
                applyTo.Add(explorer.LeftArrow);
                applyTo.Add(explorer.RightArrow);
            }
            else
            {
                applyTo.Add(hover);
            }

            for (int i = 0; i < applyTo.Count; i++)
            {
                GuiSelectionObject hoverSelection = applyTo[i].gameObject.GetComponentInChildren <GuiSelectionObject>();

                bool oldState = false;
                applyTo[i].onUpdate += delegate()
                {
                    if (hoverSelection.IsSelected == oldState)
                    {
                        return;
                    }
                    oldState = hoverSelection.IsSelected;
                    textFrame.gameObject.SetActive(oldState);
                };
            }

            return(textFrame);
        }
示例#4
0
        //======================
        //ListExplorer
        //======================
        public UIListExplorer CreateListExplorer(float posX, float posY, Transform parent, string name = "")
        {
            //Create parent GO and set it up
            GameObject uiParent = new GameObject("ModListExplorer");

            uiParent.transform.SetParent(parent, false);
            uiParent.transform.localScale    = Vector3.one;
            uiParent.transform.localPosition = new Vector3(posX, posY, 0f);

            //Create display
            UITextFrame display = CreateTextFrame(0, 0, uiParent.transform);

            display.name = "Display";
            display.transform.localPosition = ZFixVector;

            //Left  arrow
            //--------------
            //Create arrow button, position and name it
            UIButton leftArrow = CreateButton(UIButton.ButtonType.Default, 0, 0, uiParent.transform, "");

            leftArrow.name = "LeftArrow";
            leftArrow.transform.localScale    = new Vector3(0.4f, 0.8f, 1f);
            leftArrow.transform.localPosition = new Vector3(-1.8f, 0f, -0.2f);
            //Replace gfx and position it
            SearchArrows(); //Search for arrows gfx
            Destroy(leftArrow.transform.Find("ModUIElement").Find("Root").Find("Background").gameObject);
            GameObject lArrow = Instantiate(leftArrowOriginal, leftArrow.transform.Find("ModUIElement").Find("Root"));

            lArrow.transform.localScale    = new Vector3(2f, 1f, 1f);
            lArrow.transform.localPosition = new Vector3(-0.5f, 0f, 0f);
            //Remove logic components from the gfx
            Destroy(lArrow.GetComponent <GuiClickable>());
            Destroy(lArrow.GetComponent <GuiClickRect>());
            Destroy(lArrow.GetComponent <GuiChangeEffect_ClickUpdSlider>());

            //Right arrow
            //--------------
            //Create arrow button, position and name it
            UIButton rightArrow = CreateButton(UIButton.ButtonType.Default, 0, 0, uiParent.transform, "");

            rightArrow.name = "RightArrow";
            rightArrow.transform.localScale    = new Vector3(0.4f, 0.8f, 1f);
            rightArrow.transform.localPosition = new Vector3(1.8f, 0f, -0.2f);
            //Replace gfx and position it
            Destroy(rightArrow.transform.Find("ModUIElement").Find("Root").Find("Background").gameObject);
            GameObject rArrow = Instantiate(rightArrowOriginal, rightArrow.transform.Find("ModUIElement").Find("Root"));

            rArrow.transform.localScale       = new Vector3(-2f, 1f, 1f); //The -2 flips the gfx horizontally
            rArrow.transform.localPosition    = new Vector3(0.5f, 0f, 0f);
            rArrow.transform.localEulerAngles = Vector3.zero;
            //Remove logic components from the gfx
            Destroy(rArrow.GetComponent <GuiClickable>());
            Destroy(rArrow.GetComponent <GuiClickRect>());
            Destroy(rArrow.GetComponent <GuiChangeEffect_ClickUpdSlider>());

            //Create title
            UITextFrame title = CreateTextFrame(0f, 0f, uiParent.transform);

            title.name = "UIName";
            title.transform.localPosition = new Vector3(0f, 0.65f, 0.6f);
            title.transform.localScale   *= 0.8f;
            title.ScaleText(1.25f);
            title.ScaleBackground(new Vector2(0.625f, 1f));

            //Assign component
            UIListExplorer output = uiParent.AddComponent <UIListExplorer>();

            output.Initialize();
            output.UIName = name;

            return(output);
        }