Пример #1
0
        public UICurveEditor(UIDynamic container, float width, float height, List <UIDynamicButton> buttons = null, UICurveEditorColors colors = null, bool readOnly = false)
        {
            var buttonContainerHeight = (buttons == null || buttons.Count == 0) ? 0 : 25;

            this.container = container;

            _colors = colors ?? new UICurveEditorColors();

            gameObject = new GameObject();
            gameObject.transform.SetParent(container.transform, false);

            var mask = gameObject.AddComponent <RectMask2D>();

            mask.rectTransform.anchoredPosition = new Vector2(0, buttonContainerHeight / 2);
            mask.rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, width);
            mask.rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, height - buttonContainerHeight);

            var backgroundContent = new GameObject();

            backgroundContent.transform.SetParent(gameObject.transform, false);

            var backgroundImage = backgroundContent.AddComponent <Image>();

            backgroundImage.rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, width);
            backgroundImage.rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, height - buttonContainerHeight);
            backgroundImage.color = _colors.backgroundColor;

            _canvasContainer = new GameObject();
            _canvasContainer.transform.SetParent(gameObject.transform, false);
            _canvasContainer.AddComponent <CanvasGroup>();
            _canvas = _canvasContainer.AddComponent <UICurveEditorCanvas>();
            _canvas.rectTransform.anchorMin = new Vector2(0, 0);
            _canvas.rectTransform.anchorMax = new Vector2(0, 0);
            _canvas.rectTransform.pivot     = new Vector2(0, 0);
            _canvas.rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, width);
            _canvas.rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, height - buttonContainerHeight);

            this.readOnly = readOnly;

            if (buttons != null && buttons.Count != 0)
            {
                var buttonContainer = new GameObject();
                buttonContainer.transform.SetParent(container.transform, false);

                var rectTransform = buttonContainer.AddComponent <RectTransform>();
                rectTransform.anchoredPosition = new Vector2(0, -(height - buttonContainerHeight) / 2);
                rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, width);
                rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, buttonContainerHeight);

                var gridLayout = buttonContainer.AddComponent <GridLayoutGroup>();
                gridLayout.constraint      = GridLayoutGroup.Constraint.FixedColumnCount;
                gridLayout.constraintCount = buttons.Count;
                gridLayout.spacing         = new Vector2();
                gridLayout.cellSize        = new Vector2(width / buttons.Count, buttonContainerHeight);
                gridLayout.childAlignment  = TextAnchor.MiddleCenter;

                foreach (var button in buttons)
                {
                    button.gameObject.transform.SetParent(gridLayout.transform, false);
                }
            }
        }
Пример #2
0
        public UICurveEditor(UIDynamic container, float width, float height, List <UIDynamicButton> buttons = null, UICurveEditorColors colors = null, bool readOnly = false)
        {
            var buttonContainerHeight = (buttons == null || buttons.Count == 0) ? 0 : 25;

            this.container = container;

            _storableToLineMap  = new Dictionary <IStorableAnimationCurve, UICurveLine>();
            _lineToContainerMap = new Dictionary <UICurveLine, GameObject>();
            _lines  = new List <UICurveLine>();
            _colors = colors ?? new UICurveEditorColors();

            gameObject = new GameObject();
            gameObject.transform.SetParent(container.transform, false);

            var mask = gameObject.AddComponent <RectMask2D>();

            mask.rectTransform.anchoredPosition = new Vector2(0, buttonContainerHeight / 2);
            mask.rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, width);
            mask.rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, height - buttonContainerHeight);

            var input = gameObject.AddComponent <UIInputBehaviour>();

            input.OnInput += OnInput;

            var backgroundContent = new GameObject();

            backgroundContent.transform.SetParent(gameObject.transform, false);

            var backgroundImage = backgroundContent.AddComponent <Image>();

            backgroundImage.rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, width);
            backgroundImage.rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, height - buttonContainerHeight);
            backgroundImage.color = _colors.backgroundColor;

            _linesContainer = new GameObject();
            _linesContainer.transform.SetParent(gameObject.transform, false);
            _linesContainer.AddComponent <CanvasGroup>();

            var raycastEvents = _linesContainer.AddComponent <UIRaycastEventsBehaviour>();

            raycastEvents.DefaultOnPointerClick += OnLinesContainerClick;
            raycastEvents.DefaultOnDrag         += OnLinesContainerDrag;
            raycastEvents.DefaultOnEndDrag      += OnLinesContainerEndDrag;

            this.readOnly = readOnly;

            var lineContainerRectTranform = _linesContainer.AddComponent <RectTransform>();

            lineContainerRectTranform.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, width);
            lineContainerRectTranform.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, height - buttonContainerHeight);

            if (buttons != null && buttons.Count != 0)
            {
                var buttonContainer = new GameObject();
                buttonContainer.transform.SetParent(container.transform, false);

                var rectTransform = buttonContainer.AddComponent <RectTransform>();
                rectTransform.anchoredPosition = new Vector2(0, -(height - buttonContainerHeight) / 2);
                rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, width);
                rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, buttonContainerHeight);

                var gridLayout = buttonContainer.AddComponent <GridLayoutGroup>();
                gridLayout.constraint      = GridLayoutGroup.Constraint.FixedColumnCount;
                gridLayout.constraintCount = buttons.Count;
                gridLayout.spacing         = new Vector2();
                gridLayout.cellSize        = new Vector2(width / buttons.Count, buttonContainerHeight);
                gridLayout.childAlignment  = TextAnchor.MiddleCenter;

                foreach (var button in buttons)
                {
                    button.gameObject.transform.SetParent(gridLayout.transform, false);
                }
            }

            _scrubbersContainer = new GameObject();
            _scrubbersContainer.transform.SetParent(gameObject.transform, false);
            _scrubbersContainer.AddComponent <CanvasGroup>().alpha = 0;
        }