IEnumerator FindHovering()
        {
            while (showLabel && MouseOver)
            {
                using (var enu = ItemToggles.GetEnumerator())
                {
                    while (enu.MoveNext())
                    {
                        var item = enu.Current;
                        var t    = item.Value.transform as RectTransform;
                        if (RectTransformUtility.RectangleContainsScreenPoint(scrollRect.viewport.transform as RectTransform, Input.mousePosition))
                        {
                            if (RectTransformUtility.RectangleContainsScreenPoint(t, Input.mousePosition))
                            {
                                if (labelInfo.name == null || labelInfo != item.Key)
                                {
                                    labelInfo     = item.Key;
                                    labelItem     = item.Value;
                                    labelFadeTime = 1.5f;
                                    if (labelFadingCoroutine != null)
                                    {
                                        StopCoroutine(labelFadingCoroutine);
                                    }
                                    labelFadingCoroutine = StartCoroutine(LabelFading());
                                }
                                break;
                            }
                        }
                    }
                }
                yield return(new WaitForSecondsRealtime(0.1f));

                yield return(new WaitForEndOfFrame());
            }
        }
Ejemplo n.º 2
0
 public void RemoveItem(T s)
 {
     if (ItemToggles != null && ItemToggles.ContainsKey(s))
     {
         GameObject g = ItemToggles[s].gameObject;
         g.GetComponent <Toggle>().onValueChanged.RemoveAllListeners();
         g.SetActive(false);
         Destroy(g);
         ItemToggles.Remove(s);
     }
 }
 private void Update()
 {
     if (Input.anyKeyDown)
     {
         if (MouseOver && MouseOver == this)
         {
             if (Input.GetKeyDown(KeyCode.A) || Input.GetKeyDown(KeyCode.LeftArrow))
             {
                 OnSelectLeft();
                 selectedToggle.Select();
                 OnItemSelected(false);
                 labelInfo     = selected;
                 labelItem     = selectedToggle;
                 labelFadeTime = 1.5f;
                 showLabel     = true;
                 if (labelFadingCoroutine != null)
                 {
                     StopCoroutine(labelFadingCoroutine);
                 }
                 labelFadingCoroutine = StartCoroutine(LabelFading());
             }
             else if (Input.GetKeyDown(KeyCode.D) || Input.GetKeyDown(KeyCode.RightArrow))
             {
                 OnSelectRight();
                 selectedToggle.Select();
                 OnItemSelected(false);
                 labelInfo     = selected;
                 labelItem     = selectedToggle;
                 labelFadeTime = 1.5f;
                 showLabel     = true;
                 if (labelFadingCoroutine != null)
                 {
                     StopCoroutine(labelFadingCoroutine);
                 }
                 labelFadingCoroutine = StartCoroutine(LabelFading());
             }
         }
     }
     if (showLabel)
     {
         var enu = ItemToggles.GetEnumerator();
         while (enu.MoveNext())
         {
             var item = enu.Current;
             var t    = item.Value.transform as RectTransform;
             if (RectTransformUtility.RectangleContainsScreenPoint(t, Input.mousePosition))
             {
                 labelInfo = item.Key;
                 break;
             }
         }
     }
 }
 protected override void AddItem(TextureSetDefinition s)
 {
     if (ItemToggles == null)
     {
         ItemToggles = new Dictionary <TextureSetDefinition, Toggle>();
     }
     if (!ItemToggles.ContainsKey(s))
     {
         var r = Instantiate(itemTogglePrefab.gameObject);
         r.transform.SetParent(scrollRect.content);
         r.gameObject.SetActive(true);
         r.GetComponent <RawImage>().texture = s.diff;
         Toggle t = r.GetComponent <Toggle>();
         t.onValueChanged.AddListener(OnItemSelected);
         if (ItemToggles.Count == 0)
         {
             t.SetIsOnWithoutNotify(true);
         }
         ItemToggles.Add(s, t);
     }
 }
Ejemplo n.º 5
0
 protected virtual void AddItem(T s)
 {
     if (ItemToggles == null)
     {
         ItemToggles = new Dictionary <T, Toggle>();
     }
     if (!ItemToggles.ContainsKey(s))
     {
         var r = Instantiate(itemTogglePrefab.gameObject);
         r.transform.SetParent(scrollRect.content);
         r.gameObject.SetActive(true);
         r.GetComponentInChildren <Text>().text = ToString(s);
         Toggle t = r.GetComponent <Toggle>();
         t.onValueChanged.AddListener(OnItemSelected);
         if (ItemToggles.Count == 0)
         {
             t.SetIsOnWithoutNotify(true);
         }
         ItemToggles.Add(s, t);
     }
 }
Ejemplo n.º 6
0
        public virtual void RefreshItems(T[] newItems)
        {
            if (newItems == null)
            {
                return;
            }
            bool refresh = Items == null || newItems != Items;

            if (Items != null)
            {
                if (Items.Length > 0 && refresh)
                {
                    foreach (var s in Items)
                    {
                        RemoveItem(s);
                    }
                }
            }
            Items = newItems;
            if (Items.Length > 0)
            {
                if (refresh)
                {
                    foreach (var r in Items)
                    {
                        AddItem(r);
                    }
                }
                if (selected != null && ItemToggles.ContainsKey(selected))
                {
                    SwitchTo(selected);
                }
                else
                {
                    SwitchTo(Items[0]);
                }
            }
        }
Ejemplo n.º 7
0
 private bool AreAllSelected()
 {
     return(ItemToggles.Count(t => !t.Active) == 0);
 }