Exemplo n.º 1
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)
                    );
            }
        }
Exemplo n.º 2
0
 public static void SetParent(int childId, int parentId)
 {
     ObjectBuilder.Get(childId).transform.SetParent(ObjectBuilder.Get(parentId).transform);
 }
Exemplo n.º 3
0
 public static DynValue Instantiate(string path)
 {
     return(ObjectBuilder.InstantiateUIElement(path));
 }
Exemplo n.º 4
0
 public static InputField GetInputField(int id)
 {
     return(ObjectBuilder.Get(id).GetComponentInChildren <InputField>());
 }
Exemplo n.º 5
0
        public static void SetSizeDelta(int id, float x, float y)
        {
            var transform = ObjectBuilder.Get(id).GetComponent <RectTransform>();

            transform.sizeDelta = new Vector2(x, y);
        }
Exemplo n.º 6
0
        public static void SetPosition(int id, float x, float y)
        {
            var transform = ObjectBuilder.Get(id).GetComponent <RectTransform>();

            transform.anchoredPosition = new Vector2(x, y);
        }
Exemplo n.º 7
0
 public static void SetPivot(int id, float x, float y)
 {
     ObjectBuilder.Get(id).GetComponent <RectTransform>().pivot = new Vector2(x, y);
 }
Exemplo n.º 8
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;
            }
        }