Ejemplo n.º 1
0
        public static void SetHeight(int id, float height)
        {
            var transform = ObjectBuilder.Get(id).GetComponent <RectTransform>();

            transform.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, height);
            Canvas.ForceUpdateCanvases();
        }
Ejemplo n.º 2
0
        public static void AddOnClick(int id, DynValue function)
        {
            var go     = ObjectBuilder.Get(id);
            var button = go.GetComponent <Button>();

            button.onClick.AddListener(() => { LuaManager.GlobalScript.Call(function); });
        }
Ejemplo n.º 3
0
        public static void SetWidth(int id, float width)
        {
            var transform = ObjectBuilder.Get(id).GetComponent <RectTransform>();

            transform.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, width);
            Canvas.ForceUpdateCanvases();
        }
Ejemplo n.º 4
0
        public static void ClearOnClick(int id)
        {
            var go     = ObjectBuilder.Get(id);
            var button = go.GetComponent <Button>();

            button.onClick.RemoveAllListeners();
        }
Ejemplo n.º 5
0
        public static void SetAnchors(int id, float minX, float maxX, float minY, float maxY)
        {
            var go        = ObjectBuilder.Get(id);
            var transform = go.GetComponent <RectTransform>();

            transform.anchorMin = new Vector2(minX, minY);
            transform.anchorMax = new Vector2(maxX, maxY);
        }
Ejemplo n.º 6
0
        public static int CreateLuaObject(string path)
        {
            var id        = ObjectBuilder.InstantiateUIElement();
            var component = ObjectBuilder.Get((int)id.Number).AddComponent <LuaObjectComponent>();

            component.Load(path);
            return((int)id.Number);
        }
Ejemplo n.º 7
0
        public static int CreateSlider(string settingsKey)
        {
            var id     = (int)Instantiate("SliderSetting").Number;
            var go     = ObjectBuilder.Get(id);
            var slider = go.GetComponent <SliderSetting>();

            slider.SetKey(settingsKey);
            return(id);
        }
Ejemplo n.º 8
0
        public static Vector3[] GetWorldCorners(int id)
        {
            var go            = ObjectBuilder.Get(id);
            var rectTransform = go.GetComponent <RectTransform>();
            var corners       = new Vector3[4];

            rectTransform.GetWorldCorners(corners);
            return(corners);
        }
Ejemplo n.º 9
0
        public static void SetAllTexts(int id, string str)
        {
            var go    = ObjectBuilder.Get(id);
            var texts = go.GetComponentsInChildren <Text>();

            foreach (var text in texts)
            {
                text.text = str;
            }
        }
Ejemplo n.º 10
0
        public static void SetColor(int id, int r, int g, int b, int a = 255)
        {
            var go    = ObjectBuilder.Get(id);
            var image = go.GetComponentInChildren <Image>();

            if (image != null)
            {
                image.color = new Color(r / 255.0f, g / 255.0f, b / 255.0f, a / 255.0f);
            }
        }
Ejemplo n.º 11
0
        public static void SetTextAlignment(int id, string anchor)
        {
            var go   = ObjectBuilder.Get(id);
            var text = go.GetComponent <Text>();

            if (text != null)
            {
                Enum.TryParse(anchor, out TextAnchor result);
                text.alignment = result;
            }
        }
Ejemplo n.º 12
0
        public static void SetText(int id, string str)
        {
            var go   = ObjectBuilder.Get(id);
            var text = go.GetComponentInChildren <Text>();

            if (text == null)
            {
                InGameDebug.Log("GameObject has no Text component, nor have any of its children.");
            }
            else
            {
                text.text = str;
            }
        }
Ejemplo n.º 13
0
        public static void SetFont(int id, string fontName)
        {
            var go   = ObjectBuilder.Get(id);
            var text = go.GetComponentInChildren <Text>();

            if (text == null)
            {
                InGameDebug.Log("GameObject has no Text component, nor have any of its children.");
            }
            else
            {
                text.font = Resources.Load <Font>("Fonts/" + fontName);
            }
        }
Ejemplo n.º 14
0
        public static void SetTextColor(int id, int r, int g, int b, int a)
        {
            var go   = ObjectBuilder.Get(id);
            var text = go.GetComponentInChildren <Text>();

            if (text == null)
            {
                InGameDebug.Log("GameObject has no Text component, nor have any of its children.");
            }
            else
            {
                text.color = new Color(r / 255.0f, g / 255.0f, b / 255.0f, a / 255.0f);
            }
        }
Ejemplo n.º 15
0
        public static void SetFontSize(int id, int size)
        {
            var go   = ObjectBuilder.Get(id);
            var text = go.GetComponentInChildren <Text>();

            if (text == null)
            {
                InGameDebug.Log("GameObject has no Text component, nor have any of its children.");
            }
            else
            {
                text.fontSize = size;
            }
        }
Ejemplo n.º 16
0
        private static void AddEventTriggerEntry(int id, DynValue function, EventTriggerType type)
        {
            var go      = ObjectBuilder.Get(id);
            var trigger = go.GetComponent <EventTrigger>();

            if (trigger == null)
            {
                trigger = go.AddComponent <EventTrigger>();
            }
            var entry = new EventTrigger.Entry();

            entry.eventID = type;
            entry.callback.AddListener(_ => LuaManager.Call(function));
            trigger.triggers.Add(entry);
        }
Ejemplo n.º 17
0
        public static void SetPivot(int id, string presetStr)
        {
            var preset    = Enum.Parse(typeof(PivotPreset), presetStr);
            var go        = ObjectBuilder.Get(id);
            var transform = go.GetComponent <RectTransform>();

            switch (preset)
            {
            case PivotPreset.TopLeft:
                transform.pivot = new Vector2(0.0f, 1.0f);
                break;

            case PivotPreset.TopCenter:
                transform.pivot = new Vector2(0.5f, 1.0f);
                break;

            case PivotPreset.TopRight:
                transform.pivot = new Vector2(1.0f, 1.0f);
                break;

            case PivotPreset.MiddleLeft:
                transform.pivot = new Vector2(0.0f, 0.5f);
                break;

            case PivotPreset.MiddleCenter:
                transform.pivot = new Vector2(0.5f, 0.5f);
                break;

            case PivotPreset.MiddleRight:
                transform.pivot = new Vector2(1.0f, 0.5f);
                break;

            case PivotPreset.BottomLeft:
                transform.pivot = new Vector2(0.0f, 0.0f);
                break;

            case PivotPreset.BottomCenter:
                transform.pivot = new Vector2(0.5f, 0.0f);
                break;

            case PivotPreset.BottomRight:
                transform.pivot = new Vector2(1.0f, 0.0f);
                break;
            }
        }
Ejemplo n.º 18
0
        public static void SetImage(int id, string key)
        {
            var go    = ObjectBuilder.Get(id);
            var image = go.GetComponentInChildren <Image>();

            if (image == null)
            {
                image = go.AddComponent <Image>();
            }
            if (key == null)
            {
                image.sprite = null;
            }
            else
            {
                var texture = StreamingAssetsDatabase.GetTexture(key);
                image.sprite = Sprite.Create(
                    texture,
                    new Rect(0, 0, texture.width, texture.height),
                    new Vector2(0.5f, 0.5f)
                    );
            }
        }
Ejemplo n.º 19
0
 public static InputField GetInputField(int id)
 {
     return(ObjectBuilder.Get(id).GetComponentInChildren <InputField>());
 }
Ejemplo n.º 20
0
 public static void SetPivot(int id, float x, float y)
 {
     ObjectBuilder.Get(id).GetComponent <RectTransform>().pivot = new Vector2(x, y);
 }
Ejemplo n.º 21
0
        public static void SetPosition(int id, float x, float y)
        {
            var transform = ObjectBuilder.Get(id).GetComponent <RectTransform>();

            transform.anchoredPosition = new Vector2(x, y);
        }
Ejemplo n.º 22
0
        public static void SetSizeDelta(int id, float x, float y)
        {
            var transform = ObjectBuilder.Get(id).GetComponent <RectTransform>();

            transform.sizeDelta = new Vector2(x, y);
        }
Ejemplo n.º 23
0
 public static void SetParent(int childId, int parentId)
 {
     ObjectBuilder.Get(childId).transform.SetParent(ObjectBuilder.Get(parentId).transform);
 }
Ejemplo n.º 24
0
        public static void SetAnchor(int id, string presetStr)
        {
            var preset    = Enum.Parse(typeof(AnchorPreset), presetStr);
            var go        = ObjectBuilder.Get(id);
            var transform = go.GetComponent <RectTransform>();

            switch (preset)
            {
            case AnchorPreset.TopLeft:
                transform.anchorMin = new Vector2(0.0f, 1.0f);
                transform.anchorMax = transform.anchorMin;
                break;

            case AnchorPreset.TopCenter:
                transform.anchorMin = new Vector2(0.5f, 1.0f);
                transform.anchorMax = transform.anchorMin;
                break;

            case AnchorPreset.TopRight:
                transform.anchorMin = new Vector2(1.0f, 1.0f);
                transform.anchorMax = transform.anchorMin;
                break;

            case AnchorPreset.MiddleLeft:
                transform.anchorMin = new Vector2(0.0f, 0.5f);
                transform.anchorMax = transform.anchorMin;
                break;

            case AnchorPreset.MiddleCenter:
                transform.anchorMin = new Vector2(0.5f, 0.5f);
                transform.anchorMax = transform.anchorMin;
                break;

            case AnchorPreset.MiddleRight:
                transform.anchorMin = new Vector2(1.0f, 0.5f);
                transform.anchorMax = transform.anchorMin;
                break;

            case AnchorPreset.BottomLeft:
                transform.anchorMin = new Vector2(0.0f, 0.0f);
                transform.anchorMax = transform.anchorMin;
                break;

            case AnchorPreset.BottomCenter:
                transform.anchorMin = new Vector2(0.5f, 0.0f);
                transform.anchorMax = transform.anchorMin;
                break;

            case AnchorPreset.BottomRight:
                transform.anchorMin = new Vector2(1.0f, 0.0f);
                transform.anchorMax = transform.anchorMin;
                break;

            case AnchorPreset.VerticalStretchLeft:
                transform.anchorMin = new Vector2(0.0f, 0.0f);
                transform.anchorMax = new Vector2(0.0f, 1.0f);
                break;

            case AnchorPreset.VerticalStretchCenter:
                transform.anchorMin = new Vector2(0.5f, 0.0f);
                transform.anchorMax = new Vector2(0.5f, 1.0f);
                break;

            case AnchorPreset.VerticalStretchRight:
                transform.anchorMin = new Vector2(1.0f, 0.0f);
                transform.anchorMax = new Vector2(1.0f, 1.0f);
                break;

            case AnchorPreset.HorizontalStretchTop:
                transform.anchorMin = new Vector2(0.0f, 1.0f);
                transform.anchorMax = new Vector2(1.0f, 1.0f);
                break;

            case AnchorPreset.HorizontalStretchMiddle:
                transform.anchorMin = new Vector2(0.0f, 0.5f);
                transform.anchorMax = new Vector2(1.0f, 0.5f);
                break;

            case AnchorPreset.HorizontalStretchBottom:
                transform.anchorMin = new Vector2(0.0f, 0.0f);
                transform.anchorMax = new Vector2(1.0f, 0.0f);
                break;

            case AnchorPreset.StretchAll:
                transform.anchorMin = new Vector2(0.0f, 0.0f);
                transform.anchorMax = new Vector2(1.0f, 1.0f);
                break;
            }
        }