public Selectable FindSelectable(Vector3 dir) { dir = dir.normalized; Vector3 v = Quaternion.Inverse(base.transform.rotation) * dir; Vector3 b = base.transform.TransformPoint(Selectable.GetPointOnRectEdge(base.transform as RectTransform, v)); float num = float.NegativeInfinity; Selectable result = null; for (int i = 0; i < Selectable.s_List.Count; i++) { Selectable selectable = Selectable.s_List[i]; if (!(selectable == this) && !(selectable == null)) { if (selectable.IsInteractable() && selectable.navigation.mode != Navigation.Mode.None) { RectTransform rectTransform = selectable.transform as RectTransform; Vector3 position = (!(rectTransform != null)) ? Vector3.zero : rectTransform.rect.center; Vector3 rhs = selectable.transform.TransformPoint(position) - b; float num2 = Vector3.Dot(dir, rhs); if (num2 > 0f) { float num3 = num2 / rhs.sqrMagnitude; if (num3 > num) { num = num3; result = selectable; } } } } } return(result); }
// Selection logic // Find the next selectable object in the specified world-space direction. 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; for (int i = 0; i < s_List.Count; ++i) { Selectable sel = s_List[i]; if (sel == this || sel == null) { continue; } if (!sel.IsInteractable() || sel.navigation.mode == Navigation.Mode.None) { continue; } 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); }
public Selectable FindSelectable(Vector3 dir) { dir = dir.normalized; Vector3 vector = (Vector3)(Quaternion.Inverse(base.transform.rotation) * dir); Vector3 vector2 = base.transform.TransformPoint(GetPointOnRectEdge(base.transform as RectTransform, vector)); float negativeInfinity = float.NegativeInfinity; Selectable selectable = null; for (int i = 0; i < s_List.Count; i++) { Selectable selectable2 = s_List[i]; if (((selectable2 != this) && (selectable2 != null)) && (selectable2.IsInteractable() && (selectable2.navigation.mode != Navigation.Mode.None))) { RectTransform transform = selectable2.transform as RectTransform; Vector3 position = (transform == null) ? Vector3.zero : ((Vector3)transform.rect.center); Vector3 rhs = selectable2.transform.TransformPoint(position) - vector2; float num3 = Vector3.Dot(dir, rhs); if (num3 > 0f) { float num4 = num3 / rhs.sqrMagnitude; if (num4 > negativeInfinity) { negativeInfinity = num4; selectable = selectable2; } } } } return(selectable); }
static public int IsInteractable(IntPtr l) { try { #if DEBUG var method = System.Reflection.MethodBase.GetCurrentMethod(); string methodName = GetMethodName(method); #if UNITY_5_5_OR_NEWER UnityEngine.Profiling.Profiler.BeginSample(methodName); #else Profiler.BeginSample(methodName); #endif #endif UnityEngine.UI.Selectable self = (UnityEngine.UI.Selectable)checkSelf(l); var ret = self.IsInteractable(); pushValue(l, true); pushValue(l, ret); return(2); } catch (Exception e) { return(error(l, e)); } #if DEBUG finally { #if UNITY_5_5_OR_NEWER UnityEngine.Profiling.Profiler.EndSample(); #else Profiler.EndSample(); #endif } #endif }
static int IsInteractable(IntPtr L) { L.ChkArgsCount(1); UnityEngine.UI.Selectable obj = (UnityEngine.UI.Selectable)L.ChkUnityObjectSelf(1, "UnityEngine.UI.Selectable"); bool o = obj.IsInteractable(); L.PushBoolean(o); return(1); }
static int IsInteractable(IntPtr L) { LuaScriptMgr.CheckArgsCount(L, 1); UnityEngine.UI.Selectable obj = (UnityEngine.UI.Selectable)LuaScriptMgr.GetUnityObjectSelf(L, 1, "UnityEngine.UI.Selectable"); bool o = obj.IsInteractable(); LuaScriptMgr.Push(L, o); return(1); }
static public int IsInteractable(IntPtr l) { try { UnityEngine.UI.Selectable self = (UnityEngine.UI.Selectable)checkSelf(l); var ret = self.IsInteractable(); pushValue(l, ret); return(1); } catch (Exception e) { return(error(l, e)); } }
static public int IsInteractable(IntPtr l) { try { UnityEngine.UI.Selectable self=(UnityEngine.UI.Selectable)checkSelf(l); var ret=self.IsInteractable(); pushValue(l,ret); return 1; } catch(Exception e) { LuaDLL.luaL_error(l, e.ToString()); return 0; } }
static int QPYX_IsInteractable_YXQP(IntPtr L_YXQP) { try { ToLua.CheckArgsCount(L_YXQP, 1); UnityEngine.UI.Selectable QPYX_obj_YXQP = (UnityEngine.UI.Selectable)ToLua.CheckObject <UnityEngine.UI.Selectable>(L_YXQP, 1); bool QPYX_o_YXQP = QPYX_obj_YXQP.IsInteractable(); LuaDLL.lua_pushboolean(L_YXQP, QPYX_o_YXQP); return(1); } catch (Exception e_YXQP) { return(LuaDLL.toluaL_exception(L_YXQP, e_YXQP)); } }
static int IsInteractable(IntPtr L) { try { ToLua.CheckArgsCount(L, 1); UnityEngine.UI.Selectable obj = (UnityEngine.UI.Selectable)ToLua.CheckObject(L, 1, typeof(UnityEngine.UI.Selectable)); bool o = obj.IsInteractable(); LuaDLL.lua_pushboolean(L, o); return(1); } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e)); } }
/// <summary> /// <para>Finds the selectable object next to this one.</para> /// </summary> /// <param name="dir">The direction in which to search for a neighbouring Selectable object.</param> /// <returns> /// <para>The neighbouring Selectable object. Null if none found.</para> /// </returns> public Selectable FindSelectable(Vector3 dir) { dir = dir.normalized; Vector3 vector3 = this.transform.TransformPoint(Selectable.GetPointOnRectEdge(this.transform as RectTransform, (Vector2)(Quaternion.Inverse(this.transform.rotation) * dir))); float num1 = float.NegativeInfinity; Selectable selectable1 = (Selectable)null; for (int index = 0; index < Selectable.s_List.Count; ++index) { Selectable selectable2 = Selectable.s_List[index]; if (!((UnityEngine.Object)selectable2 == (UnityEngine.Object) this) && !((UnityEngine.Object)selectable2 == (UnityEngine.Object)null) && selectable2.IsInteractable() && selectable2.navigation.mode != Navigation.Mode.None) { RectTransform transform = selectable2.transform as RectTransform; Vector3 position = !((UnityEngine.Object)transform != (UnityEngine.Object)null) ? Vector3.zero : (Vector3)transform.rect.center; Vector3 rhs = selectable2.transform.TransformPoint(position) - vector3; float num2 = Vector3.Dot(dir, rhs); if ((double)num2 > 0.0) { float num3 = num2 / rhs.sqrMagnitude; if ((double)num3 > (double)num1) { num1 = num3; selectable1 = selectable2; } } } } return(selectable1); }
// 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); }
public static Selectable FindSelectablePerpendicular(this Selectable selectable, Vector3 direction, params FilterDelegate[] filters) { direction = direction.normalized; Vector3 localDir = selectable.transform.rotation * direction; Vector3 pos = selectable.transform.TransformPoint(GetPointOnRectEdge(selectable.transform as RectTransform, localDir)); float maxScore = Mathf.Infinity; float maxDistance = Mathf.Infinity; Selectable bestPick = null; Ray ray = new Ray(pos, Quaternion.AngleAxis(90, selectable.transform.forward) * localDir); //Rotate the localDir 90° around the selectable's forward axis, to get a direction along selectable.rect side for (int i = 0; i < Selectable.allSelectables.Count; i++) { Selectable sel = Selectable.allSelectables[i]; if (sel == selectable || sel == null) { continue; } if (!sel.IsInteractable() || sel.navigation.mode == Navigation.Mode.None) { continue; } bool resultfilter = true; for (int j = 0; j < filters.Length; j++) { resultfilter = filters[j](selectable, sel); if (resultfilter == false) { break; } } if (!resultfilter) { continue; } var selRect = sel.transform as RectTransform; Vector3 selCenter = selRect != null?sel.transform.TransformPoint((Vector3)selRect.rect.center) : Vector3.zero; Vector3 myVector = selCenter - pos; // Value that is the distance out along the direction. float dot = Vector3.Dot(localDir, myVector.normalized); // Skip elements that are in the wrong direction or which have zero distance. if (dot <= 0) { continue; } float score = Vector3.Cross(ray.direction, selCenter - ray.origin).sqrMagnitude; //Returns the distance between the selected rect's center and a ray along the edge of selectable if (score < maxScore) { maxScore = score; maxDistance = myVector.sqrMagnitude; bestPick = sel; } else if (score == maxScore) { if (maxDistance < myVector.sqrMagnitude) { continue; } else { maxScore = score; maxDistance = myVector.sqrMagnitude; bestPick = sel; } } } return(bestPick); }