示例#1
0
            public static Scrollbar AddScrollbar(GameObject goScrollbar, Scrollbar.Direction direction = Scrollbar.Direction.LeftToRight)
            {
                Scrollbar scrollbar = goScrollbar.AddOrGetComponent <Scrollbar>();
                {
                    Image image = goScrollbar.AddOrGetComponent <Image>();
                    image.sprite = Resources.Instance.GetSpriteField();
                    image.type   = Image.Type.Sliced;
                }

                GameObject goSliding = FindOrCreateUI(NameScrollbarSlidingArea, goScrollbar, (string name, GameObject parent) =>
                {
                    GameObject sliding = CreateGUIGameObject(name, parent);
                    SetRectTransform(sliding, 0, 0, 1, 1, 0.5f, 0.5f, 0, 0, 0, 0);
                    return(sliding);
                });

                GameObject goHandle = FindOrCreateUI(NameScrollbarHandle, goSliding, (string name, GameObject parent) =>
                {
                    GameObject handle     = CreateGUIGameObject(NameScrollbarHandle, goSliding);
                    RectTransform rect    = handle.AddOrGetComponent <RectTransform>();
                    rect.pivot            = new Vector2(0.5f, 0.5f);
                    rect.sizeDelta        = new Vector2(0, 0);
                    rect.anchoredPosition = new Vector2(0, 0);
                    scrollbar.handleRect  = rect;

                    Image image  = handle.AddOrGetComponent <Image>();
                    image.sprite = Resources.Instance.GetSpriteButton();
                    image.type   = Image.Type.Sliced;
                    return(handle);
                });

                scrollbar.direction = direction;
                return(scrollbar);
            }
    static int SetDirection(IntPtr L)
    {
        LuaScriptMgr.CheckArgsCount(L, 3);
        Scrollbar obj = (Scrollbar)LuaScriptMgr.GetUnityObjectSelf(L, 1, "Scrollbar");

        Scrollbar.Direction arg0 = (Scrollbar.Direction)LuaScriptMgr.GetNetObject(L, 2, typeof(Scrollbar.Direction));
        bool arg1 = LuaScriptMgr.GetBoolean(L, 3);

        obj.SetDirection(arg0, arg1);
        return(0);
    }
示例#3
0
    public static GameObject CreateScrollBar(Scrollbar.Direction direction, GameObject parent)
    {
        // Create the scroll bar object.
        var scrollBar = CreateUIObject("Scrollbar", parent);

        scrollBar.AddComponent <CanvasRenderer>();

        var   isHorizontal = (direction == Scrollbar.Direction.LeftToRight) || (direction == Scrollbar.Direction.RightToLeft);
        float length       = 160;

        scrollBar.GetComponent <RectTransform>().sizeDelta = isHorizontal ? new Vector2(length, 20) : new Vector2(20, length);

        var scrollBarImage = scrollBar.AddComponent <Image>();

        scrollBarImage.sprite = backgroundImg;
        scrollBarImage.type   = Image.Type.Sliced;

        var scrollBarComponent = scrollBar.AddComponent <Scrollbar>();

        scrollBarComponent.direction = direction;

        // Create the sliding area.
        var slidingArea = CreateUIObject("Sliding Area", scrollBar);

        var slidingAreaRectTransform = slidingArea.GetComponent <RectTransform>();

        slidingAreaRectTransform.anchorMin = Vector2.zero;
        slidingAreaRectTransform.anchorMax = Vector2.one;
        slidingAreaRectTransform.offsetMin = new Vector2(10, 10);
        slidingAreaRectTransform.offsetMax = new Vector2(-10, -10);

        // Create the handle.
        var handle = CreateUIObject("Handle", slidingArea);

        handle.AddComponent <CanvasRenderer>();

        var handleImage = handle.AddComponent <Image>();

        handleImage.sprite = spriteImg;
        handleImage.type   = Image.Type.Sliced;

        var handleRectTransform = handle.GetComponent <RectTransform>();

        handleRectTransform.offsetMin = new Vector2(-10, -10);
        handleRectTransform.offsetMax = new Vector2(10, 10);

        // Link everything together.
        scrollBarComponent.handleRect    = handle.GetComponent <RectTransform>();
        scrollBarComponent.targetGraphic = handle.GetComponent <Image>();

        return(scrollBar);
    }
        public override void OnEnter()
        {
            GameObject _go = Fsm.GetOwnerDefaultTarget(gameObject);

            if (_go != null)
            {
                _scrollbar = _go.GetComponent <Scrollbar>();
            }

            if (resetOnExit.Value)
            {
                _originalValue = _scrollbar.direction;
            }

            DoSetValue();

            Finish();
        }
示例#5
0
            public static GameObject CreateScrollBar(GameObject parent, string name, Scrollbar.Direction direction = Scrollbar.Direction.LeftToRight)
            {
                GameObject goScrollbar = CreateGUIGameObject(name, parent);

                AddScrollbar(goScrollbar, direction);

                if (direction == Scrollbar.Direction.BottomToTop ||
                    direction == Scrollbar.Direction.TopToBottom)
                {
                    Helper.SetRectTransform(goScrollbar, 1, 0, 1, 1, 1, 1, 20.0f, 0.0f, 0.0f, 0.0f);
                }
                else
                {
                    Helper.SetRectTransform(goScrollbar, 0, 0, 1, 0, 0, 0, 0.0f, 20.0f, 0.0f, 0.0f);
                }

                return(goScrollbar);
            }
示例#6
0
        public void SetDirection(Scrollbar.Direction direction, bool includeRectLayouts)
        {
            Scrollbar.Axis axis         = this.axis;
            bool           reverseValue = this.reverseValue;

            this.direction = direction;
            if (includeRectLayouts)
            {
                if (this.axis != axis)
                {
                    RectTransformUtility.FlipLayoutAxes(base.transform as RectTransform, true, true);
                }
                if (this.reverseValue != reverseValue)
                {
                    RectTransformUtility.FlipLayoutOnAxis(base.transform as RectTransform, (int)this.axis, true, true);
                }
            }
        }
示例#7
0
        /// <summary>
        /// Turn a Scrollbar direction into a UIDirection
        /// </summary>
        /// <param name="direction">The UnityEngine UI Scrollbar direction</param>
        /// <returns>The UIDirection corresponding to the scrollbar direction</returns>
        public static EUIDirection ScrollbarDirectionToUIDirection(Scrollbar.Direction direction)
        {
            switch (direction)
            {
            case (Scrollbar.Direction.TopToBottom):
                return(EUIDirection.TopToBottom);

            case (Scrollbar.Direction.BottomToTop):
                return(EUIDirection.BottomToTop);

            case (Scrollbar.Direction.LeftToRight):
                return(EUIDirection.LeftToRight);

            case (Scrollbar.Direction.RightToLeft):
                return(EUIDirection.RightToLeft);

            default:
                return(EUIDirection.TopToBottom);
            }
        }
示例#8
0
        public void SetDirection(Scrollbar.Direction direction, bool includeRectLayouts)
        {
            Axis oldAxis    = axis;
            bool oldReverse = reverseValue;

            this.direction = direction;

            if (!includeRectLayouts)
            {
                return;
            }

            if (axis != oldAxis)
            {
                RectTransformUtility.FlipLayoutAxes(transform as RectTransform, true, true);
            }

            if (reverseValue != oldReverse)
            {
                RectTransformUtility.FlipLayoutOnAxis(transform as RectTransform, (int)axis, true, true);
            }
        }
示例#9
0
        public static GameObject CreateScrollbar(GameObject parent, float width, float height, Scrollbar.Direction direction)
        {
            GameObject scrollbar = CreateUIBase("Scrollbar", parent);

            scrollbar.GetComponent <RectTransform>().sizeDelta = new Vector2(width, height);
            //scrollbar.GetComponent<RectTransform>().Rotate(0, 0, rotate);
            scrollbar.AddComponent <Image>().color = Color.black;

            GameObject scrollbarsa = CreateUIBase("Sliding Area", scrollbar);

            scrollbarsa.GetComponent <RectTransform>().anchorMin = new Vector2(0, 0);
            scrollbarsa.GetComponent <RectTransform>().anchorMax = new Vector2(1, 1);
            scrollbarsa.GetComponent <RectTransform>().pivot     = new Vector2(0.5f, 0.5f);
            scrollbarsa.GetComponent <RectTransform>().sizeDelta = new Vector2(0, 0);
            //scrollbarsa.GetComponent<RectTransform>().Rotate(0, 0, rotate);

            GameObject scrollbarha = CreateUIBase("Handle", scrollbarsa);

            scrollbarha.GetComponent <RectTransform>().pivot            = new Vector2(0.5f, 0.5f);
            scrollbarha.GetComponent <RectTransform>().anchoredPosition = new Vector2(0, 0);
            scrollbarha.GetComponent <RectTransform>().sizeDelta        = new Vector2(0, 0);
            //scrollbarha.GetComponent<RectTransform>().Rotate(0, 0, rotate);
            scrollbarha.AddComponent <Image>().color           = Color.white;
            scrollbar.AddComponent <Scrollbar>().handleRect    = scrollbarha.GetComponent <RectTransform>();
            scrollbar.GetComponent <Scrollbar>().targetGraphic = scrollbarha.GetComponent <Image>();
            scrollbar.GetComponent <Scrollbar>().direction     = direction;
            return(scrollbar);
        }
示例#10
0
        public override void OnInspectorGUI()
        {
            base.OnInspectorGUI();
            EditorGUILayout.Space();

            serializedObject.Update();

            // EditorGUILayout.PropertyField(m_HandleRect);
            EditorGUI.BeginChangeCheck();
            RectTransform newRectTransform = EditorGUILayout.ObjectField("Handle Rect", m_HandleRect.objectReferenceValue, typeof(RectTransform), true) as RectTransform;

            if (EditorGUI.EndChangeCheck())
            {
                // Handle Rect will modify its GameObject RectTransform drivenBy, so we need to Record the old and new RectTransform.
                List <Object> modifiedObjects = new List <Object>();
                modifiedObjects.Add(newRectTransform);
                foreach (var target in m_HandleRect.serializedObject.targetObjects)
                {
                    MonoBehaviour mb = target as MonoBehaviour;
                    if (mb == null)
                    {
                        continue;
                    }

                    modifiedObjects.Add(mb);
                    modifiedObjects.Add(mb.GetComponent <RectTransform>());
                }
                Undo.RecordObjects(modifiedObjects.ToArray(), "Change Handle Rect");
                m_HandleRect.objectReferenceValue = newRectTransform;
            }

            if (m_HandleRect.objectReferenceValue != null)
            {
                EditorGUI.BeginChangeCheck();
                EditorGUILayout.PropertyField(m_Direction);
                if (EditorGUI.EndChangeCheck())
                {
                    Scrollbar.Direction direction = (Scrollbar.Direction)m_Direction.enumValueIndex;
                    foreach (var obj in serializedObject.targetObjects)
                    {
                        Scrollbar scrollbar = obj as Scrollbar;
                        scrollbar.SetDirection(direction, true);
                    }
                }

                EditorGUILayout.PropertyField(m_Value);
                EditorGUILayout.PropertyField(m_Size);
                EditorGUILayout.PropertyField(m_NumberOfSteps);

                bool warning = false;
                foreach (var obj in serializedObject.targetObjects)
                {
                    Scrollbar           scrollbar = obj as Scrollbar;
                    Scrollbar.Direction dir       = scrollbar.direction;
                    if (dir == Scrollbar.Direction.LeftToRight || dir == Scrollbar.Direction.RightToLeft)
                    {
                        warning = (scrollbar.navigation.mode != Navigation.Mode.Automatic && (scrollbar.FindSelectableOnLeft() != null || scrollbar.FindSelectableOnRight() != null));
                    }
                    else
                    {
                        warning = (scrollbar.navigation.mode != Navigation.Mode.Automatic && (scrollbar.FindSelectableOnDown() != null || scrollbar.FindSelectableOnUp() != null));
                    }
                }

                if (warning)
                {
                    EditorGUILayout.HelpBox("The selected scrollbar direction conflicts with navigation. Not all navigation options may work.", MessageType.Warning);
                }

                EditorGUILayout.Space();
                // Draw the event notification options
                EditorGUILayout.PropertyField(m_OnValueChanged);
            }
            else
            {
                EditorGUILayout.HelpBox("Specify a RectTransform for the scrollbar handle. It must have a parent RectTransform that the handle can slide within.", MessageType.Info);
            }

            serializedObject.ApplyModifiedProperties();
        }
示例#11
0
 public UIScrollbar Direction(Scrollbar.Direction direction)
 {
     scrollbar.direction = direction;
     return(this);
 }
示例#12
0
        /// <summary>
        /// <para>See: Editor.OnInspectorGUI.</para>
        /// </summary>
        public override void OnInspectorGUI()
        {
            base.OnInspectorGUI();
            EditorGUILayout.Space();
            base.serializedObject.Update();
            EditorGUI.BeginChangeCheck();
            RectTransform transform = EditorGUILayout.ObjectField("Handle Rect", this.m_HandleRect.objectReferenceValue, typeof(RectTransform), true, new GUILayoutOption[0]) as RectTransform;

            if (EditorGUI.EndChangeCheck())
            {
                List <UnityEngine.Object> list = new List <UnityEngine.Object> {
                    transform
                };
                foreach (UnityEngine.Object obj2 in this.m_HandleRect.serializedObject.targetObjects)
                {
                    MonoBehaviour item = obj2 as MonoBehaviour;
                    if (item != null)
                    {
                        list.Add(item);
                        list.Add(item.GetComponent <RectTransform>());
                    }
                }
                Undo.RecordObjects(list.ToArray(), "Change Handle Rect");
                this.m_HandleRect.objectReferenceValue = transform;
            }
            if (this.m_HandleRect.objectReferenceValue != null)
            {
                EditorGUI.BeginChangeCheck();
                EditorGUILayout.PropertyField(this.m_Direction, new GUILayoutOption[0]);
                if (EditorGUI.EndChangeCheck())
                {
                    Scrollbar.Direction enumValueIndex = (Scrollbar.Direction) this.m_Direction.enumValueIndex;
                    foreach (UnityEngine.Object obj3 in base.serializedObject.targetObjects)
                    {
                        (obj3 as Scrollbar).SetDirection(enumValueIndex, true);
                    }
                }
                EditorGUILayout.PropertyField(this.m_Value, new GUILayoutOption[0]);
                EditorGUILayout.PropertyField(this.m_Size, new GUILayoutOption[0]);
                EditorGUILayout.PropertyField(this.m_NumberOfSteps, new GUILayoutOption[0]);
                bool flag = false;
                foreach (UnityEngine.Object obj4 in base.serializedObject.targetObjects)
                {
                    Scrollbar scrollbar2 = obj4 as Scrollbar;
                    switch (scrollbar2.direction)
                    {
                    case Scrollbar.Direction.LeftToRight:
                    case Scrollbar.Direction.RightToLeft:
                        flag = (scrollbar2.navigation.mode != Navigation.Mode.Automatic) && ((scrollbar2.FindSelectableOnLeft() != null) || (scrollbar2.FindSelectableOnRight() != null));
                        break;

                    default:
                        flag = (scrollbar2.navigation.mode != Navigation.Mode.Automatic) && ((scrollbar2.FindSelectableOnDown() != null) || (scrollbar2.FindSelectableOnUp() != null));
                        break;
                    }
                }
                if (flag)
                {
                    EditorGUILayout.HelpBox("The selected scrollbar direction conflicts with navigation. Not all navigation options may work.", MessageType.Warning);
                }
                EditorGUILayout.Space();
                EditorGUILayout.PropertyField(this.m_OnValueChanged, new GUILayoutOption[0]);
            }
            else
            {
                EditorGUILayout.HelpBox("Specify a RectTransform for the scrollbar handle. It must have a parent RectTransform that the handle can slide within.", MessageType.Info);
            }
            base.serializedObject.ApplyModifiedProperties();
        }
示例#13
0
        public override void OnInspectorGUI()
        {
            base.OnInspectorGUI();
            EditorGUILayout.Space();
            base.serializedObject.Update();
            EditorGUI.BeginChangeCheck();
            RectTransform rectTransform = EditorGUILayout.ObjectField("Handle Rect", this.m_HandleRect.objectReferenceValue, typeof(RectTransform), true, new GUILayoutOption[0]) as RectTransform;

            if (EditorGUI.EndChangeCheck())
            {
                List <UnityEngine.Object> list = new List <UnityEngine.Object>();
                list.Add(rectTransform);
                UnityEngine.Object[] targetObjects = this.m_HandleRect.serializedObject.targetObjects;
                for (int i = 0; i < targetObjects.Length; i++)
                {
                    UnityEngine.Object @object       = targetObjects[i];
                    MonoBehaviour      monoBehaviour = @object as MonoBehaviour;
                    if (!(monoBehaviour == null))
                    {
                        list.Add(monoBehaviour);
                        list.Add(monoBehaviour.GetComponent <RectTransform>());
                    }
                }
                Undo.RecordObjects(list.ToArray(), "Change Handle Rect");
                this.m_HandleRect.objectReferenceValue = rectTransform;
            }
            if (this.m_HandleRect.objectReferenceValue != null)
            {
                EditorGUI.BeginChangeCheck();
                EditorGUILayout.PropertyField(this.m_Direction, new GUILayoutOption[0]);
                if (EditorGUI.EndChangeCheck())
                {
                    Scrollbar.Direction  enumValueIndex = (Scrollbar.Direction) this.m_Direction.enumValueIndex;
                    UnityEngine.Object[] targetObjects2 = base.serializedObject.targetObjects;
                    for (int j = 0; j < targetObjects2.Length; j++)
                    {
                        UnityEngine.Object object2   = targetObjects2[j];
                        Scrollbar          scrollbar = object2 as Scrollbar;
                        scrollbar.SetDirection(enumValueIndex, true);
                    }
                }
                EditorGUILayout.PropertyField(this.m_Value, new GUILayoutOption[0]);
                EditorGUILayout.PropertyField(this.m_Size, new GUILayoutOption[0]);
                EditorGUILayout.PropertyField(this.m_NumberOfSteps, new GUILayoutOption[0]);
                bool flag = false;
                UnityEngine.Object[] targetObjects3 = base.serializedObject.targetObjects;
                for (int k = 0; k < targetObjects3.Length; k++)
                {
                    UnityEngine.Object  object3    = targetObjects3[k];
                    Scrollbar           scrollbar2 = object3 as Scrollbar;
                    Scrollbar.Direction direction  = scrollbar2.direction;
                    if (direction == Scrollbar.Direction.LeftToRight || direction == Scrollbar.Direction.RightToLeft)
                    {
                        flag = (scrollbar2.navigation.mode != Navigation.Mode.Automatic && (scrollbar2.FindSelectableOnLeft() != null || scrollbar2.FindSelectableOnRight() != null));
                    }
                    else
                    {
                        flag = (scrollbar2.navigation.mode != Navigation.Mode.Automatic && (scrollbar2.FindSelectableOnDown() != null || scrollbar2.FindSelectableOnUp() != null));
                    }
                }
                if (flag)
                {
                    EditorGUILayout.HelpBox("The selected scrollbar direction conflicts with navigation. Not all navigation options may work.", MessageType.Warning);
                }
                EditorGUILayout.Space();
                EditorGUILayout.PropertyField(this.m_OnValueChanged, new GUILayoutOption[0]);
            }
            else
            {
                EditorGUILayout.HelpBox("Specify a RectTransform for the scrollbar handle. It must have a parent RectTransform that the handle can slide within.", MessageType.Info);
            }
            base.serializedObject.ApplyModifiedProperties();
        }
示例#14
0
 private void OnDirectionChanged(Scrollbar.Direction newValue)
 {
     scrollbar.direction = newValue;
 }