Inheritance: UnityEngine.EventSystems.UIBehaviour, IMoveHandler, IPointerDownHandler, IPointerUpHandler, IPointerEnterHandler, IPointerExitHandler, ISelectHandler, IDeselectHandler
		protected override void DoStateTransition(Selectable.SelectionState state, bool instant) {

			base.DoStateTransition(state, instant);

			this.interactable = base.interactable;

		}
		protected override void DoStateTransition(Selectable.SelectionState state, bool instant) {

			base.DoStateTransition(state, instant);

			this.ApplyState(state, instant);

		}
		protected override void DoStateTransition(Selectable.SelectionState state, bool instant) {

			base.DoStateTransition(state, instant);

			if (this.label != null) {

				switch (this.currentSelectionState) {
					
					case SelectionState.Disabled:
						this.label.CrossFadeColor(this.labelColor.disabledColor, this.labelColor.fadeDuration, false, true);
						break;
						
					case SelectionState.Normal:
						this.label.CrossFadeColor(this.labelColor.normalColor, this.labelColor.fadeDuration, false, true);
						break;
						
					case SelectionState.Highlighted:
						this.label.CrossFadeColor(this.labelColor.highlightedColor, this.labelColor.fadeDuration, false, true);
						break;
						
					case SelectionState.Pressed:
						this.label.CrossFadeColor(this.labelColor.pressedColor, this.labelColor.fadeDuration, false, true);
						break;

				}

			}

		}
		private void ApplyState(Selectable.SelectionState state, bool instant) {

			if (this.label != null) {
				
				switch (state) {
					
					case SelectionState.Disabled:
						this.label.CrossFadeColor(this.labelColor.disabledColor, instant == true ? 0f : this.labelColor.fadeDuration, false, true);
						break;
						
					case SelectionState.Normal:
						this.label.CrossFadeColor(this.labelColor.normalColor, instant == true ? 0f : this.labelColor.fadeDuration, false, true);
						break;
						
					case SelectionState.Highlighted:
						this.label.CrossFadeColor(this.labelColor.highlightedColor, instant == true ? 0f : this.labelColor.fadeDuration, false, true);
						break;
						
					case SelectionState.Pressed:
						this.label.CrossFadeColor(this.labelColor.pressedColor, instant == true ? 0f : this.labelColor.fadeDuration, false, true);
						break;
						
				}
				
			}

		}
 private static void SetDefaultColorTransitionValues(Selectable slider)
 {
   ColorBlock colors = slider.colors;
   colors.highlightedColor = new Color(0.882f, 0.882f, 0.882f);
   colors.pressedColor = new Color(0.698f, 0.698f, 0.698f);
   colors.disabledColor = new Color(0.521f, 0.521f, 0.521f);
 }
Exemple #6
0
        private void Apply(string themeClass, Selectable item) {
            if(item == null) return;

            SelectableSettings_Base settings;
            if(item as Button != null) {
                switch(themeClass) {
                    case "inputGridField":
                        settings = _inputGridFieldSettings;
                        break;
                    default:
                        settings = _buttonSettings;
                        break;
                }

            } else if(item as Scrollbar != null) settings = _scrollbarSettings;
            else if(item as Slider != null) settings = _sliderSettings;
            else if(item as Toggle != null) {
                switch(themeClass) {
                    case "button":
                        settings = _buttonSettings;
                        break;
                    default:
                        settings = _selectableSettings;
                        break;
                }

            } else settings = _selectableSettings;

            settings.Apply(item);
        }
		protected override void DoStateTransition(Selectable.SelectionState state, bool instant) {

			Color color;
			Sprite newSprite;
			string triggername;

			switch (state) {

				case Selectable.SelectionState.Normal:
					color = this.colors.normalColor;
					newSprite = null;
					triggername = this.animationTriggers.normalTrigger;
				break;
				case Selectable.SelectionState.Highlighted:
					color = this.colors.highlightedColor;
					newSprite = this.spriteState.highlightedSprite;
					triggername = this.animationTriggers.highlightedTrigger;
				break;
				case Selectable.SelectionState.Pressed:
					color = this.colors.pressedColor;
					newSprite = this.spriteState.pressedSprite;
					triggername = this.animationTriggers.pressedTrigger;
				break;
				case Selectable.SelectionState.Disabled:
					color = this.colors.disabledColor;
					newSprite = this.spriteState.disabledSprite;
					triggername = this.animationTriggers.disabledTrigger;
				break;
				default:
					color = Color.black;
					newSprite = null;
					triggername = string.Empty;
				break;

			}

			if (base.gameObject.activeInHierarchy) {

				switch (this.transitionExtended) {

					case Transition.SpriteSwapAndColorTint:
						this.StartColorTween(color * this.colors.colorMultiplier, instant);
						this.DoSpriteSwap(newSprite);
					break;
					case Transition.ColorTint:
						this.StartColorTween(color * this.colors.colorMultiplier, instant);
					break;
					case Transition.SpriteSwap:
						this.DoSpriteSwap(newSprite);
					break;
					case Transition.Animation:
						this.TriggerAnimation(triggername);
					break;

				}

			}

		}
Exemple #8
0
 private void AddSceneColor(UnityEngine.UI.Selectable selectable)
 {
     UnityEngine.UI.ColorBlock colorBlock = selectable.colors;
     AddSceneColor(colorBlock.normalColor);
     // Uncomment if you want to include additional colorBlock colors
     //AddSceneColor(colorBlock.highlightedColor);
     //AddSceneColor(colorBlock.pressedColor);
     //AddSceneColor(colorBlock.disabledColor);
 }
Exemple #9
0
    static int FindSelectableOnDown(IntPtr L)
    {
        LuaScriptMgr.CheckArgsCount(L, 1);
        Toggle obj = LuaScriptMgr.GetNetObject <Toggle>(L, 1);

        UI.Selectable o = obj.FindSelectableOnDown();
        LuaScriptMgr.Push(L, o);
        return(1);
    }
Exemple #10
0
    static int FindSelectable(IntPtr L)
    {
        LuaScriptMgr.CheckArgsCount(L, 2);
        Toggle  obj  = LuaScriptMgr.GetNetObject <Toggle>(L, 1);
        Vector3 arg0 = LuaScriptMgr.GetNetObject <Vector3>(L, 2);

        UI.Selectable o = obj.FindSelectable(arg0);
        LuaScriptMgr.Push(L, o);
        return(1);
    }
 private Selectable Next(Selectable current)
 {
     switch (Direction)
     {
         case DirectionEnum.UpDown:
             return current.FindSelectableOnDown();
         case DirectionEnum.LeftRight:
             return current.FindSelectableOnRight();
     }
     return current.FindSelectableOnDown();
 }
Exemple #12
0
		public virtual void Apply(Selectable element)
		{
			ColorBlock block = element.colors;

			block.disabledColor = disabledColor;
			block.highlightedColor = highlightedColor;
			block.normalColor = normalColor;
			block.pressedColor = pressedColor;

			element.colors = block;
		}
Exemple #13
0
        void Update()
        {
            if (Input.GetKeyDown(KeyCode.Tab))
            {
                UnityEngine.UI.Selectable next = EventSystem.current.currentSelectedGameObject.GetComponent <UnityEngine.UI.Selectable>().FindSelectableOnDown();

                if (next != null)
                {
                    InputField inputfield = next.GetComponent <InputField>();

                    if (inputfield != null)
                    {
                        inputfield.OnPointerClick(new PointerEventData(EventSystem.current));
                        EventSystem.current.SetSelectedGameObject(next.gameObject, new BaseEventData(EventSystem.current));
                    }
                }
            }
        }
		protected override void DoStateTransition(Selectable.SelectionState state, bool instant) {

			base.DoStateTransition(state, instant);

			if (this.label != null) {

				if (this.interactable == false) {

					this.label.color = this.labelColor.disabledColor;

				} else {

					this.label.color = this.labelColor.normalColor;

				}

			}

		}
Exemple #15
0
 /// <summary>
 /// Sets all of the current variables to a ColorBlock and returns it
 /// </summary>
 /// <param name="cb">The color block from the UI element</param>
 /// <returns>The color block with the new values</returns>
 public void SetColorBlock(UnityEngine.UI.Selectable selectable, ColorSet colorSet)
 {
     UnityEngine.UI.Image img = selectable.GetComponent <UnityEngine.UI.Image>();
     if (selectable.transition == UnityEngine.UI.Selectable.Transition.ColorTint)
     {
         if (img)
         {
             img.color = Color.white;
         }
         UnityEngine.UI.ColorBlock cb = selectable.colors;
         cb.normalColor      = colorSet.normal;
         cb.highlightedColor = colorSet.highlighted;
         cb.pressedColor     = colorSet.pressed;
         cb.disabledColor    = colorSet.disabled;
         selectable.colors   = cb;
     }
     else if (selectable.GetComponent <UnityEngine.UI.Image>())
     {
         img.color = colorSet.normal;
     }
 }
Exemple #16
0
    static int set_targetGraphic(IntPtr L)
    {
        object o = L.ToUserData(1);

        UnityEngine.UI.Selectable obj = (UnityEngine.UI.Selectable)o;

        if (obj == null)
        {
            LuaTypes types = L.Type(1);

            if (types == LuaTypes.LUA_TTABLE)
            {
                LuaDLL.luaL_error(L, "unknown member name targetGraphic");
            }
            else
            {
                LuaDLL.luaL_error(L, "attempt to index targetGraphic on a nil value");
            }
        }

        obj.targetGraphic = L.ToComponent(3, typeof(UnityEngine.UI.Graphic)) as UnityEngine.UI.Graphic;
        return(0);
    }
    static int set_navigation(IntPtr L)
    {
        object o = LuaScriptMgr.GetLuaObject(L, 1);

        UnityEngine.UI.Selectable obj = (UnityEngine.UI.Selectable)o;

        if (obj == null)
        {
            LuaTypes types = LuaDLL.lua_type(L, 1);

            if (types == LuaTypes.LUA_TTABLE)
            {
                LuaDLL.luaL_error(L, "unknown member name navigation");
            }
            else
            {
                LuaDLL.luaL_error(L, "attempt to index navigation on a nil value");
            }
        }

        obj.navigation = (UnityEngine.UI.Navigation)LuaScriptMgr.GetNetObject(L, 3, typeof(UnityEngine.UI.Navigation));
        return(0);
    }
Exemple #18
0
    static int set_animationTriggers(IntPtr L)
    {
        object o = L.ToUserData(1);

        UnityEngine.UI.Selectable obj = (UnityEngine.UI.Selectable)o;

        if (obj == null)
        {
            LuaTypes types = L.Type(1);

            if (types == LuaTypes.LUA_TTABLE)
            {
                LuaDLL.luaL_error(L, "unknown member name animationTriggers");
            }
            else
            {
                LuaDLL.luaL_error(L, "attempt to index animationTriggers on a nil value");
            }
        }

        obj.animationTriggers = (UnityEngine.UI.AnimationTriggers)L.ChkUserData(3, typeof(UnityEngine.UI.AnimationTriggers));
        return(0);
    }
Exemple #19
0
    static int set_interactable(IntPtr L)
    {
        object o = L.ToUserData(1);

        UnityEngine.UI.Selectable obj = (UnityEngine.UI.Selectable)o;

        if (obj == null)
        {
            LuaTypes types = L.Type(1);

            if (types == LuaTypes.LUA_TTABLE)
            {
                LuaDLL.luaL_error(L, "unknown member name interactable");
            }
            else
            {
                LuaDLL.luaL_error(L, "attempt to index interactable on a nil value");
            }
        }

        obj.interactable = L.ChkBoolean(3);
        return(0);
    }
Exemple #20
0
    static int set_transition(IntPtr L)
    {
        object o = L.ToUserData(1);

        UnityEngine.UI.Selectable obj = (UnityEngine.UI.Selectable)o;

        if (obj == null)
        {
            LuaTypes types = L.Type(1);

            if (types == LuaTypes.LUA_TTABLE)
            {
                LuaDLL.luaL_error(L, "unknown member name transition");
            }
            else
            {
                LuaDLL.luaL_error(L, "attempt to index transition on a nil value");
            }
        }

        obj.transition = (UnityEngine.UI.Selectable.Transition)L.ChkEnumValue(3, typeof(UnityEngine.UI.Selectable.Transition));
        return(0);
    }
    static int set_image(IntPtr L)
    {
        object o = LuaScriptMgr.GetLuaObject(L, 1);

        UnityEngine.UI.Selectable obj = (UnityEngine.UI.Selectable)o;

        if (obj == null)
        {
            LuaTypes types = LuaDLL.lua_type(L, 1);

            if (types == LuaTypes.LUA_TTABLE)
            {
                LuaDLL.luaL_error(L, "unknown member name image");
            }
            else
            {
                LuaDLL.luaL_error(L, "attempt to index image on a nil value");
            }
        }

        obj.image = (UnityEngine.UI.Image)LuaScriptMgr.GetUnityObject(L, 3, typeof(UnityEngine.UI.Image));
        return(0);
    }
    static int set_animationTriggers(IntPtr L)
    {
        object o = LuaScriptMgr.GetLuaObject(L, 1);

        UnityEngine.UI.Selectable obj = (UnityEngine.UI.Selectable)o;

        if (obj == null)
        {
            LuaTypes types = LuaDLL.lua_type(L, 1);

            if (types == LuaTypes.LUA_TTABLE)
            {
                LuaDLL.luaL_error(L, "unknown member name animationTriggers");
            }
            else
            {
                LuaDLL.luaL_error(L, "attempt to index animationTriggers on a nil value");
            }
        }

        obj.animationTriggers = (UnityEngine.UI.AnimationTriggers)LuaScriptMgr.GetNetObject(L, 3, typeof(UnityEngine.UI.AnimationTriggers));
        return(0);
    }
Exemple #23
0
    static int get_navigation(IntPtr L)
    {
        object o = L.ToUserData(1);

        UnityEngine.UI.Selectable obj = (UnityEngine.UI.Selectable)o;

        if (obj == null)
        {
            LuaTypes types = L.Type(1);

            if (types == LuaTypes.LUA_TTABLE)
            {
                LuaDLL.luaL_error(L, "unknown member name navigation");
            }
            else
            {
                LuaDLL.luaL_error(L, "attempt to index navigation on a nil value");
            }
        }

        L.PushLightUserData(obj.navigation);
        return(1);
    }
    static int get_transition(IntPtr L)
    {
        object o = LuaScriptMgr.GetLuaObject(L, 1);

        UnityEngine.UI.Selectable obj = (UnityEngine.UI.Selectable)o;

        if (obj == null)
        {
            LuaTypes types = LuaDLL.lua_type(L, 1);

            if (types == LuaTypes.LUA_TTABLE)
            {
                LuaDLL.luaL_error(L, "unknown member name transition");
            }
            else
            {
                LuaDLL.luaL_error(L, "attempt to index transition on a nil value");
            }
        }

        LuaScriptMgr.Push(L, obj.transition);
        return(1);
    }
Exemple #25
0
    static int set_image(IntPtr L)
    {
        object o = L.ToUserData(1);

        UnityEngine.UI.Selectable obj = (UnityEngine.UI.Selectable)o;

        if (obj == null)
        {
            LuaTypes types = L.Type(1);

            if (types == LuaTypes.LUA_TTABLE)
            {
                LuaDLL.luaL_error(L, "unknown member name image");
            }
            else
            {
                LuaDLL.luaL_error(L, "attempt to index image on a nil value");
            }
        }

        obj.image = L.ToComponent(3, typeof(UnityEngine.UI.Image)) as UnityEngine.UI.Image;
        return(0);
    }
Exemple #26
0
    static int set_spriteState(IntPtr L)
    {
        object o = L.ToUserData(1);

        UnityEngine.UI.Selectable obj = (UnityEngine.UI.Selectable)o;

        if (obj == null)
        {
            LuaTypes types = L.Type(1);

            if (types == LuaTypes.LUA_TTABLE)
            {
                LuaDLL.luaL_error(L, "unknown member name spriteState");
            }
            else
            {
                LuaDLL.luaL_error(L, "attempt to index spriteState on a nil value");
            }
        }

        obj.spriteState = (UnityEngine.UI.SpriteState)L.ChkUserData(3, typeof(UnityEngine.UI.SpriteState));
        return(0);
    }
        private static string BuildAnimationPath(Selectable target)
        {
            // if no target don't hook up any curves.
            var highlight = target.targetGraphic;
            if (highlight == null)
                return string.Empty;

            var startGo = highlight.gameObject;
            var toFindGo = target.gameObject;

            var pathComponents = new Stack<string>();
            while (toFindGo != startGo)
            {
                pathComponents.Push(startGo.name);

                // didn't exist in hierarchy!
                if (startGo.transform.parent == null)
                    return string.Empty;

                startGo = startGo.transform.parent.gameObject;
            }

            // calculate path
            var animPath = new StringBuilder();
            if (pathComponents.Count > 0)
                animPath.Append(pathComponents.Pop());

            while (pathComponents.Count > 0)
                animPath.Append("/").Append(pathComponents.Pop());

            return animPath.ToString();
        }
        private static void DrawNavigationForSelectable(Selectable sel)
        {
            if (sel == null)
                return;

            Transform transform = sel.transform;
            bool active = Selection.transforms.Any(e => e == transform);
            Handles.color = new Color(1.0f, 0.9f, 0.1f, active ? 1.0f : 0.4f);
            DrawNavigationArrow(-Vector2.right, sel, sel.FindSelectableOnLeft());
            DrawNavigationArrow(Vector2.right, sel, sel.FindSelectableOnRight());
            DrawNavigationArrow(Vector2.up, sel, sel.FindSelectableOnUp());
            DrawNavigationArrow(-Vector2.up, sel, sel.FindSelectableOnDown());
        }
		protected override void DoStateTransition(Selectable.SelectionState state, bool instant) {
			
			float scale;
			float alpha;
			Color color;
			Sprite newSprite;
			string triggername;

			switch (state) {

				case Selectable.SelectionState.Normal:
					scale = this.scale.normalScale;
					alpha = this.alpha.normalAlpha;
					color = this.colors.normalColor;
					newSprite = null;
					triggername = this.animationTriggers.normalTrigger;
				break;
				case Selectable.SelectionState.Highlighted:
					scale = this.scale.highlightedScale;
					alpha = this.alpha.highlightedAlpha;
					color = this.colors.highlightedColor;
					newSprite = this.spriteState.highlightedSprite;
					triggername = this.animationTriggers.highlightedTrigger;
				break;
				case Selectable.SelectionState.Pressed:
					scale = this.scale.pressedScale;
					alpha = this.alpha.pressedAlpha;
					color = this.colors.pressedColor;
					newSprite = this.spriteState.pressedSprite;
					triggername = this.animationTriggers.pressedTrigger;
				break;
				case Selectable.SelectionState.Disabled:
					scale = this.scale.disabledScale;
					alpha = this.alpha.disabledAlpha;
					color = this.colors.disabledColor;
					newSprite = this.spriteState.disabledSprite;
					triggername = this.animationTriggers.disabledTrigger;
				break;
				default:
					scale = 0f;
					alpha = 0f;
					color = Color.black;
					newSprite = null;
					triggername = string.Empty;
				break;

			}

			if (base.gameObject.activeInHierarchy == true) {
				
				if ((this.transitionExtended & Transition.Scale) != 0) {
					
					this.StartScaleTween(scale * this.scale.scaleMultiplier, instant);
					
				}
				
				if ((this.transitionExtended & Transition.CanvasGroupAlpha) != 0) {
					
					this.StartAlphaTween(alpha * this.alpha.alphaMultiplier, instant);
					
				}
				
				if ((this.transitionExtended & Transition.ColorTint) != 0) {
					
					this.StartColorTween(color * this.colors.colorMultiplier, instant);
					
				}
				
				if ((this.transitionExtended & Transition.SpriteSwap) != 0) {
					
					this.DoSpriteSwap(newSprite);
					
				}
				
				if ((this.transitionExtended & Transition.Animation) != 0) {
					
					this.TriggerAnimation(triggername);
					
				}

			}

		}
 private static string GetSaveControllerPath(Selectable target)
 {
     var defaultName = target.gameObject.name;
     var message = string.Format("Create a new animator for the game object '{0}':", defaultName);
     return EditorUtility.SaveFilePanelInProject("New Animation Contoller", defaultName, "controller", message);
 }
Exemple #31
0
 void UISetdisplay(Selectable obj, float posX, float posY, float sizeX, float sizeY)
 {
     RectTransform rectTransform = obj.transform as RectTransform;
     rectTransform.sizeDelta = new Vector2(sizeX, sizeY);
     rectTransform.position = new Vector3(posX, posY, 0f);
 }
 static public int get_colors(IntPtr l)
 {
     UnityEngine.UI.Selectable o = (UnityEngine.UI.Selectable)checkSelf(l);
     pushValue(l, o.colors);
     return(1);
 }
 public void SetSelectedElement(Selectable selectable)
 {
     Selected = selectable;
     EventSystem.SetSelectedGameObject(Selected.gameObject);
 }
 protected virtual void DoStateTransition(Selectable.SelectionState state, bool instant)
 {
   Color color;
   Sprite newSprite;
   string triggername;
   switch (state)
   {
     case Selectable.SelectionState.Normal:
       color = this.m_Colors.normalColor;
       newSprite = (Sprite) null;
       triggername = this.m_AnimationTriggers.normalTrigger;
       break;
     case Selectable.SelectionState.Highlighted:
       color = this.m_Colors.highlightedColor;
       newSprite = this.m_SpriteState.highlightedSprite;
       triggername = this.m_AnimationTriggers.highlightedTrigger;
       break;
     case Selectable.SelectionState.Pressed:
       color = this.m_Colors.pressedColor;
       newSprite = this.m_SpriteState.pressedSprite;
       triggername = this.m_AnimationTriggers.pressedTrigger;
       break;
     case Selectable.SelectionState.Disabled:
       color = this.m_Colors.disabledColor;
       newSprite = this.m_SpriteState.disabledSprite;
       triggername = this.m_AnimationTriggers.disabledTrigger;
       break;
     default:
       color = Color.black;
       newSprite = (Sprite) null;
       triggername = string.Empty;
       break;
   }
   if (!this.gameObject.activeInHierarchy)
     return;
   switch (this.m_Transition)
   {
     case Selectable.Transition.ColorTint:
       this.StartColorTween(color * this.m_Colors.colorMultiplier, instant);
       break;
     case Selectable.Transition.SpriteSwap:
       this.DoSpriteSwap(newSprite);
       break;
     case Selectable.Transition.Animation:
       this.TriggerAnimation(triggername);
       break;
   }
 }
 static public int get_animator(IntPtr l)
 {
     UnityEngine.UI.Selectable o = (UnityEngine.UI.Selectable)checkSelf(l);
     pushValue(l, o.animator);
     return(1);
 }
 static public int get_interactable(IntPtr l)
 {
     UnityEngine.UI.Selectable o = (UnityEngine.UI.Selectable)checkSelf(l);
     pushValue(l, o.interactable);
     return(1);
 }
 static public int get_targetGraphic(IntPtr l)
 {
     UnityEngine.UI.Selectable o = (UnityEngine.UI.Selectable)checkSelf(l);
     pushValue(l, o.targetGraphic);
     return(1);
 }
 static public int get_spriteState(IntPtr l)
 {
     UnityEngine.UI.Selectable o = (UnityEngine.UI.Selectable)checkSelf(l);
     pushValue(l, o.spriteState);
     return(1);
 }
Exemple #39
0
 // Use this for initialization
 void Start()
 {
     selectable = GetComponent <UnityEngine.UI.Selectable> ();
 }
 static public int get_transition(IntPtr l)
 {
     UnityEngine.UI.Selectable o = (UnityEngine.UI.Selectable)checkSelf(l);
     pushValue(l, o.transition);
     return(1);
 }
        // Find the next selectable object in the specified world-space direction.
        public static Selectable FindNextSelectable(Selectable selectable, Transform transform, List<Selectable> allSelectables, Vector3 direction) {
            RectTransform rectTransform = transform as RectTransform;
            if(rectTransform == null) return null;
            
            direction = direction.normalized;
            Vector2 localDir = Quaternion.Inverse(transform.rotation) * direction;
            Vector2 searchStartPos = transform.TransformPoint(Rewired.UI.ControlMapper.UITools.GetPointOnRectEdge(rectTransform, localDir)); // search from point on rect edge from center out in direction
            //Vector2 searchStartPos = transform.TransformPoint((transform as RectTransform).rect.center); // search from center
            bool isHoriz = direction == Vector3.left || direction == Vector3.right;

            float minCenterDistSqMag = Mathf.Infinity;
            float minDirectLineSqMag = Mathf.Infinity;
            Selectable bestCenterDistPick = null;
            Selectable bestDirectLinePick = null;

            const float length = 999999f; // Mathf.Infinity fails
            Vector2 directLineCastEndPos = searchStartPos + localDir * length;

            for(int i = 0; i < allSelectables.Count; ++i) {
                Selectable sel = allSelectables[i];

                if(sel == selectable || sel == null) continue; // skip if self or null
                if(sel.navigation.mode == Navigation.Mode.None) continue; // skip if non-navigable

                // Allow selection of non-interactable elements because it makes navigating easier and more predictable
                // but the CanvasGroup interactable value is private in Selectable
#if !UNITY_WSA
                // Reflect to get group intaractability if non-interactable
                bool canvasGroupAllowsInteraction = sel.IsInteractable() || Rewired.Utils.ReflectionTools.GetPrivateField<Selectable, bool>(sel, "m_GroupsAllowInteraction");
                if(!canvasGroupAllowsInteraction) continue; // skip if disabled by canvas group, otherwise allow it
#else
                // Can't do private field reflection in Metro
                if(!sel.IsInteractable()) continue; // skip if disabled
#endif

                var selRect = sel.transform as RectTransform;
                if(selRect == null) continue;

                // Check direct line cast from center edge of object in direction pressed
                float directLineSqMag;
                Rect worldSpaceRect = Rewired.UI.ControlMapper.UITools.GetWorldSpaceRect(selRect);

                // Check for direct line rect intersection
                if(Rewired.Utils.MathTools.LineIntersectsRect(searchStartPos, directLineCastEndPos, worldSpaceRect, out directLineSqMag)) {
                    if(isHoriz) directLineSqMag *= 0.25f; // give extra bonus to horizontal directions because most of the UI groups are laid out horizontally                     
                    if(directLineSqMag < minDirectLineSqMag) {
                        minDirectLineSqMag = directLineSqMag;
                        bestDirectLinePick = sel;
                    }
                }

                // Check distance to center
                Vector2 selCenter = (Vector3)selRect.rect.center;
                Vector2 searchPosToSelCenter = (Vector2)sel.transform.TransformPoint(selCenter) - searchStartPos;

                const float maxSafeAngle = 75.0f;

                // Get the angle the target center deviates from straight
                float angle = Mathf.Abs(Vector2.Angle(localDir, searchPosToSelCenter));
                if(angle > maxSafeAngle) continue; // only consider if within a reasonable angle of the desired direction

                float score = searchPosToSelCenter.sqrMagnitude;

                // Lower score is better
                if(score < minCenterDistSqMag) {
                    minCenterDistSqMag = score;
                    bestCenterDistPick = sel;
                }
            }

            // Choose between direct line and center dist
            if(bestCenterDistPick != null && bestCenterDistPick != null) {
                if(minDirectLineSqMag > minCenterDistSqMag) {
                    return bestCenterDistPick;
                }
                return bestDirectLinePick;
            }

            return bestDirectLinePick ?? bestCenterDistPick;
        }
Exemple #42
0
    static int QPYX_set_interactable_YXQP(IntPtr L_YXQP)
    {
        object QPYX_o_YXQP = null;

        try
        {
            QPYX_o_YXQP = ToLua.ToObject(L_YXQP, 1);                        UnityEngine.UI.Selectable QPYX_obj_YXQP = (UnityEngine.UI.Selectable)QPYX_o_YXQP;
            bool QPYX_arg0_YXQP = LuaDLL.luaL_checkboolean(L_YXQP, 2);
            QPYX_obj_YXQP.interactable = QPYX_arg0_YXQP;
            return(0);
        }
        catch (Exception QPYX_e_YXQP)            {
            return(LuaDLL.toluaL_exception(L_YXQP, QPYX_e_YXQP, QPYX_o_YXQP, "attempt to index interactable on a nil value"));
        }
    }
Exemple #43
0
 /// <summary>
 /// Stops the compiler and shows a dialog box containing the error message on the target <see cref="UnityEngine.UI.Selectable"/>.
 /// </summary>
 /// <exception cref="PMRuntimeException">Is always thrown</exception>
 public static void RaiseError(UnityEngine.UI.Selectable targetSelectable, string message)
 {
     UISingleton.instance.textField.theLineMarker.setErrorMarker(targetSelectable, message);
 }
Exemple #44
0
		private void findLastSelected()
		{
			var obj = UnityEngine.EventSystems.EventSystem.current.currentSelectedGameObject;
			if (!obj)
			{
				LastSelected = null;
				return;
			}
			var sel = obj.GetComponent<Selectable>();
			LastSelected = sel;
		}
Exemple #45
0
        /// <summary>
        /// Does the state transitioning.
        /// </summary>
        /// <param name="state">State.</param>
        /// <param name="instant">If set to <c>true</c> instant.</param>
        protected override void DoStateTransition(Selectable.SelectionState state, bool instant)
        {
            if (!this.m_HasEnableRun)
                return;

            // Save the state as current state
            this.m_CurrentState = state;

            Color newImageColor = this.m_ImageColors.normalColor;
            Color newTextColor = this.m_TextColors.normalColor;
            Sprite newSprite = null;
            string imageTrigger = this.m_ImageAnimationTriggers.normalTrigger;

            // Prepare state values
            switch (state)
            {
            case Selectable.SelectionState.Normal:
                newImageColor = (!this.isOn) ? this.m_ImageColors.normalColor : this.m_ImageColors.activeColor;
                newTextColor = (!this.isOn) ? this.m_TextColors.normalColor : this.m_TextColors.activeColor;
                newSprite = (!this.isOn) ? null : this.m_ImageSpriteState.activeSprite;
                imageTrigger = (!this.isOn) ? this.m_ImageAnimationTriggers.normalTrigger : this.m_ImageAnimationTriggers.activeTrigger;
                break;
            case Selectable.SelectionState.Highlighted:
                newImageColor = (!this.isOn) ? this.m_ImageColors.highlightedColor : this.m_ImageColors.activeHighlightedColor;
                newTextColor = (!this.isOn) ? this.m_TextColors.highlightedColor : this.m_TextColors.activeHighlightedColor;
                newSprite = (!this.isOn) ? this.m_ImageSpriteState.highlightedSprite : this.m_ImageSpriteState.activeHighlightedSprite;
                imageTrigger = (!this.isOn) ? this.m_ImageAnimationTriggers.highlightedTrigger : this.m_ImageAnimationTriggers.activeHighlightedTrigger;
                break;
            case Selectable.SelectionState.Pressed:
                newImageColor = (!this.isOn) ? this.m_ImageColors.pressedColor : this.m_ImageColors.activePressedColor;
                newTextColor = (!this.isOn) ? this.m_TextColors.pressedColor : this.m_TextColors.activePressedColor;
                newSprite = (!this.isOn) ? this.m_ImageSpriteState.pressedSprite : this.m_ImageSpriteState.activePressedSprite;
                imageTrigger = (!this.isOn) ? this.m_ImageAnimationTriggers.pressedTrigger : this.m_ImageAnimationTriggers.activePressedTrigger;
                break;
            case Selectable.SelectionState.Disabled:
                newImageColor = this.m_ImageColors.disabledColor;
                newTextColor = this.m_TextColors.disabledColor;
                newSprite = this.m_ImageSpriteState.disabledSprite;
                imageTrigger = this.m_ImageAnimationTriggers.disabledTrigger;
                break;
            }

            // Check if the tab is active in the scene
            if (this.gameObject.activeInHierarchy)
            {
                // Do the image transition
                switch (this.m_ImageTransition)
                {
                case Selectable.Transition.ColorTint:
                    this.StartColorTween((this.m_ImageTarget as Graphic), newImageColor * this.m_ImageColors.colorMultiplier, (instant ? 0f : this.m_ImageColors.fadeDuration));
                    break;
                case Selectable.Transition.SpriteSwap:
                    this.DoSpriteSwap(this.m_ImageTarget, newSprite);
                    break;
                case Selectable.Transition.Animation:
                    this.TriggerAnimation(this.m_ImageTarget.gameObject, imageTrigger);
                    break;
                }

                // Do the text transition
                switch (this.m_TextTransition)
                {
                case TextTransition.ColorTint:
                    this.StartColorTween((this.m_TextTarget as Graphic), newTextColor * this.m_TextColors.colorMultiplier, (instant ? 0f : this.m_TextColors.fadeDuration));
                    break;
                }
            }
        }
        /// <summary>
        /// My black vodoo script, do not use outside
        /// </summary>
        /// <param name="ScreenMgr"></param>
        /// <param name="children"></param>
        private void UpdateNavigation(ScreenManager ScreenMgr, Transform[] children)
        {
            for (int i = 0; i < children.Length; i++) children[i].gameObject.SetActive(false);

            List<Selectable> selectables = new List<Selectable>();

            for (int i = 0; i < children.Length; i++) {
                Transform parent = children[i];
                BaseScreen screen = parent.GetComponent<BaseScreen>();

                if (!screen.generateNavigation) continue;

                parent.gameObject.SetActive(true);

                selectables.Clear();
                parent.GetComponentsInChildren<Selectable>(selectables);

                Selectable[] directions = new Selectable[4];
                foreach (Selectable selectableUI in selectables) {
                    //Debug.Log("<b>" + parent.name + "</b>." + selectableUI.name, selectableUI);

                    Transform t = selectableUI.transform;

                    directions[0] = FindSelectable(parent, t, selectables, t.rotation * Vector3.up);
                    directions[1] = FindSelectable(parent, t, selectables, t.rotation * Vector3.right);
                    directions[2] = FindSelectable(parent, t, selectables, t.rotation * Vector3.down);
                    directions[3] = FindSelectable(parent, t, selectables, t.rotation * Vector3.left);

                    if (selectableUI is Slider) {
                        Slider.Direction dir = (selectableUI as Slider).direction;
                        if (dir == Slider.Direction.TopToBottom || dir == Slider.Direction.BottomToTop) {
                            directions[0] = directions[2] = null;
                        } else {
                            directions[1] = directions[3] = null;
                        }
                    }

                    selectableUI.navigation = new Navigation() {
                        mode = Navigation.Mode.Explicit,
                        selectOnUp = directions[0],
                        selectOnRight = directions[1],
                        selectOnDown = directions[2],
                        selectOnLeft = directions[3],
                    };

                    CancelTrigger sctrigger = selectableUI.gameObject.GetComponent<CancelTrigger>();

                    if (sctrigger == null) {
                        var cancelHandlerAvailable = selectableUI.GetComponent<ICancelHandler>();
                        if (cancelHandlerAvailable == null) {
                            sctrigger = selectableUI.gameObject.AddComponent<CancelTrigger>();
                            sctrigger.disableCancelHandler = cancelHandlerAvailable != null;
                        }
                    }

                }
                parent.gameObject.SetActive(false);
            }
            if (ScreenMgr.defaultScreen != null) ScreenMgr.defaultScreen.gameObject.SetActive(true);
        }
Exemple #47
0
 public static IDisposable SubscribeToInteractable(this IObservable <bool> source, UnityEngine.UI.Selectable selectable)
 {
     return(source.Subscribe(x => selectable.interactable = x));
 }
        private static AnimatorController GenerateSelectableAnimatorContoller(AnimationTriggers animationTriggers, Selectable target)
        {
            if (target == null)
                return null;

            // Where should we create the controller?
            var path = GetSaveControllerPath(target);
            if (string.IsNullOrEmpty(path))
                return null;

            // figure out clip names
            var normalName = string.IsNullOrEmpty(animationTriggers.normalTrigger) ? "Normal" : animationTriggers.normalTrigger;
            var highlightedName = string.IsNullOrEmpty(animationTriggers.highlightedTrigger) ? "Highlighted" : animationTriggers.highlightedTrigger;
            var pressedName = string.IsNullOrEmpty(animationTriggers.pressedTrigger) ? "Pressed" : animationTriggers.pressedTrigger;
            var disabledName = string.IsNullOrEmpty(animationTriggers.disabledTrigger) ? "Disabled" : animationTriggers.disabledTrigger;

            // Create controller and hook up transitions.
            var controller = AnimatorController.CreateAnimatorControllerAtPath(path);

            GenerateTriggerableTransition(normalName, controller);
            GenerateTriggerableTransition(highlightedName, controller);
            GenerateTriggerableTransition(pressedName, controller);
            GenerateTriggerableTransition(disabledName, controller);

            return controller;
        }
Exemple #49
0
 public void ChangeFirstButton(Selectable button)
 {
     _eventSystem.firstSelectedGameObject = button.gameObject;
 }
Exemple #50
0
            public override void Apply(Selectable item) {
                if(item == null) return;
                base.Apply(item);

                if(_imageSettings != null) _imageSettings.CopyTo(item.targetGraphic as Image);
            }
Exemple #51
0
		/**
		 * Get the next selectable to the right, or if null, the next selectable down and left-most.
		 */
		public static Selectable GetNextSelectable(Selectable current)
		{
			if(current == null)
				return null;

			Selectable next = current.FindSelectableOnRight();

			if(next != null)
			{
				return next;
			}
			else
			{
				next = current.FindSelectableOnDown();

				if(next == null)
					return null;

				Selectable left = next;

				while(next != null)
				{
					left = left.FindSelectableOnLeft();

					if(left == null)
						return next;

					next = left;
				}
			}

			return null;
		}
Exemple #52
0
 public override void Apply(Selectable item) {
     base.Apply(item);
     Apply(item as Scrollbar);
 }
Exemple #53
0
            public virtual void Apply(Selectable item) {
                Selectable.Transition transition = _transition;
                bool transitionChanged = item.transition != transition;
                item.transition = transition;

                ICustomSelectable customSel = item as ICustomSelectable;

                if(transition == Selectable.Transition.ColorTint) {
                    // Two-step color change to get around delay bug due to fade duration
                    CustomColorBlock cb = _colors;
                    cb.fadeDuration = 0.0f;
                    item.colors = cb;
                    cb.fadeDuration = _colors.fadeDuration;
                    item.colors = cb;
                    if(customSel != null) customSel.disabledHighlightedColor = cb.disabledHighlightedColor;

                } else if(transition == Selectable.Transition.SpriteSwap) {
                    item.spriteState = _spriteState;
                    if(customSel != null) customSel.disabledHighlightedSprite = _spriteState.disabledHighlightedSprite;
                } else if(transition == Selectable.Transition.Animation) {
                    item.animationTriggers.disabledTrigger = _animationTriggers.disabledTrigger;
                    item.animationTriggers.highlightedTrigger = _animationTriggers.highlightedTrigger;
                    item.animationTriggers.normalTrigger = _animationTriggers.normalTrigger;
                    item.animationTriggers.pressedTrigger = _animationTriggers.pressedTrigger;
                    if(customSel != null) customSel.disabledHighlightedTrigger = _animationTriggers.disabledHighlightedTrigger;
                }

                if(transitionChanged) item.targetGraphic.CrossFadeColor(item.targetGraphic.color, 0.0f, true, true); // force color to revert to default or it will be left with color tint
            }
        private static void DrawNavigationArrow(Vector2 direction, Selectable fromObj, Selectable toObj)
        {
            if (fromObj == null || toObj == null)
                return;
            Transform fromTransform = fromObj.transform;
            Transform toTransform = toObj.transform;

            Vector2 sideDir = new Vector2(direction.y, -direction.x);
            Vector3 fromPoint = fromTransform.TransformPoint(GetPointOnRectEdge(fromTransform as RectTransform, direction));
            Vector3 toPoint = toTransform.TransformPoint(GetPointOnRectEdge(toTransform as RectTransform, -direction));
            float fromSize = HandleUtility.GetHandleSize(fromPoint) * 0.05f;
            float toSize = HandleUtility.GetHandleSize(toPoint) * 0.05f;
            fromPoint += fromTransform.TransformDirection(sideDir) * fromSize;
            toPoint += toTransform.TransformDirection(sideDir) * toSize;
            float length = Vector3.Distance(fromPoint, toPoint);
            Vector3 fromTangent = fromTransform.rotation * direction * length * 0.3f;
            Vector3 toTangent = toTransform.rotation * -direction * length * 0.3f;

            Handles.DrawBezier(fromPoint, toPoint, fromPoint + fromTangent, toPoint + toTangent, Handles.color, null, kArrowThickness);
            Handles.DrawAAPolyLine(kArrowThickness, toPoint, toPoint + toTransform.rotation * (-direction - sideDir) * toSize * kArrowHeadSize);
            Handles.DrawAAPolyLine(kArrowThickness, toPoint, toPoint + toTransform.rotation * (-direction + sideDir) * toSize * kArrowHeadSize);
        }
Exemple #55
0
 public override void Apply(Selectable item) {
     Apply(item as Slider);
 }
Exemple #56
0
    static int QPYX_set_image_YXQP(IntPtr L_YXQP)
    {
        object QPYX_o_YXQP = null;

        try
        {
            QPYX_o_YXQP = ToLua.ToObject(L_YXQP, 1);                        UnityEngine.UI.Selectable QPYX_obj_YXQP = (UnityEngine.UI.Selectable)QPYX_o_YXQP;
            UnityEngine.UI.Image QPYX_arg0_YXQP = (UnityEngine.UI.Image)ToLua.CheckObject <UnityEngine.UI.Image>(L_YXQP, 2);
            QPYX_obj_YXQP.image = QPYX_arg0_YXQP;
            return(0);
        }
        catch (Exception QPYX_e_YXQP)            {
            return(LuaDLL.toluaL_exception(L_YXQP, QPYX_e_YXQP, QPYX_o_YXQP, "attempt to index image on a nil value"));
        }
    }
Exemple #57
0
        // Selection logic

        /// <summary>
        /// Finds the selectable object next to this one.
        /// </summary>
        /// <remarks>
        /// The direction is determined by a Vector3 variable.
        /// </remarks>
        /// <param name="dir">The direction in which to search for a neighbouring Selectable object.</param>
        /// <returns>The neighbouring Selectable object. Null if none found.</returns>
        /// <example>
        /// <code>
        /// using UnityEngine;
        /// using System.Collections;
        /// using UnityEngine.UI; // required when using UI elements in scripts
        ///
        /// public class ExampleClass : MonoBehaviour
        /// {
        ///     //Sets the direction as "Up" (Y is in positive).
        ///     public Vector3 direction = new Vector3(0, 1, 0);
        ///     public Button btnMain;
        ///
        ///     public void Start()
        ///     {
        ///         //Finds and assigns the selectable above the main button
        ///         Selectable newSelectable = btnMain.FindSelectable(direction);
        ///
        ///         Debug.Log(newSelectable.name);
        ///     }
        /// }
        /// </code>
        /// </example>
        public Selectable FindSelectable(Vector3 dir)
        {
            dir = dir.normalized;
            Vector3    localDir = Quaternion.Inverse(transform.rotation) * dir;
            Vector3    pos      = transform.TransformPoint(GetPointOnRectEdge(transform as RectTransform, localDir));
            float      maxScore = Mathf.NegativeInfinity;
            Selectable bestPick = null;

            if (s_IsDirty)
            {
                RemoveInvalidSelectables();
            }

            for (int i = 0; i < s_SelectableCount; ++i)
            {
                Selectable sel = s_Selectables[i];

                if (sel == this)
                {
                    continue;
                }

                if (!sel.IsInteractable() || sel.navigation.mode == Navigation.Mode.None)
                {
                    continue;
                }

#if UNITY_EDITOR
                // Apart from runtime use, FindSelectable is used by custom editors to
                // draw arrows between different selectables. For scene view cameras,
                // only selectables in the same stage should be considered.
                if (Camera.current != null && !UnityEditor.SceneManagement.StageUtility.IsGameObjectRenderedByCamera(sel.gameObject, Camera.current))
                {
                    continue;
                }
#endif

                var     selRect   = sel.transform as RectTransform;
                Vector3 selCenter = selRect != null ? (Vector3)selRect.rect.center : Vector3.zero;
                Vector3 myVector  = sel.transform.TransformPoint(selCenter) - pos;

                // Value that is the distance out along the direction.
                float dot = Vector3.Dot(dir, myVector);

                // Skip elements that are in the wrong direction or which have zero distance.
                // This also ensures that the scoring formula below will not have a division by zero error.
                if (dot <= 0)
                {
                    continue;
                }

                // This scoring function has two priorities:
                // - Score higher for positions that are closer.
                // - Score higher for positions that are located in the right direction.
                // This scoring function combines both of these criteria.
                // It can be seen as this:
                //   Dot (dir, myVector.normalized) / myVector.magnitude
                // The first part equals 1 if the direction of myVector is the same as dir, and 0 if it's orthogonal.
                // The second part scores lower the greater the distance is by dividing by the distance.
                // The formula below is equivalent but more optimized.
                //
                // If a given score is chosen, the positions that evaluate to that score will form a circle
                // that touches pos and whose center is located along dir. A way to visualize the resulting functionality is this:
                // From the position pos, blow up a circular balloon so it grows in the direction of dir.
                // The first Selectable whose center the circular balloon touches is the one that's chosen.
                float score = dot / myVector.sqrMagnitude;

                if (score > maxScore)
                {
                    maxScore = score;
                    bestPick = sel;
                }
            }
            return(bestPick);
        }
 // Start is called before the first frame update
 void Awake()
 {
     eventSystem = GameObject.FindObjectOfType <UnityEngine.EventSystems.EventSystem>();
     selectable  = GetComponent <UnityEngine.UI.Selectable>();
 }
 private void Navigate(AxisEventData eventData, Selectable sel)
 {
   if (!((UnityEngine.Object) sel != (UnityEngine.Object) null) || !sel.IsActive())
     return;
   eventData.selectedObject = sel.gameObject;
 }
Exemple #60
0
 private void Awake()
 {
     selectable = GetComponent<Selectable>();
 }