void ChangeDirection(SelectDirection direction, Action callback = null)
    {
        if (currentSelectDirection == direction)
        {
            return;
        }

        if (positionControlCoroutine != null)
        {
            StopCoroutine(positionControlCoroutine);
        }

        currentSelectDirection = direction;
        Vector2 targetPosition = currentSelectDirection == SelectDirection.Left ? leftTextRec.anchoredPosition : rightTextRec.anchoredPosition;

        positionControlCoroutine = StartCoroutine(ChangeSelectMakerPosition(targetPosition).OnCompleted(() =>
        {
            positionControlCoroutine = null;
            ChangeTextColor(currentSelectDirection);
            if (callback != null)
            {
                callback.Invoke();
            }
        }));
    }
Exemplo n.º 2
0
    public void Selection(SelectDirection dir)      //changes the currently selected dinosaur based on user input
    {
        if (dir == SelectDirection.Up && currentPosition - numberOfCols >= 0)
        {
            currentPosition -= numberOfCols;
            statDelegates();
            MoveHighlightBox(dir);
        }
        else if (dir == SelectDirection.Down && currentPosition + numberOfCols < numberOfDinosaurs.Count)
        {
            currentPosition += numberOfCols;
            statDelegates();
            MoveHighlightBox(dir);
        }
        else if (dir == SelectDirection.Left && currentPosition - 1 >= 0)
        {
            currentPosition -= 1;
            statDelegates();
            MoveHighlightBox(dir);
        }
        else if (dir == SelectDirection.Right && currentPosition + 1 < numberOfDinosaurs.Count)
        {
            currentPosition += 1;
            statDelegates();
            MoveHighlightBox(dir);
        }

        PlayerManager.PlayerDinos[(int)player] = numberOfDinosaurs[currentPosition];
    }
 void ChangeTextColor(SelectDirection direction)
 {
     if (direction == SelectDirection.Left)
     {
         leftText.color  = selectTextColor;
         rightText.color = defaultTextColor;
     }
     else
     {
         leftText.color  = defaultTextColor;
         rightText.color = selectTextColor;
     }
 }
Exemplo n.º 4
0
        private void ChooseTextInDropDown(SelectDirection dir, bool Incremental)
        {
            using (new HourGlass())
            {
                treeView1.BeginUpdate();
                int Increment = 1;
                foreach (var item in treeView1.SelectedNodes)
                {
                    MyNode     n    = item.Tag as MyNode;
                    NavDetails nav  = n.Tag as NavDetails;
                    int        Base = Incremental ? n.OriginalCount - 1 : 0;
                    if (nav.DetectedTexts == null)
                    {
                        continue;
                    }

                    int QtyMax = n.DetectedCombo.Count - 1;
                    int index  = nav.DetectedTexts.IndexOf(n.DetectedText);
                    if (nav.DetectedTexts.Count > 1)
                    {
                        if (index >= 0 && dir == SelectDirection.Next)
                        {
                            int NewIndex = Incremental ? index + Increment + Base : index + Increment;
                            if (NewIndex > QtyMax)
                            {
                                NewIndex = QtyMax;
                            }

                            nav.Text       = nav.DetectedTexts[NewIndex];
                            n.DetectedText = nav.DetectedTexts[NewIndex];
                        }
                        else
                        {
                            if (index > 0 && index <= QtyMax)
                            {
                                nav.Text       = nav.DetectedTexts[index - Increment];
                                n.DetectedText = nav.DetectedTexts[index - Increment];
                            }
                        }


                        if (Incremental)
                        {
                            Increment++;
                        }
                    }
                    AddToTextSelected(nav);
                }
                treeView1.EndUpdate();
            }
        }
Exemplo n.º 5
0
        public ActionResult GetDirections(SelectDirection w)
        {
            try{
                List <Guid> result         = new List <Guid>();;
                var         allUser        = _userService.AllUsersId().ToList();
                var         currentMembers = _groupService.MembersId(w.GroupId).ToList();

                if (w.SelectedDirection == "Все направления")
                {
                    if (currentMembers.Count() > 0)
                    {
                        result = _groupService.ExcludeMembers(allUser, currentMembers);
                    }
                }

                else
                {
                    var users = _userService.GetUsersByDirection(w.SelectedDirection).Select(x => x.Id).ToList();
                    if (users.Count() > 0)
                    {
                        result = _groupService.ExcludeMembers(users, currentMembers);
                    }
                }


                List <UserListViewModel> model = new List <UserListViewModel>();

                if (result.Count() > 0)
                {
                    var data = _userService.GetUsersByListId(result);
                    foreach (var item in data)
                    {
                        UserListViewModel user = new UserListViewModel();
                        user.Id        = item.Id;
                        user.Name      = item.Name;
                        user.Surname   = item.Surname;
                        user.Direction = item.Direction;
                        user.Image     = item.Image;
                        model.Add(user);
                    }
                }
                model.OrderBy(x => x.Surname);
                ViewBag.GroupId = w.GroupId;
                return(PartialView("_SelectMembers", model));
            }
            catch (Exception e)

            {
                return(RedirectToAction("AddMembers"));
            }
        }
    void ChangePicture(SelectDirection direction)
    {
        Texture picture = AppData.SelectThetaPictures[direction == SelectDirection.Left ? 0 : 1];

        Vector3 temp = AppData.differenceVec;

        if (direction == SelectDirection.Right)
        {
            temp = -temp;
        }
        cameraComtroller.SetDifferenceVec(temp);

        SetPicture(picture);
    }
    void Start()
    {
        if (!AppData.CanChangePicture)
        {
            return;
        }

        button.onClick.AddListener(() =>
        {
            //反転
            SelectDirection direction = currentSelectDirection == SelectDirection.Left ? SelectDirection.Right : SelectDirection.Left;
            ChangeDirection(direction, () => ChangePicture(direction));
        });

        EventTrigger trigger = selectMakerRec.gameObject.AddComponent <EventTrigger>();

        EventTrigger.Entry onStartDrag = new EventTrigger.Entry();
        onStartDrag.eventID = EventTriggerType.BeginDrag;
        onStartDrag.callback.AddListener(OnStartDrag);
        trigger.triggers.Add(onStartDrag);

        EventTrigger.Entry onDrag = new EventTrigger.Entry();
        onDrag.eventID = EventTriggerType.Drag;
        onDrag.callback.AddListener(OnDrag);
        trigger.triggers.Add(onDrag);

        EventTrigger.Entry onEndDrag = new EventTrigger.Entry();
        onEndDrag.eventID = EventTriggerType.EndDrag;
        onEndDrag.callback.AddListener(OnPointerUp);
        trigger.triggers.Add(onEndDrag);

        selectMakerImage = selectMakerRec.GetComponent <Image>();
        buttonRect       = button.transform as RectTransform;

        Vector2 targetImageSize = button.GetComponent <RectTransform>().sizeDelta *button.transform.lossyScale.x;

        dragLimitX = targetImageSize.x;
        dragLimitY = targetImageSize.y;

        leftText         = leftTextRec.GetComponent <Text>();
        rightText        = rightTextRec.GetComponent <Text>();
        defaultTextColor = rightText.color;
        leftText.color   = selectTextColor;
    }
Exemplo n.º 8
0
 public void MoveHighlightBox(SelectDirection dir)     //controls the position of the highlighter box
 {
     if (dir == SelectDirection.Up)
     {
         highlightTranformer.localPosition = panels[currentPosition].transform.localPosition;             //shift the position of the highlight box up one
     }
     else if (dir == SelectDirection.Down)
     {
         highlightTranformer.localPosition = panels [currentPosition].transform.localPosition;
     }
     else if (dir == SelectDirection.Left)
     {
         highlightTranformer.localPosition = panels [currentPosition].transform.localPosition;
     }
     else if (dir == SelectDirection.Right)
     {
         highlightTranformer.localPosition = panels [currentPosition].transform.localPosition;
     }
 }
Exemplo n.º 9
0
        public static int SelectNext(int index, int count, SelectDirection direction, bool circular)
        {
            if (count == 0)
            {
                return(-1);
            }
            if (count == 1)
            {
                return(0);
            }

            switch (direction)
            {
            case SelectDirection.First:
                return(0);

            case SelectDirection.Prev:
                if (index > 0)
                {
                    return(index - 1);
                }
                return(circular ? count - 1 : 0);

            case SelectDirection.Next:
                if (index < count - 1)
                {
                    return(index + 1);
                }
                return(circular ? 0 : count - 1);

            case SelectDirection.Last:
                return(count - 1);

            default:
                throw new ArgumentOutOfRangeException(nameof(direction));
            }
        }
Exemplo n.º 10
0
        private void DrawItem(ListItem item, Rect area, float x, float y, bool focus, bool selected)
        {
            bool flag  = item == this.dragTarget;
            bool flag2 = selected;

            if (selected)
            {
                Texture2D image = !focus ? this.greyTex : this.blueTex;
                GUI.DrawTexture(new Rect(area.x, y, area.width, 16f), image, ScaleMode.StretchToFill, false);
            }
            else if (!flag)
            {
                if (((this.dragTarget != null) && (item == this.dragTarget.Parent)) && (this.dragAdjust != SelectDirection.Current))
                {
                    GUI.DrawTexture(new Rect(area.x, y, area.width, 16f), this.yellowTex, ScaleMode.StretchToFill, false);
                    flag2 = true;
                }
            }
            else
            {
                SelectDirection dragAdjust = this.dragAdjust;
                if (dragAdjust == SelectDirection.Up)
                {
                    if (item.PrevOpenVisible != item.Parent)
                    {
                        GUI.DrawTexture(new Rect(x, y - 1f, area.width, 2f), this.yellowTex, ScaleMode.StretchToFill, false);
                    }
                }
                else if (dragAdjust == SelectDirection.Down)
                {
                    GUI.DrawTexture(new Rect(x, (y + 16f) - 1f, area.width, 2f), this.yellowTex, ScaleMode.StretchToFill, false);
                }
                else if (item.CanAccept)
                {
                    GUI.DrawTexture(new Rect(area.x, y, area.width, 16f), this.yellowTex, ScaleMode.StretchToFill, false);
                    flag2 = true;
                }
            }
            if (item.HasActions)
            {
                for (int i = 0; i < item.Actions.Length; i++)
                {
                    this.calcSizeTmpContent.text = item.Actions[i];
                    Vector2 vector = GUI.skin.button.CalcSize(this.calcSizeTmpContent);
                    if (GUI.Button(new Rect(x, y, vector.x, 16f), item.Actions[i]))
                    {
                        this.actionDelegate(item, i);
                    }
                    x += vector.x + 4f;
                }
            }
            if (item.CanExpand)
            {
                EditorGUI.Foldout(new Rect(x, y, 16f, 16f), item.Expanded, GUIContent.none);
            }
            Texture icon         = item.Icon;
            Color   color        = GUI.color;
            Color   contentColor = GUI.contentColor;

            if (item.Dummy)
            {
                GUI.color = new Color(0.65f, 0.65f, 0.65f);
            }
            if (!item.Dummy)
            {
                if (icon == null)
                {
                    icon = InternalEditorUtility.GetIconForFile(item.Name);
                }
                Rect position = new Rect(x + 14f, y, 16f, 16f);
                if (icon != null)
                {
                    GUI.DrawTexture(position, icon);
                }
                if (item.Asset != null)
                {
                    Rect itemRect = position;
                    itemRect.width += 12f;
                    itemRect.x     -= 6f;
                    Overlay.DrawOverlay(item.Asset, itemRect);
                }
            }
            string  t       = this.DisplayName(item);
            Vector2 vector2 = EditorStyles.label.CalcSize(EditorGUIUtility.TempContent(t));
            float   num2    = x + 32f;

            if (flag2)
            {
                GUI.contentColor = new Color(3f, 3f, 3f);
                GUI.Label(new Rect(num2, y, area.width - num2, 18f), t);
            }
            else
            {
                GUI.Label(new Rect(num2, y, area.width - num2, 18f), t);
            }
            if (this.HasHiddenMetaFile(item))
            {
                GUI.color = new Color(0.55f, 0.55f, 0.55f);
                float num3 = (num2 + vector2.x) + 2f;
                GUI.Label(new Rect(num3, y, area.width - num3, 18f), "+meta");
            }
            GUI.contentColor = contentColor;
            GUI.color        = color;
        }
Exemplo n.º 11
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="input"></param>
 /// <param name="max">全要素数</param>
 /// <param name="freq">負ならループしない</param>
 /// <param name="length">一行(列)の長さ</param>
 /// <param name="dir">行方向だと+1か、列方向だとか</param>
 public PlaneSelecter(ControlState input, int max, int freq, int length, SelectDirection dir)
     : this(input, max, freq, freq, length, dir)
 {
 }
Exemplo n.º 12
0
 public PlaneSelecter(ControlState input, int max, int freq, int loopBegin, int length, SelectDirection dir)
     : base(input, max, freq, loopBegin)
 {
     Direction = dir;
     LineLength = length;
 }
Exemplo n.º 13
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="input">使用する入力State 普通はキー入力そのままの</param>
 /// <param name="max">要素数</param>
 /// <param name="freq">押しっぱなし自動移動の速度、負ならループしない</param>
 /// <param name="dir">縦か横か</param>
 public LinearSelecter(ControlState input, int max, int freq, SelectDirection dir)
     : this(input, max, freq, freq, dir)
 {
 }
Exemplo n.º 14
0
 public LinearSelecter(ControlState input, int max, int freq, int loopBegin, SelectDirection dir)
     : base(input, max, freq, loopBegin)
 {
     Direction = dir;
 }
Exemplo n.º 15
0
        private bool HandleMouse(Rect area)
        {
            Event current = Event.current;
            bool  flag    = false;
            bool  flag2   = area.Contains(current.mousePosition);

            if ((current.type == EventType.MouseDown) && flag2)
            {
                flag                       = true;
                this.dragCount             = 0;
                GUIUtility.keyboardControl = 0;
                this.singleSelect          = this.GetItemAt(area, current.mousePosition);
                if ((this.singleSelect != null) && !this.singleSelect.Dummy)
                {
                    if (((current.button == 0) && (current.clickCount > 1)) && (this.singleSelect.Asset != null))
                    {
                        this.singleSelect.Asset.Edit();
                    }
                    if (current.button < 2)
                    {
                        float num = area.x + ((this.singleSelect.Indent - 1) * 0x12);
                        if (((current.mousePosition.x >= num) && (current.mousePosition.x < (num + 16f))) && this.singleSelect.CanExpand)
                        {
                            this.singleSelect.Expanded = !this.singleSelect.Expanded;
                            this.CallExpandedEvent(this.singleSelect, true);
                            this.singleSelect = null;
                        }
                        else if (current.control || current.command)
                        {
                            if (current.button == 1)
                            {
                                this.SelectedAdd(this.singleSelect);
                            }
                            else
                            {
                                this.SelectedToggle(this.singleSelect);
                            }
                            this.singleSelect = null;
                        }
                        else if (current.shift)
                        {
                            this.SelectionFlow(this.singleSelect);
                            this.singleSelect = null;
                        }
                        else if (!this.IsSelected(this.singleSelect))
                        {
                            this.SelectedSet(this.singleSelect);
                            this.singleSelect = null;
                        }
                    }
                }
                else if (current.button == 0)
                {
                    this.SelectedClear();
                    this.singleSelect = null;
                }
            }
            else if (((current.type == EventType.MouseUp) || (current.type == EventType.ContextClick)) && flag2)
            {
                GUIUtility.keyboardControl = 0;
                this.singleSelect          = this.GetItemAt(area, current.mousePosition);
                this.dragCount             = 0;
                flag = true;
                if ((this.singleSelect != null) && !this.singleSelect.Dummy)
                {
                    if (current.type == EventType.ContextClick)
                    {
                        this.singleSelect = null;
                        if (!this.IsSelectedAsset() && !string.IsNullOrEmpty(this.menuFolder))
                        {
                            s_uniqueIDList[this.uniqueID] = this;
                            EditorUtility.DisplayPopupMenu(new Rect(current.mousePosition.x, current.mousePosition.y, 0f, 0f), this.menuFolder, new MenuCommand(null, this.uniqueID));
                        }
                        else if (!string.IsNullOrEmpty(this.menuDefault))
                        {
                            s_uniqueIDList[this.uniqueID] = this;
                            EditorUtility.DisplayPopupMenu(new Rect(current.mousePosition.x, current.mousePosition.y, 0f, 0f), this.menuDefault, new MenuCommand(null, this.uniqueID));
                        }
                    }
                    else if (((((current.type != EventType.ContextClick) && (current.button == 0)) && (!current.control && !current.command)) && !current.shift) && this.IsSelected(this.singleSelect))
                    {
                        this.SelectedSet(this.singleSelect);
                        this.singleSelect = null;
                    }
                }
            }
            if ((current.type == EventType.MouseDrag) && flag2)
            {
                this.dragCount++;
                if ((this.dragCount > 2) && (Selection.objects.Length > 0))
                {
                    DragAndDrop.PrepareStartDrag();
                    if (this.singleSelect != null)
                    {
                        DragAndDrop.objectReferences = new UnityEngine.Object[] { this.singleSelect.Asset.Load() };
                    }
                    else
                    {
                        DragAndDrop.objectReferences = Selection.objects;
                    }
                    DragAndDrop.StartDrag("Move");
                }
            }
            if (current.type == EventType.DragUpdated)
            {
                flag = true;
                DragAndDrop.visualMode = DragAndDropVisualMode.Move;
                this.dragTarget        = this.GetItemAt(area, current.mousePosition);
                if (this.dragTarget != null)
                {
                    if (this.IsSelected(this.dragTarget))
                    {
                        this.dragTarget = null;
                    }
                    else if (this.dragAcceptOnly)
                    {
                        if (!this.dragTarget.CanAccept)
                        {
                            this.dragTarget = null;
                        }
                    }
                    else
                    {
                        bool  flag3 = !this.dragTarget.CanAccept || (this.dragTarget.PrevOpenVisible != this.dragTarget.Parent);
                        bool  flag4 = !this.dragTarget.CanAccept || (this.dragTarget.NextOpenVisible != this.dragTarget.FirstChild);
                        float num2  = !this.dragTarget.CanAccept ? 8f : 2f;
                        int   num3  = (int)((current.mousePosition.y - area.y) / 16f);
                        float num4  = area.y + (num3 * 16f);
                        this.dragAdjust = SelectDirection.Current;
                        if (flag3 && (current.mousePosition.y <= (num4 + num2)))
                        {
                            this.dragAdjust = SelectDirection.Up;
                        }
                        else if (flag4 && (current.mousePosition.y >= ((num4 + 16f) - num2)))
                        {
                            this.dragAdjust = SelectDirection.Down;
                        }
                    }
                }
            }
            if ((current.type == EventType.DragPerform) && (this.dragTarget != null))
            {
                ListItem item = (this.dragAdjust != SelectDirection.Current) ? this.dragTarget.Parent : this.dragTarget;
                if (((this.dragDelegate != null) && (item != null)) && item.CanAccept)
                {
                    this.dragDelegate(item.Change);
                }
                this.dragTarget = null;
            }
            if (current.type == EventType.DragExited)
            {
                this.dragTarget = null;
            }
            return(flag);
        }
Exemplo n.º 16
0
        private void ChooseTextInDropDown(SelectDirection dir, bool Incremental)
        {
            using (new HourGlass())
            {
                treeView1.BeginUpdate();
                int Increment = 1;
                foreach (var item in treeView1.SelectedNodes)
                {
                    MyNode n = item.Tag as MyNode;
                    NavDetails nav = n.Tag as NavDetails;
                    int Base = Incremental ? n.OriginalCount - 1 : 0;
                    if (nav.DetectedTexts == null)
                        continue;

                    int QtyMax = n.DetectedCombo.Count - 1;
                    int index = nav.DetectedTexts.IndexOf(n.DetectedText);
                    if (nav.DetectedTexts.Count > 1)
                    {
                        if (index >= 0 && dir == SelectDirection.Next)
                        {
                            int NewIndex = Incremental ? index + Increment + Base : index + Increment;
                            if (NewIndex > QtyMax)
                            {
                                NewIndex = QtyMax;
                            }

                            nav.Text = nav.DetectedTexts[NewIndex];
                            n.DetectedText = nav.DetectedTexts[NewIndex];
                        } else
                        {
                            if (index > 0 && index <= QtyMax)
                            {
                                nav.Text = nav.DetectedTexts[index - Increment];
                                n.DetectedText = nav.DetectedTexts[index - Increment];
                            }
                        }

                        if (Incremental)
                            Increment++;

                    }
                    AddToTextSelected(nav);
                }
                treeView1.EndUpdate();
            }
        }
Exemplo n.º 17
0
 private bool HandleMouse(Rect area)
 {
     Event current = Event.current;
     bool flag = false;
     bool flag2 = area.Contains(current.mousePosition);
     if ((current.type == EventType.MouseDown) && flag2)
     {
         flag = true;
         this.dragCount = 0;
         GUIUtility.keyboardControl = 0;
         this.singleSelect = this.GetItemAt(area, current.mousePosition);
         if ((this.singleSelect != null) && !this.singleSelect.Dummy)
         {
             if (((current.button == 0) && (current.clickCount > 1)) && (this.singleSelect.Asset != null))
             {
                 this.singleSelect.Asset.Edit();
             }
             if (current.button < 2)
             {
                 float num = area.x + ((this.singleSelect.Indent - 1) * 0x12);
                 if (((current.mousePosition.x >= num) && (current.mousePosition.x < (num + 16f))) && this.singleSelect.CanExpand)
                 {
                     this.singleSelect.Expanded = !this.singleSelect.Expanded;
                     this.CallExpandedEvent(this.singleSelect, true);
                     this.singleSelect = null;
                 }
                 else if (current.control || current.command)
                 {
                     if (current.button == 1)
                     {
                         this.SelectedAdd(this.singleSelect);
                     }
                     else
                     {
                         this.SelectedToggle(this.singleSelect);
                     }
                     this.singleSelect = null;
                 }
                 else if (current.shift)
                 {
                     this.SelectionFlow(this.singleSelect);
                     this.singleSelect = null;
                 }
                 else if (!this.IsSelected(this.singleSelect))
                 {
                     this.SelectedSet(this.singleSelect);
                     this.singleSelect = null;
                 }
             }
         }
         else if (current.button == 0)
         {
             this.SelectedClear();
             this.singleSelect = null;
         }
     }
     else if (((current.type == EventType.MouseUp) || (current.type == EventType.ContextClick)) && flag2)
     {
         GUIUtility.keyboardControl = 0;
         this.singleSelect = this.GetItemAt(area, current.mousePosition);
         this.dragCount = 0;
         flag = true;
         if ((this.singleSelect != null) && !this.singleSelect.Dummy)
         {
             if (current.type == EventType.ContextClick)
             {
                 this.singleSelect = null;
                 if (!this.IsSelectedAsset() && !string.IsNullOrEmpty(this.menuFolder))
                 {
                     s_uniqueIDList[this.uniqueID] = this;
                     EditorUtility.DisplayPopupMenu(new Rect(current.mousePosition.x, current.mousePosition.y, 0f, 0f), this.menuFolder, new MenuCommand(null, this.uniqueID));
                 }
                 else if (!string.IsNullOrEmpty(this.menuDefault))
                 {
                     s_uniqueIDList[this.uniqueID] = this;
                     EditorUtility.DisplayPopupMenu(new Rect(current.mousePosition.x, current.mousePosition.y, 0f, 0f), this.menuDefault, new MenuCommand(null, this.uniqueID));
                 }
             }
             else if (((((current.type != EventType.ContextClick) && (current.button == 0)) && (!current.control && !current.command)) && !current.shift) && this.IsSelected(this.singleSelect))
             {
                 this.SelectedSet(this.singleSelect);
                 this.singleSelect = null;
             }
         }
     }
     if ((current.type == EventType.MouseDrag) && flag2)
     {
         this.dragCount++;
         if ((this.dragCount > 2) && (Selection.objects.Length > 0))
         {
             DragAndDrop.PrepareStartDrag();
             if (this.singleSelect != null)
             {
                 DragAndDrop.objectReferences = new Object[] { this.singleSelect.Asset.Load() };
             }
             else
             {
                 DragAndDrop.objectReferences = Selection.objects;
             }
             DragAndDrop.StartDrag("Move");
         }
     }
     if (current.type == EventType.DragUpdated)
     {
         flag = true;
         DragAndDrop.visualMode = DragAndDropVisualMode.Move;
         this.dragTarget = this.GetItemAt(area, current.mousePosition);
         if (this.dragTarget != null)
         {
             if (this.IsSelected(this.dragTarget))
             {
                 this.dragTarget = null;
             }
             else if (this.dragAcceptOnly)
             {
                 if (!this.dragTarget.CanAccept)
                 {
                     this.dragTarget = null;
                 }
             }
             else
             {
                 bool flag3 = !this.dragTarget.CanAccept || (this.dragTarget.PrevOpenVisible != this.dragTarget.Parent);
                 bool flag4 = !this.dragTarget.CanAccept || (this.dragTarget.NextOpenVisible != this.dragTarget.FirstChild);
                 float num2 = !this.dragTarget.CanAccept ? 8f : 2f;
                 int num3 = (int) ((current.mousePosition.y - area.y) / 16f);
                 float num4 = area.y + (num3 * 16f);
                 this.dragAdjust = SelectDirection.Current;
                 if (flag3 && (current.mousePosition.y <= (num4 + num2)))
                 {
                     this.dragAdjust = SelectDirection.Up;
                 }
                 else if (flag4 && (current.mousePosition.y >= ((num4 + 16f) - num2)))
                 {
                     this.dragAdjust = SelectDirection.Down;
                 }
             }
         }
     }
     if ((current.type == EventType.DragPerform) && (this.dragTarget != null))
     {
         ListItem item = (this.dragAdjust != SelectDirection.Current) ? this.dragTarget.Parent : this.dragTarget;
         if (((this.dragDelegate != null) && (item != null)) && item.CanAccept)
         {
             this.dragDelegate(item.Change);
         }
         this.dragTarget = null;
     }
     if (current.type == EventType.DragExited)
     {
         this.dragTarget = null;
     }
     return flag;
 }
Exemplo n.º 18
0
        private bool HandleMouse(Rect area)
        {
            Event e       = Event.current;
            bool  repaint = false;

            // Handle mouse down clicks
            bool mouseInArea = area.Contains(e.mousePosition);

            if (e.type == EventType.MouseDown && mouseInArea)
            {
                repaint   = true;
                dragCount = 0;
                GUIUtility.keyboardControl = 0;
                singleSelect = GetItemAt(area, e.mousePosition);

                // Ensure a valid selection
                if (singleSelect != null && !singleSelect.Dummy)
                {
                    // Double click handling
                    if (e.button == 0 && e.clickCount > 1 && singleSelect.Asset != null)
                    {
                        singleSelect.Asset.Edit();
                    }

                    // Expand/Contract
                    if (e.button < 2)
                    {
                        float x = area.x + ((singleSelect.Indent - 1) * 18);
                        if (e.mousePosition.x >= x && e.mousePosition.x < x + 16 && singleSelect.CanExpand)
                        {
                            singleSelect.Expanded = !singleSelect.Expanded;
                            CallExpandedEvent(singleSelect, true);
                            singleSelect = null;
                        }
                        else if (e.control || e.command)
                        {
                            // Right clicking can never de-toggle something
                            if (e.button == 1)
                            {
                                SelectedAdd(singleSelect);
                            }
                            else
                            {
                                SelectedToggle(singleSelect);
                            }
                            singleSelect = null;
                        }
                        else if (e.shift)
                        {
                            SelectionFlow(singleSelect);
                            singleSelect = null;
                        }
                        else
                        {
                            if (!IsSelected(singleSelect))
                            {
                                SelectedSet(singleSelect);
                                // Do not set singleSelect to null in order for drag to
                                // know what is dragged
                                singleSelect = null;
                            }
                        }
                    }
                }
                else if (e.button == 0)
                {
                    // Clear selection when a click was made on nothing
                    SelectedClear();
                    singleSelect = null;
                }
            }
            // Handle mouse up clicks
            else if ((e.type == EventType.MouseUp || e.type == EventType.ContextClick) && mouseInArea)
            {
                GUIUtility.keyboardControl = 0;
                singleSelect = GetItemAt(area, e.mousePosition);
                dragCount    = 0;
                repaint      = true;

                if (singleSelect != null && !singleSelect.Dummy)
                {
                    // right click menus - we pass the static index of the list so the menu can find what is selected
                    if (e.type == EventType.ContextClick)
                    {
                        singleSelect = null;

                        if (!IsSelectedAsset() && !string.IsNullOrEmpty(menuFolder))
                        {
                            s_uniqueIDList[uniqueID] = this;
                            EditorUtility.DisplayPopupMenu(new Rect(e.mousePosition.x, e.mousePosition.y, 0, 0), menuFolder, new MenuCommand(null, uniqueID));
                        }
                        else if (!string.IsNullOrEmpty(menuDefault))
                        {
                            s_uniqueIDList[uniqueID] = this;
                            EditorUtility.DisplayPopupMenu(new Rect(e.mousePosition.x, e.mousePosition.y, 0, 0), menuDefault, new MenuCommand(null, uniqueID));
                        }
                    }
                    // Left click up should set selection if singleSelect is in selection since
                    // this is the case where the user has clicked and hold on a selection (which may start a drag or not)
                    // and then released it.
                    else if (e.type != EventType.ContextClick && e.button == 0 && !(e.control || e.command || e.shift))
                    {
                        if (IsSelected(singleSelect))
                        {
                            SelectedSet(singleSelect);
                            singleSelect = null;
                        }
                    }
                }
            }

            if (e.type == EventType.MouseDrag && mouseInArea)
            {
                // Ive added this to stop the accidental drag messages that pop up
                // you only seem to get one when its not intentional so this should
                // give a better effect.
                ++dragCount;

                if (dragCount > 2 && Selection.objects.Length > 0)
                {
                    DragAndDrop.PrepareStartDrag();
                    if (singleSelect != null)
                    {
                        DragAndDrop.objectReferences = new UnityEngine.Object[] { singleSelect.Asset.Load() };
                    }
                    else
                    {
                        DragAndDrop.objectReferences = Selection.objects;
                    }
                    DragAndDrop.StartDrag("Move");
                }
            }

            // Drag has been updated
            if (e.type == EventType.DragUpdated)
            {
                repaint = true;
                DragAndDrop.visualMode = DragAndDropVisualMode.Move;
                dragTarget             = GetItemAt(area, e.mousePosition);

                // Dont target selected items
                if (dragTarget != null)
                {
                    if (IsSelected(dragTarget))
                    {
                        dragTarget = null;
                    }
                    else
                    {
                        if (dragAcceptOnly)
                        {
                            if (!dragTarget.CanAccept)
                            {
                                dragTarget = null;
                            }
                        }
                        else
                        {
                            bool  canPrev = !dragTarget.CanAccept || dragTarget.PrevOpenVisible != dragTarget.Parent;
                            bool  canNext = !dragTarget.CanAccept || dragTarget.NextOpenVisible != dragTarget.FirstChild;
                            float size    = dragTarget.CanAccept ? 2 : c_lineHeight / 2;
                            int   index   = (int)((e.mousePosition.y - area.y) / c_lineHeight);
                            float pos     = area.y + (index * c_lineHeight);
                            dragAdjust = SelectDirection.Current;

                            if (canPrev && e.mousePosition.y <= pos + size)
                            {
                                dragAdjust = SelectDirection.Up;
                            }
                            else if (canNext && e.mousePosition.y >= pos + c_lineHeight - size)
                            {
                                dragAdjust = SelectDirection.Down;
                            }
                        }
                    }
                }
            }

            // Drag and drop completion
            if (e.type == EventType.DragPerform)
            {
                if (dragTarget != null)
                {
                    ListItem drag = dragAdjust == SelectDirection.Current ? dragTarget : dragTarget.Parent;
                    if (dragDelegate != null && drag != null && drag.CanAccept)
                    {
                        dragDelegate(drag.Change);
                    }

                    dragTarget = null;
                }
            }

            if (e.type == EventType.DragExited)
            {
                dragTarget = null;
            }
            return(repaint);
        }
Exemplo n.º 19
0
 public void Select(SelectDirection direction, bool cyclic = false)
 {
     if (cyclic)
     {
         if ((direction == SelectDirection.Next)
             && (_elements[_active] == _elements.Last(x => x.Enabled)))
             Select(_elements.FindIndex(x => x.Enabled));
         else if ((direction == SelectDirection.Prev)
                  && (_elements[_active] == _elements.First(x => x.Enabled)))
             Select(_elements.FindLastIndex(x => x.Enabled));
         else Select(direction);
     }
     else
     {
         if ((direction == SelectDirection.Next)
             && (_elements[_active] == _elements.Last(x => x.Enabled)))
             return;
         if ((direction == SelectDirection.Prev)
             && (_elements[_active] == _elements.First(x => x.Enabled)))
             return;
         Select(direction == SelectDirection.Next
             ? _elements.FindIndex(_active + 1, x => x.Enabled)
             : _elements.FindLastIndex(_active - 1, _active, x => x.Enabled));
     }
 }