Example #1
0
 public static void zero_margins(RectTransform rectTransform)
 {
     // anchors are set correctly, but margins are off. zero all margins to match anchor location
     RectTransformExtensions.SetLeft(rectTransform, 0);
     RectTransformExtensions.SetBottom(rectTransform, 0);
     RectTransformExtensions.SetRight(rectTransform, 0);
     RectTransformExtensions.SetTop(rectTransform, 0);
 }
        public void refresh()
        {
            Slider slider = GameObjectExtensions.AddOrGetComponent <Slider>(base.gameObject);

            slider.normalizedValue = 1f;
            if (this.Background != null)
            {
                this.Background.anchorMin     = Vector2.zero;
                this.Background.anchorMax     = Vector2.one;
                this.Background.pivot         = (Vector2)(Vector2.one * 0.5f);
                this.Background.localRotation = Quaternion.identity;
                this.Background.localScale    = Vector3.one;
            }
            if (this.ForegroundMask != null)
            {
                slider.fillRect                        = this.ForegroundMask;
                this.ForegroundMask.pivot              = (Vector2)(Vector2.one * 0.5f);
                this.ForegroundMask.localRotation      = Quaternion.identity;
                this.ForegroundMask.localScale         = Vector3.one;
                this.ForegroundMask.anchoredPosition3D = Vector3.zero;
                this.ForegroundMask.sizeDelta          = Vector2.zero;
                GameObjectExtensions.AddOrGetComponent <Mask>(this.ForegroundMask.gameObject).showMaskGraphic = false;
                Image image = GameObjectExtensions.AddOrGetComponent <Image>(this.ForegroundMask.gameObject);
                image.sprite = null;
                image.color  = new Color(0.9882353f, 0.2588235f, 0.8470588f, 0.3843137f);
            }
            if (this.Foreground != null)
            {
                this.Foreground.anchorMin          = Vector2.zero;
                this.Foreground.anchorMax          = Vector2.one;
                this.Foreground.pivot              = new Vector2(0f, 0.5f);
                this.Foreground.localRotation      = Quaternion.identity;
                this.Foreground.localScale         = Vector3.one;
                this.Foreground.anchoredPosition3D = new Vector3(this.ForegroundMargin, 0f, 0f);
                RectTransformExtensions.SetTop(this.Foreground, -this.ForegroundMargin);
                RectTransformExtensions.SetBottom(this.Foreground, this.ForegroundMargin);
                LayoutElement element = GameObjectExtensions.AddOrGetComponent <LayoutElement>(this.Foreground.gameObject);
                if ((this.ForegroundMask != null) && (this.ForegroundMask.rect.width > 0f))
                {
                    element.minWidth = this.ForegroundMask.rect.width - (this.ForegroundMargin * 2f);
                }
                ContentSizeFitter fitter = GameObjectExtensions.AddOrGetComponent <ContentSizeFitter>(this.Foreground.gameObject);
                fitter.horizontalFit = ContentSizeFitter.FitMode.MinSize;
                fitter.verticalFit   = ContentSizeFitter.FitMode.Unconstrained;
                GameObjectExtensions.AddOrGetComponent <Image>(this.Foreground.gameObject);
            }
        }
Example #3
0
        /// <summary>
        /// Instantiates a curve field UI object and adds it to the list.
        /// </summary>
        /// <param name="curve">The curve attached to this curve field.</param>
        /// <returns>The instantated gameobject's UIGraphField component.</returns>
        private UIGraphField InstantiateCurveField(Curve curve)
        {
            // Instantiate and get components
            var field          = Instantiate(unityCurveFieldPrefab);
            var fieldComponent = field.GetComponent <UIGraphField>();
            var rectComponent  = field.GetComponent <RectTransform>();

            // Update CurveField position, size, etc.
            field.transform.SetParent(transform);
            field.transform.localScale    = new Vector3(1, 1, 1);
            field.transform.localPosition = new Vector3(0, 0, 0);
            RectTransformExtensions.SetLeft(rectComponent, 0);
            RectTransformExtensions.SetRight(rectComponent, 0);
            RectTransformExtensions.SetTop(rectComponent, SPACING + (HEIGHT * Fields.Count - 1));
            rectComponent.sizeDelta = new Vector2(rectComponent.sizeDelta.x, HEIGHT);

            // Set up field curve and return
            fieldComponent.FieldCurve = curve;
            Fields.Add(fieldComponent);
            return(fieldComponent);
        }