コード例 #1
0
        /// <summary>
        /// Called by a BaseInputModule when a drag is ended.
        /// </summary>
        /// <param name="eventData">Current event data.</param>
        public virtual void OnEndDrag(PointerEventData eventData)
        {
            if (!IsDragged)
            {
                return;
            }

            var target = FindTarget(eventData);

            if (target != null)
            {
                target.Drop(Data, eventData);
                Dropped(true);
            }
            else
            {
                Dropped(false);
            }

            IsDragged = false;
            Cursor.SetCursor(DefaultCursorTexture, DefaultCursorHotSpot, Utilites.GetCursorMode());
        }
コード例 #2
0
ファイル: Popup.cs プロジェクト: daxingyou/client-2
        /// <summary>
        /// Show popup.
        /// </summary>
        /// <param name="title">Title.</param>
        /// <param name="message">Message.</param>
        /// <param name="position">Position.</param>
        /// <param name="icon">Icon.</param>
        /// <param name="modal">If set to <c>true</c> modal.</param>
        /// <param name="modalSprite">Modal sprite.</param>
        /// <param name="modalColor">Modal color.</param>
        /// <param name="canvas">Canvas.</param>
        public virtual void Show(string title     = null,
                                 string message   = null,
                                 Vector3?position = null,
                                 Sprite icon      = null,

                                 bool modal         = false,
                                 Sprite modalSprite = null,
                                 Color?modalColor   = null,

                                 Canvas canvas = null)
        {
            if (position == null)
            {
                position = new Vector3(0, 0, 0);
            }

            SetInfo(title, message, icon);

            var parent = (canvas != null) ? canvas.transform : Utilites.FindTopmostCanvas(gameObject.transform);

            if (parent != null)
            {
                transform.SetParent(parent, false);
            }

            if (modal)
            {
                ModalKey = ModalHelper.Open(this, modalSprite, modalColor, Close);
            }
            else
            {
                ModalKey = null;
            }

            transform.SetAsLastSibling();

            transform.localPosition = (Vector3)position;
            gameObject.SetActive(true);
        }
コード例 #3
0
        /// <summary>
        /// Init this instance.
        /// </summary>
        protected virtual void Init()
        {
            if (isInited)
            {
                return;
            }

            isInited = true;

            InputFieldProxy.onValueChanged.AddListener(ApplyFilter);

            var inputListener = Utilites.GetOrAddComponent <InputFieldListener>(InputFieldProxy.gameObject);

            inputListener.OnMoveEvent.AddListener(SelectResult);
            inputListener.OnSubmitEvent.AddListener(SubmitResult);
            inputListener.onDeselect.AddListener(InputDeselected);

            DisplayListView.gameObject.SetActive(false);

            DisplayListView.MultipleSelect = false;
            DisplayListView.OnSelect.AddListener(ItemSelected);
        }
コード例 #4
0
        public void LateUpdate()
        {
            if (!IsCursorOver)
            {
                return;
            }
            if (processDrag)
            {
                return;
            }
            if (CursorTexture == null)
            {
                return;
            }
            if (!Input.mousePresent)
            {
                return;
            }

            Vector2 point;

            if (!RectTransformUtility.ScreenPointToLocalPointInRectangle(RectTransform, Input.mousePosition, CurrentCamera, out point))
            {
                return;
            }

            var rect = RectTransform.rect;

            if (rect.Contains(point))
            {
                cursorChanged = true;
                Cursor.SetCursor(CursorTexture, CursorHotSpot, Utilites.GetCursorMode());
            }
            else if (cursorChanged)
            {
                cursorChanged = false;
                Cursor.SetCursor(DefaultCursorTexture, DefaultCursorHotSpot, Utilites.GetCursorMode());
            }
        }
コード例 #5
0
        /// <summary>
        /// Raises the begin drag event.
        /// </summary>
        /// <param name="eventData">Event data.</param>
        public void OnBeginDrag(PointerEventData eventData)
        {
            Vector2 point;

            processDrag = false;

            if (!RectTransformUtility.ScreenPointToLocalPointInRectangle(RectTransform, eventData.pressPosition, eventData.pressEventCamera, out point))
            {
                return;
            }

            var index = transform.GetSiblingIndex();

            if (index == 0 || transform.parent.childCount == (index + 1))
            {
                return;
            }

            Cursor.SetCursor(CursorTexture, CursorHotSpot, Utilites.GetCursorMode());
            cursorChanged = true;

            processDrag = true;

            if (mode == SplitterMode.Auto)
            {
                leftTarget  = transform.parent.GetChild(index - 1) as RectTransform;
                rightTarget = transform.parent.GetChild(index + 1) as RectTransform;
            }

            LeftTargetElement.preferredWidth  = leftTarget.rect.width;
            LeftTargetElement.preferredHeight = leftTarget.rect.height;

            RightTargetElement.preferredWidth  = rightTarget.rect.width;
            RightTargetElement.preferredHeight = rightTarget.rect.height;

            summarySize = new Vector2(leftTarget.rect.width + rightTarget.rect.width, leftTarget.rect.height + rightTarget.rect.height);

            OnStartResize.Invoke(this);
        }
コード例 #6
0
        /// <summary>
        /// Instantiated date component from template.
        /// </summary>
        /// <returns>Date component.</returns>
        protected virtual CalendarDateBase GenerateDay()
        {
            CalendarDateBase day;

            if (Cache.Count > 0)
            {
                day = Cache.Pop();
            }
            else
            {
                day = Compatibility.Instantiate(CalendarDateTemplate);
                day.transform.SetParent(Container, false);
                Utilites.FixInstantiated(CalendarDateTemplate, day);

                day.Calendar = this;
            }

            day.gameObject.SetActive(true);
            day.transform.SetAsLastSibling();

            return(day);
        }
コード例 #7
0
        /// <summary>
        /// Start this instance.
        /// </summary>
        public virtual void Start()
        {
            if (isStartedComboboxCustom)
            {
                return;
            }
            isStartedComboboxCustom = true;

            onSelectCallback = index => OnSelect.Invoke(index, listView.DataSource[index]);

            SetToggleButton(toggleButton);

            SetListView(listView);

            if (listView != null)
            {
                current.gameObject.SetActive(false);

                listView.OnSelectObject.RemoveListener(UpdateView);
                listView.OnDeselectObject.RemoveListener(UpdateView);

                listCanvas = Utilites.FindTopmostCanvas(listParent);

                listView.gameObject.SetActive(true);
                listView.Start();
                if ((listView.SelectedIndex == -1) && (listView.DataSource.Count > 0) && (!listView.Multiple))
                {
                    listView.SelectedIndex = 0;
                }
                if (listView.SelectedIndex != -1)
                {
                    UpdateView();
                }
                listView.gameObject.SetActive(false);

                listView.OnSelectObject.AddListener(UpdateView);
                listView.OnDeselectObject.AddListener(UpdateView);
            }
        }
コード例 #8
0
        /// <summary>
        /// Sets the palette.
        /// </summary>
        /// <param name="value">Value.</param>
        protected virtual void SetPalette(Image value)
        {
            if (dragListener != null)
            {
                dragListener.OnDragEvent.RemoveListener(OnDrag);
            }

            if (clickListener != null)
            {
                clickListener.ClickEvent.RemoveListener(OnDrag);
            }

            if (resizeListener != null)
            {
                resizeListener.OnResize.RemoveListener(UpdateView);
            }

            palette = value;
            if (palette != null)
            {
                paletteRect = palette.transform as RectTransform;

                dragListener = Utilites.GetOrAddComponent <OnDragListener>(palette);
                dragListener.OnDragEvent.AddListener(OnDrag);

                clickListener = Utilites.GetOrAddComponent <ClickListener>(palette);
                clickListener.ClickEvent.AddListener(OnDrag);

                resizeListener = Utilites.GetOrAddComponent <ResizeListener>(palette);
                resizeListener.OnResize.AddListener(UpdateView);

                UpdateMaterial();
            }
            else
            {
                paletteRect = null;
            }
        }
コード例 #9
0
        /// <summary>
        /// Raises the drag event.
        /// </summary>
        /// <param name="eventData">Event data.</param>
        public void OnDrag(PointerEventData eventData)
        {
            if (!processDrag)
            {
                return;
            }
            if (canvas == null)
            {
                throw new MissingComponentException(gameObject.name + " not in Canvas hierarchy.");
            }
            Cursor.SetCursor(CursorTexture, CursorHotSpot, Utilites.GetCursorMode());

            Vector2 p1;

            RectTransformUtility.ScreenPointToLocalPointInRectangle(RectTransform, eventData.position, CurrentCamera, out p1);
            Vector2 p2;

            RectTransformUtility.ScreenPointToLocalPointInRectangle(RectTransform, eventData.position - eventData.delta, CurrentCamera, out p2);
            var delta = p1 - p2;

            if (delta.x > 0)
            {
                leftTarget.preferredWidth  = Mathf.Min(leftTarget.preferredWidth + delta.x, widthLimit - rightTarget.minWidth);
                rightTarget.preferredWidth = widthLimit - leftTarget.preferredWidth;
            }
            else
            {
                rightTarget.preferredWidth = Mathf.Min(rightTarget.preferredWidth - delta.x, widthLimit - leftTarget.minWidth);
                leftTarget.preferredWidth  = widthLimit - rightTarget.preferredWidth;
            }

            LayoutUtilites.UpdateLayout(layout);

            if (OnDragUpdate)
            {
                Resize();
            }
        }
コード例 #10
0
        /// <summary>
        /// Animation coroutine.
        /// </summary>
        /// <returns>Coroutine.</returns>
        protected IEnumerator AnimationCoroutine()
        {
            var start_pos = DragRect.localPosition;
            var end_pos   = RestrictPosition(DragRect.localPosition);

            if (start_pos != end_pos)
            {
                var animation_length   = Draggable.Curve.keys[Draggable.Curve.keys.Length - 1].time;
                var startTime          = Utilites.GetTime(Draggable.UnscaledTime);
                var animation_position = 0f;

                do
                {
                    animation_position = Utilites.GetTime(Draggable.UnscaledTime) - startTime;
                    var value = Draggable.Curve.Evaluate(animation_position);
                    DragRect.localPosition = Vector3.Lerp(start_pos, end_pos, value);

                    yield return(null);
                }while (animation_position < animation_length);

                DragRect.localPosition = end_pos;
            }
        }
コード例 #11
0
        /// <summary>
        /// Adds the component.
        /// </summary>
        protected virtual void AddComponent()
        {
            TComponent component;

            if (componentsCache.Count > 0)
            {
                component = componentsCache[componentsCache.Count - 1];
                componentsCache.RemoveAt(componentsCache.Count - 1);
            }
            else
            {
                component = Compatibility.Instantiate(current);
                component.transform.SetParent(current.transform.parent, false);

                Utilites.FixInstantiated(current, component);
            }

            component.Index = -2;
            component.Owner = ListView;
            component.transform.SetAsLastSibling();
            component.gameObject.SetActive(true);
            components.Add(component);
        }
コード例 #12
0
        /// <summary>
        /// Rotate animation.
        /// </summary>
        /// <returns>Animation.</returns>
        /// <param name="rectTransform">RectTransform.</param>
        /// <param name="time">Time.</param>
        /// <param name="startAngle">Start rotation angle.</param>
        /// <param name="endAngle">End rotation angle.</param>
        /// <param name="unscaledTime">Use unscaled time.</param>
        /// <param name="actionAfter">Action to run after animation.</param>
        public static IEnumerator Rotate(RectTransform rectTransform, float time = 0.5f, float startAngle = 0, float endAngle = 90, bool unscaledTime = false, Action actionAfter = null)
        {
            var start_rotarion = rectTransform.localRotation.eulerAngles;

            var end_time = Utilites.GetTime(unscaledTime) + time;

            while (Utilites.GetTime(unscaledTime) <= end_time)
            {
                var t          = 1 - ((end_time - Utilites.GetTime(unscaledTime)) / time);
                var rotation_x = Mathf.Lerp(startAngle, endAngle, t);

                rectTransform.localRotation = Quaternion.Euler(rotation_x, start_rotarion.y, start_rotarion.z);
                yield return(null);
            }

            // return rotation back for future use
            rectTransform.localRotation = Quaternion.Euler(start_rotarion);

            if (actionAfter != null)
            {
                actionAfter();
            }
        }
コード例 #13
0
        /// <summary>
        /// Sets the palette.
        /// </summary>
        /// <param name="value">Value.</param>
        protected virtual void SetImage(Image value)
        {
            if (dragListener != null)
            {
                dragListener.OnDragEvent.RemoveListener(OnDrag);
            }

            image = value;
            if (image != null)
            {
                imageRect = image.transform as RectTransform;

                dragListener = Utilites.GetOrAddComponent <OnDragListener>(image);
                dragListener.OnDragEvent.AddListener(OnDrag);

                clickListener = Utilites.GetOrAddComponent <ClickListener>(image);
                clickListener.ClickEvent.AddListener(OnDrag);
            }
            else
            {
                imageRect = null;
            }
        }
コード例 #14
0
        /// <summary>
        /// Gets the height of the item.
        /// </summary>
        /// <returns>The item height.</returns>
        /// <param name="item">Item.</param>
        float CalculateItemHeight(string item)
        {
            if (defaultItemLayoutGroup == null)
            {
                defaultItemLayoutGroup = DefaultItemCopy.GetComponent <LayoutGroup>();
            }

            float height = 0f;

            if (defaultItemLayoutGroup != null)
            {
                DefaultItemCopy.gameObject.SetActive(true);

                DefaultItemCopy.SetData(item);
                Utilites.UpdateLayout(defaultItemLayoutGroup);

                height = LayoutUtility.GetPreferredHeight(DefaultItemCopyRect);

                DefaultItemCopy.gameObject.SetActive(false);
            }

            return(height);
        }
コード例 #15
0
        /// <summary>
        /// Enable points view.
        /// </summary>
        /// <param name="pointsView">Points view.</param>
        protected virtual void EnablePointsView(ScrollBlock pointsView)
        {
            if (pointsView == null)
            {
                return;
            }

            DataHeaderSize = (pointsView.DefaultItem.transform as RectTransform).rect.size;

            pointsView.AlwaysCenter = false;
            pointsView.Increase     = Increase;
            pointsView.Decrease     = Decrease;
            pointsView.Value        = Value2Text;
            pointsView.UpdateView();

            var points_drag = Utilites.GetOrAddComponent <DragListener>(pointsView);

            points_drag.OnInitializePotentialDragEvent.AddListener(OnPointsDragInit);
            points_drag.OnDragStartEvent.AddListener(OnPointsDragBegin);
            points_drag.OnDragEvent.AddListener(OnPointsDrag);
            points_drag.OnDragEndEvent.AddListener(OnPointsDragEnd);
            points_drag.OnScrollEvent.AddListener(OnPointsScroll);
        }
コード例 #16
0
        List <TComponent> GetNewComponents()
        {
            componentsCache = componentsCache.Where(x => x != null).ToList();
            var new_components = new List <TComponent>();

            customItems.ForEach((x, i) => {
                if (i >= visibleItems)
                {
                    return;
                }

                if (components.Count > 0)
                {
                    new_components.Add(components[0]);
                    components.RemoveAt(0);
                }
                else if (componentsCache.Count > 0)
                {
                    componentsCache[0].gameObject.SetActive(true);
                    new_components.Add(componentsCache[0]);
                    componentsCache.RemoveAt(0);
                }
                else
                {
                    var component = Instantiate(DefaultItem) as TComponent;
                    Utilites.FixInstantiated(DefaultItem, component);
                    component.gameObject.SetActive(true);
                    new_components.Add(component);
                }
            });

            components.ForEach(x => x.gameObject.SetActive(false));
            componentsCache.AddRange(components);
            components.Clear();

            return(new_components);
        }
コード例 #17
0
ファイル: Picker.cs プロジェクト: RockfFestival/Rock
        /// <summary>
        /// Show picker.
        /// </summary>
        /// <param name="defaultValue">Default value.</param>
        /// <param name="onSelect">Callback with selected value.</param>
        /// <param name="onCancel">Callback when picker closed without any value selected.</param>
        /// <param name="modalSprite">Modal sprite.</param>
        /// <param name="modalColor">Modal color.</param>
        /// <param name="canvas">Canvas.</param>
        public virtual void Show(
            TValue defaultValue,
            Action <TValue> onSelect,
            Action onCancel    = null,
            Sprite modalSprite = null,
            Color?modalColor   = null,

            Canvas canvas = null)
        {
            if (IsTemplate)
            {
                Debug.LogWarning("Use the template clone, not the template itself: PickerTemplate.Clone().Show(...), not PickerTemplate.Show(...)");
            }

            OnSelect = onSelect;
            OnCancel = onCancel;

            var parent = (canvas != null) ? canvas.transform : Utilites.FindTopmostCanvas(gameObject.transform);

            if (parent != null)
            {
                transform.SetParent(parent, false);
            }

            if (modalColor == null)
            {
                modalColor = new Color(0, 0, 0, 0.8f);
            }

            ModalKey = ModalHelper.Open(this, modalSprite, modalColor, Close);

            transform.SetAsLastSibling();

            gameObject.SetActive(true);

            BeforeOpen(defaultValue);
        }
コード例 #18
0
ファイル: Tabs.cs プロジェクト: pmindek/cellVIEWcut
        /// <summary>
        /// Creates the buttons.
        /// </summary>
        void CreateButtons()
        {
            if (tabObjects.Length > defaultButtons.Count)
            {
                for (var i = defaultButtons.Count; i < tabObjects.Length; i++)
                {
                    var defaultButton = Instantiate(DefaultTabButton) as Button;
                    defaultButton.transform.SetParent(Container, false);

                    Utilites.FixInstantiated(DefaultTabButton, defaultButton);

                    defaultButtons.Add(defaultButton);

                    var activeButton = Instantiate(ActiveTabButton) as Button;
                    activeButton.transform.SetParent(Container, false);

                    Utilites.FixInstantiated(ActiveTabButton, activeButton);

                    activeButtons.Add(activeButton);
                }
            }
            //del existing ui elements if necessary
            if (tabObjects.Length < defaultButtons.Count)
            {
                for (var i = defaultButtons.Count; i > tabObjects.Length; i--)
                {
                    Destroy(defaultButtons[i]);
                    Destroy(activeButtons[i]);

                    defaultButtons.RemoveAt(i);
                    activeButtons.RemoveAt(i);
                }
            }

            defaultButtons.ForEach(SetButtonName);
            activeButtons.ForEach(SetButtonName);
        }
コード例 #19
0
        /// <summary>
        /// Init this instance.
        /// </summary>
        public void Init()
        {
            canvasRect = Utilites.FindCanvas(transform) as RectTransform;
            canvas     = canvasRect.GetComponent <Canvas>();

            children.Clear();
            childrenLayouts.Clear();
            int i = 0;

            foreach (Transform child in transform)
            {
                var element = child.GetComponent <LayoutElement>() ?? child.gameObject.AddComponent <LayoutElement>();
                children.Add(child as RectTransform);
                childrenLayouts.Add(element);

                var cell = child.gameObject.AddComponent <ResizableHeaderDragCell>();
                cell.Position                = i;
                cell.ResizableHeader         = this;
                cell.AllowDropCursor         = AllowDropCursor;
                cell.AllowDropCursorHotSpot  = AllowDropCursorHotSpot;
                cell.DeniedDropCursor        = DeniedDropCursor;
                cell.DeniedDropCursorHotSpot = DeniedDropCursorHotSpot;

                var events = child.gameObject.AddComponent <ResizableHeaderCell>();
                events.OnInitializePotentialDragEvent.AddListener(OnInitializePotentialDrag);
                events.OnBeginDragEvent.AddListener(OnBeginDrag);
                events.OnDragEvent.AddListener(OnDrag);
                events.OnEndDragEvent.AddListener(OnEndDrag);

                i++;
            }
            positions = Enumerable.Range(0, i).ToList();

            CalculateWidths();
            //ResetChildren();
            //Resize();
        }
コード例 #20
0
        /// <summary>
        /// Create modal helper with the specified parent, sprite and color.
        /// </summary>
        /// <param name="parent">Parent.</param>
        /// <param name="sprite">Sprite.</param>
        /// <param name="color">Color.</param>
        /// <returns>Modal helper index</returns>
        public static int Open(MonoBehaviour parent, Sprite sprite = null, Color?color = null)
        {
            //check if in cache
            if (!Templates.Exists(key))
            {
                Templates.FindTemplates();
                CreateTemplate();
            }

            var modal = Templates.Instance(key);

            modal.transform.SetParent(Utilites.FindCanvas(parent.transform), false);
            modal.gameObject.SetActive(true);
            modal.transform.SetAsLastSibling();

            var rect = modal.GetComponent <RectTransform>();

            rect.sizeDelta        = new Vector2(0, 0);
            rect.anchorMin        = new Vector2(0, 0);
            rect.anchorMax        = new Vector2(1, 1);
            rect.anchoredPosition = new Vector2(0, 0);

            var img = modal.GetComponent <Image>();

            if (sprite != null)
            {
                img.sprite = sprite;
            }
            if (color != null)
            {
                img.color = (Color)color;
            }

            used.Add(modal.GetInstanceID(), modal);
            return(modal.GetInstanceID());
        }
コード例 #21
0
        /// <summary>
        /// Reinit this instance in case if you remove or add cells manually.
        /// </summary>
        public void Reinit()
        {
            RestoreOrder();

            // clear cells list
            CellsInfo.Clear();

            // clear cell settings and events
            foreach (Transform child in transform)
            {
                transform.gameObject.SetActive(true);

                var cell = Utilites.GetOrAddComponent <ResizableHeaderDragCell>(child);
                cell.Position = -1;

                var events = Utilites.GetOrAddComponent <ResizableHeaderCell>(child);
                events.OnInitializePotentialDragEvent.RemoveListener(OnInitializePotentialDrag);
                events.OnBeginDragEvent.RemoveListener(OnBeginDrag);
                events.OnDragEvent.RemoveListener(OnDrag);
                events.OnEndDragEvent.RemoveListener(OnEndDrag);
            }

            Refresh();
        }
コード例 #22
0
        /// <summary>
        /// Runs the animation.
        /// </summary>
        /// <returns>The animation.</returns>
        /// <param name="isHorizontal">If set to <c>true</c> is horizontal.</param>
        /// <param name="startPosition">Start position.</param>
        /// <param name="endPosition">End position.</param>
        /// <param name="unscaledTime">If set to <c>true</c> use unscaled time.</param>
        protected virtual IEnumerator RunAnimation(bool isHorizontal, float startPosition, float endPosition, bool unscaledTime)
        {
            float delta;

            var animation_length = Movement.keys[Movement.keys.Length - 1].time;
            var start_time       = Utilites.GetTime(unscaledTime);

            do
            {
                delta = Utilites.GetTime(unscaledTime) - start_time;
                var value = Movement.Evaluate(delta);

                var position = startPosition + ((endPosition - startPosition) * value);
                if (isHorizontal)
                {
                    RectTransform.anchoredPosition = new Vector2(position, RectTransform.anchoredPosition.y);
                }
                else
                {
                    RectTransform.anchoredPosition = new Vector2(RectTransform.anchoredPosition.x, position);
                }

                yield return(null);
            }while (delta < animation_length);

            if (isHorizontal)
            {
                RectTransform.anchoredPosition = new Vector2(endPosition, RectTransform.anchoredPosition.y);
            }
            else
            {
                RectTransform.anchoredPosition = new Vector2(RectTransform.anchoredPosition.x, endPosition);
            }

            IsAnimationRunning = false;
        }
コード例 #23
0
        /// <summary>
        /// Initializes a new instance of the <see cref="UIWidgets.StandardLayoutBridge"/> class.
        /// </summary>
        /// <param name="layout">Layout.</param>
        /// <param name="defaultItem">Default item.</param>
        public StandardLayoutBridge(HorizontalOrVerticalLayoutGroup layout, RectTransform defaultItem)
        {
            Utilites.UpdateLayout(layout);

            Layout      = layout;
            DefaultItem = defaultItem;

            isHorizontal = layout is HorizontalLayoutGroup;

            var firstFillerGO        = new GameObject("FirstFiller");
            var firstFillerTransform = (firstFillerGO.transform as RectTransform) ?? firstFillerGO.AddComponent <RectTransform>();

            firstFillerTransform.SetParent(Layout.transform);
            firstFillerTransform.localScale = Vector3.one;
            FirstFiller = firstFillerGO.AddComponent <LayoutElement>();

            var lastFillerGO        = new GameObject("LastFiller");
            var lastFillerTransform = (lastFillerGO.transform as RectTransform) ?? lastFillerGO.AddComponent <RectTransform>();

            lastFillerTransform.SetParent(Layout.transform);
            lastFillerTransform.localScale = Vector3.one;
            LastFiller = lastFillerGO.AddComponent <LayoutElement>();

            var size = GetItemSize();

            if (IsHorizontal)
            {
                firstFillerTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, size.y);
                lastFillerTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, size.y);
            }
            else
            {
                firstFillerTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, size.x);
                lastFillerTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, size.x);
            }
        }
コード例 #24
0
        /// <summary>
        /// Enable data view.
        /// </summary>
        /// <param name="dataView">Data view.</param>
        protected virtual void EnableDataView(ScrollRect dataView)
        {
            if (dataView == null)
            {
                return;
            }

            dataView.content.pivot = new Vector2(0.5f, 1f);
            dataView.inertia       = false;
            dataView.horizontal    = true;
            dataView.vertical      = true;

            var data_drag = Utilites.GetOrAddComponent <DragListener>(dataView);

            data_drag.OnInitializePotentialDragEvent.AddListener(OnDataDragInit);
            data_drag.OnDragStartEvent.AddListener(OnDataDragBegin);
            data_drag.OnDragEvent.AddListener(OnDataDrag);
            data_drag.OnDragEndEvent.AddListener(OnDataDragEnd);
            data_drag.OnScrollEvent.AddListener(OnDataScroll);

            var data_resize = Utilites.GetOrAddComponent <ResizeListener>(dataView);

            data_resize.OnResize.AddListener(OnResize);
        }
コード例 #25
0
        /// <summary>
        /// Adds page the component.
        /// </summary>
        /// <param name="page">Page.</param>
        protected virtual void AddComponent(int page)
        {
            ScrollRectPage component;

            if (DefaultPagesCache.Count > 0)
            {
                component = DefaultPagesCache[DefaultPagesCache.Count - 1];
                DefaultPagesCache.RemoveAt(DefaultPagesCache.Count - 1);
            }
            else
            {
                component = Instantiate(SRDefaultPage) as ScrollRectPage;
                component.transform.SetParent(SRDefaultPage.transform.parent, false);

                component.OnPageSelect.AddListener(GoToPage);

                Utilites.FixInstantiated(SRDefaultPage, component);
            }
            component.transform.SetAsLastSibling();
            component.gameObject.SetActive(true);
            component.SetPage(page);

            DefaultPages.Add(component);
        }
コード例 #26
0
ファイル: Switch.cs プロジェクト: cschladetsch/UnityTemplate
 protected float GetTime()
 {
     return(Utilites.GetTime(UnscaledTime));
 }
コード例 #27
0
 static void CreateObject()
 {
     Utilites.CreateWidgetFromAsset("ListViewGameObjects");
 }
コード例 #28
0
        /// <summary>
        /// Adds listener.
        /// </summary>
        /// <param name="rect">RectTransform</param>
        protected virtual void AddListener(RectTransform rect)
        {
            var rl = Utilites.GetOrAddComponent <ResizeListener>(rect);

            rl.OnResize.AddListener(CalculatePositions);
        }
コード例 #29
0
ファイル: Tabs.cs プロジェクト: faint449/GGJ2017DEMO
 static void CreateObject()
 {
     Utilites.CreateWidgetFromAsset("Tabs");
 }
コード例 #30
0
ファイル: Tabs.cs プロジェクト: faint449/GGJ2017DEMO
        void CreateButtons()
        {
            if (KeepTabsActive)
            {
                tabObjects[_selectedTab].TabObject.transform.SetAsLastSibling();
            }
            else
            {
                tabObjects.ForEach(x => x.TabObject.SetActive(false));
                tabObjects[_selectedTab].TabObject.SetActive(true);
            }
            if (tabObjects.Length > defaultButtons.Count)
            {
                for (var i = defaultButtons.Count; i < tabObjects.Length; i++)
                {
                    var defaultButton = Instantiate(DefaultTabButton) as Button;
                    defaultButton.transform.SetParent(Container, false);
                    if (i == _selectedTab || !TabObjects[i].Activated)
                    {
                        defaultButton.gameObject.SetActive(false);
                    }
                    else
                    {
                        defaultButton.gameObject.SetActive(true);
                    }

                    Utilites.FixInstantiated(DefaultTabButton, defaultButton);

                    defaultButtons.Add(defaultButton);

                    var activeButton = Instantiate(ActiveTabButton) as Button;
                    activeButton.transform.SetParent(Container, false);
                    if (i == _selectedTab)
                    {
                        activeButton.gameObject.SetActive(true);
                    }
                    else
                    {
                        activeButton.gameObject.SetActive(false);
                    }

                    Utilites.FixInstantiated(ActiveTabButton, activeButton);

                    activeButtons.Add(activeButton);
                }
            }
            //del existing ui elements if necessary
            if (tabObjects.Length < defaultButtons.Count)
            {
                for (var i = defaultButtons.Count; i > tabObjects.Length; i--)
                {
                    Destroy(defaultButtons[i]);
                    Destroy(activeButtons[i]);

                    defaultButtons.RemoveAt(i);
                    activeButtons.RemoveAt(i);
                }
            }

            defaultButtons.ForEach(SetButtonName);
            activeButtons.ForEach(SetButtonName);
        }