Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

C# Updating Selectable Script for Unity 5.2

Discussion in 'Scripting' started by kenaochreous, Oct 21, 2015.

  1. kenaochreous

    kenaochreous

    Joined:
    Sep 7, 2012
    Posts:
    395
    I keep getting the error Cannot implicitly convert type UnityEngine.UI.Selectable to UnityEngine.UI.Selectable . The error points me to the following lines of code
    Code (CSharp):
    1. return m_Navigation.selectOnLeft;//At 392,17, Cannot implicitly convert type UnityEngine.UI.Selectable to UnityEngine.UI.Selectable
    2. return m_Navigation.selectOnRight;//At 406,17, Cannot implicitly convert type UnityEngine.UI.Selectable to UnityEngine.UI.Selectable
    3. return m_Navigation.selectOnUp; //At 420,17, Cannot implicitly convert type UnityEngine.UI.Selectable to UnityEngine.UI.Selectable
    4. return m_Navigation.selectOnDown; //At 434,17, Cannot implicitly convert type UnityEngine.UI.Selectable to UnityEngine.UI.Selectable
    I'm not sure why this error is occurring. Since UnityEngine.UI.Selectable and UnityEngine.UI.Selectable are exactly the same they shouldn't have any conversion errors. Are there any issues with the syntax? I checked through Selectable's Syntax and didn't find any missing or out of place parameters. Did importing and updating the script possibly break it?
    Code (CSharp):
    1. using System;
    2. using System.Collections.Generic;
    3. using UnityEngine.Serialization;
    4. using UnityEngine.EventSystems;
    5.  
    6. namespace UnityEngine.UI
    7. {
    8.     // Simple selectable object - derived from to create a control.
    9.     [AddComponentMenu("UI/Selectable", 70)]
    10.     [ExecuteInEditMode]
    11.     [SelectionBase]
    12.     [DisallowMultipleComponent]
    13.     public class Selectable
    14.         :
    15.         UIBehaviour,
    16.         IMoveHandler,
    17.         IPointerDownHandler, IPointerUpHandler,
    18.         IPointerEnterHandler, IPointerExitHandler,
    19.         ISelectHandler, IDeselectHandler
    20.     {
    21.         // Selection state
    22.  
    23.         // List of all the selectable objects currently active in the scene
    24.         private static List<Selectable> s_List = new List<Selectable>();
    25.         public static List<Selectable> allSelectables { get { return s_List; } }
    26.  
    27.         // Navigation information.
    28.         [FormerlySerializedAs("navigation")]
    29.         [SerializeField]
    30.         private Navigation m_Navigation = Navigation.defaultNavigation;
    31.  
    32.         // Highlighting state
    33.         public enum Transition
    34.         {
    35.             None,
    36.             ColorTint,
    37.             SpriteSwap,
    38.             Animation
    39.         }
    40.  
    41.         // Type of the transition that occurs when the button state changes.
    42.         [FormerlySerializedAs("transition")]
    43.         [SerializeField]
    44.         private Transition m_Transition = Transition.ColorTint;
    45.  
    46.         // Colors used for a color tint-based transition.
    47.         [FormerlySerializedAs("colors")]
    48.         [SerializeField]
    49.         private ColorBlock m_Colors = ColorBlock.defaultColorBlock;
    50.  
    51.         // Sprites used for a Image swap-based transition.
    52.         [FormerlySerializedAs("spriteState")]
    53.         [SerializeField]
    54.         private SpriteState m_SpriteState;
    55.  
    56.         [FormerlySerializedAs("animationTriggers")]
    57.         [SerializeField]
    58.         private AnimationTriggers m_AnimationTriggers = new AnimationTriggers();
    59.  
    60.         [Tooltip("Can the Selectable be interacted with?")]
    61.         [SerializeField]
    62.         private bool m_Interactable = true;
    63.  
    64.         // Graphic that will be colored.
    65.         [FormerlySerializedAs("highlightGraphic")]
    66.         [FormerlySerializedAs("m_HighlightGraphic")]
    67.         [SerializeField]
    68.         private Graphic m_TargetGraphic;
    69.  
    70.  
    71.         private bool m_GroupsAllowInteraction = true;
    72.  
    73.         private SelectionState m_CurrentSelectionState;
    74.  
    75.         public Navigation        navigation        { get { return m_Navigation; } set { if (SetPropertyUtility.SetStruct(ref m_Navigation, value))        OnSetProperty(); } }
    76.         public Transition        transition        { get { return m_Transition; } set { if (SetPropertyUtility.SetStruct(ref m_Transition, value))        OnSetProperty(); } }
    77.         public ColorBlock        colors            { get { return m_Colors; } set { if (SetPropertyUtility.SetStruct(ref m_Colors, value))            OnSetProperty(); } }
    78.         public SpriteState       spriteState       { get { return m_SpriteState; } set { if (SetPropertyUtility.SetStruct(ref m_SpriteState, value))       OnSetProperty(); } }
    79.         public AnimationTriggers animationTriggers { get { return m_AnimationTriggers; } set { if (SetPropertyUtility.SetClass(ref m_AnimationTriggers, value)) OnSetProperty(); } }
    80.         public Graphic           targetGraphic     { get { return m_TargetGraphic; } set { if (SetPropertyUtility.SetClass(ref m_TargetGraphic, value))     OnSetProperty(); } }
    81.         public bool              interactable      { get { return m_Interactable; } set { if (SetPropertyUtility.SetStruct(ref m_Interactable, value))      OnSetProperty(); } }
    82.  
    83.         private bool             isPointerInside   { get; set; }
    84.         private bool             isPointerDown     { get; set; }
    85.         private bool             hasSelection      { get; set; }
    86.  
    87.         protected Selectable()
    88.         {}
    89.  
    90.         // Convenience function that converts the Graphic to a Image, if possible
    91.         public Image image
    92.         {
    93.             get { return m_TargetGraphic as Image; }
    94.             set { m_TargetGraphic = value; }
    95.         }
    96.  
    97.         // Get the animator
    98.         public Animator animator
    99.         {
    100.             get { return GetComponent<Animator>(); }
    101.         }
    102.  
    103.         protected override void Awake()
    104.         {
    105.             if (m_TargetGraphic == null)
    106.                 m_TargetGraphic = GetComponent<Graphic>();
    107.         }
    108.  
    109.         private readonly List<CanvasGroup> m_CanvasGroupCache = new List<CanvasGroup>();
    110.         protected override void OnCanvasGroupChanged()
    111.         {
    112.             // Figure out if parent groups allow interaction
    113.             // If no interaction is alowed... then we need
    114.             // to not do that :)
    115.             var groupAllowInteraction = true;
    116.             Transform t = transform;
    117.             while (t != null)
    118.             {
    119.                 t.GetComponents(m_CanvasGroupCache);
    120.                 bool shouldBreak = false;
    121.                 for (var i = 0; i < m_CanvasGroupCache.Count; i++)
    122.                 {
    123.                     // if the parent group does not allow interaction
    124.                     // we need to break
    125.                     if (!m_CanvasGroupCache[i].interactable)
    126.                     {
    127.                         groupAllowInteraction = false;
    128.                         shouldBreak = true;
    129.                     }
    130.                     // if this is a 'fresh' group, then break
    131.                     // as we should not consider parents
    132.                     if (m_CanvasGroupCache[i].ignoreParentGroups)
    133.                         shouldBreak = true;
    134.                 }
    135.                 if (shouldBreak)
    136.                     break;
    137.  
    138.                 t = t.parent;
    139.             }
    140.  
    141.             if (groupAllowInteraction != m_GroupsAllowInteraction)
    142.             {
    143.                 m_GroupsAllowInteraction = groupAllowInteraction;
    144.                 OnSetProperty();
    145.             }
    146.         }
    147.  
    148.         public virtual bool IsInteractable()
    149.         {
    150.             return m_GroupsAllowInteraction && m_Interactable;
    151.         }
    152.  
    153.         // Call from unity if animation properties have changed
    154.         protected override void OnDidApplyAnimationProperties()
    155.         {
    156.             OnSetProperty();
    157.         }
    158.  
    159.         // Select on enable and add to the list.
    160.         protected override void OnEnable()
    161.         {
    162.             base.OnEnable();
    163.  
    164.             s_List.Add(this);
    165.             var state = SelectionState.Normal;
    166.  
    167.             // The button will be highlighted even in some cases where it shouldn't.
    168.             // For example: We only want to set the State as Highlighted if the StandaloneInputModule.m_CurrentInputMode == InputMode.Buttons
    169.             // But we dont have access to this, and it might not apply to other InputModules.
    170.             // TODO: figure out how to solve this. Case 617348.
    171.             if (hasSelection)
    172.                 state = SelectionState.Highlighted;
    173.  
    174.             m_CurrentSelectionState = state;
    175.             InternalEvaluateAndTransitionToSelectionState(true);
    176.         }
    177.  
    178.         private void OnSetProperty()
    179.         {
    180. #if UNITY_EDITOR
    181.             if (!Application.isPlaying)
    182.                 InternalEvaluateAndTransitionToSelectionState(true);
    183.             else
    184. #endif
    185.             InternalEvaluateAndTransitionToSelectionState(false);
    186.         }
    187.  
    188.         // Remove from the list.
    189.         protected override void OnDisable()
    190.         {
    191.             s_List.Remove(this);
    192.             InstantClearState();
    193.             base.OnDisable();
    194.         }
    195.  
    196. #if UNITY_EDITOR
    197.         protected override void OnValidate()
    198.         {
    199.             base.OnValidate();
    200.             m_Colors.fadeDuration = Mathf.Max(m_Colors.fadeDuration, 0.0f);
    201.  
    202.             // OnValidate can be called before OnEnable, this makes it unsafe to access other components
    203.             // since they might not have been initialized yet.
    204.             // OnSetProperty potentially access Animator or Graphics. (case 618186)
    205.             if (isActiveAndEnabled)
    206.             {
    207.                 // Need to clear out the override image on the target...
    208.                 DoSpriteSwap(null);
    209.  
    210.                 // If the transition mode got changed, we need to clear all the transitions, since we don't know what the old transition mode was.
    211.                 StartColorTween(Color.white, true);
    212.                 TriggerAnimation(m_AnimationTriggers.normalTrigger);
    213.  
    214.                 // And now go to the right state.
    215.                 InternalEvaluateAndTransitionToSelectionState(true);
    216.             }
    217.         }
    218.  
    219.         protected override void Reset()
    220.         {
    221.             m_TargetGraphic = GetComponent<Graphic>();
    222.         }
    223.  
    224. #endif // if UNITY_EDITOR
    225.  
    226.         protected SelectionState currentSelectionState
    227.         {
    228.             get { return m_CurrentSelectionState; }
    229.         }
    230.  
    231.         protected virtual void InstantClearState()
    232.         {
    233.             string triggerName = m_AnimationTriggers.normalTrigger;
    234.  
    235.             isPointerInside = false;
    236.             isPointerDown = false;
    237.             hasSelection = false;
    238.  
    239.             switch (m_Transition)
    240.             {
    241.                 case Transition.ColorTint:
    242.                     StartColorTween(Color.white, true);
    243.                     break;
    244.                 case Transition.SpriteSwap:
    245.                     DoSpriteSwap(null);
    246.                     break;
    247.                 case Transition.Animation:
    248.                     TriggerAnimation(triggerName);
    249.                     break;
    250.             }
    251.         }
    252.  
    253.         protected virtual void DoStateTransition(SelectionState state, bool instant)
    254.         {
    255.             Color tintColor;
    256.             Sprite transitionSprite;
    257.             string triggerName;
    258.  
    259.             switch (state)
    260.             {
    261.                 case SelectionState.Normal:
    262.                     tintColor = m_Colors.normalColor;
    263.                     transitionSprite = null;
    264.                     triggerName = m_AnimationTriggers.normalTrigger;
    265.                     break;
    266.                 case SelectionState.Highlighted:
    267.                     tintColor = m_Colors.highlightedColor;
    268.                     transitionSprite = m_SpriteState.highlightedSprite;
    269.                     triggerName = m_AnimationTriggers.highlightedTrigger;
    270.                     break;
    271.                 case SelectionState.Pressed:
    272.                     tintColor = m_Colors.pressedColor;
    273.                     transitionSprite = m_SpriteState.pressedSprite;
    274.                     triggerName = m_AnimationTriggers.pressedTrigger;
    275.                     break;
    276.                 case SelectionState.Disabled:
    277.                     tintColor = m_Colors.disabledColor;
    278.                     transitionSprite = m_SpriteState.disabledSprite;
    279.                     triggerName = m_AnimationTriggers.disabledTrigger;
    280.                     break;
    281.                 default:
    282.                     tintColor = Color.black;
    283.                     transitionSprite = null;
    284.                     triggerName = string.Empty;
    285.                     break;
    286.             }
    287.  
    288.             if (gameObject.activeInHierarchy)
    289.             {
    290.                 switch (m_Transition)
    291.                 {
    292.                     case Transition.ColorTint:
    293.                         StartColorTween(tintColor * m_Colors.colorMultiplier, instant);
    294.                         break;
    295.                     case Transition.SpriteSwap:
    296.                         DoSpriteSwap(transitionSprite);
    297.                         break;
    298.                     case Transition.Animation:
    299.                         TriggerAnimation(triggerName);
    300.                         break;
    301.                 }
    302.             }
    303.         }
    304.  
    305.         protected enum SelectionState
    306.         {
    307.             Normal,
    308.             Highlighted,
    309.             Pressed,
    310.             Disabled
    311.         }
    312.  
    313.         // Selection logic
    314.  
    315.         // Find the next selectable object in the specified world-space direction.
    316.         public Selectable FindSelectable(Vector3 dir)
    317.         {
    318.             dir = dir.normalized;
    319.             Vector3 localDir = Quaternion.Inverse(transform.rotation) * dir;
    320.             Vector3 pos = transform.TransformPoint(GetPointOnRectEdge(transform as RectTransform, localDir));
    321.             float maxScore = Mathf.NegativeInfinity;
    322.             Selectable bestPick = null;
    323.             for (int i = 0; i < s_List.Count; ++i)
    324.             {
    325.                 Selectable sel = s_List[i];
    326.  
    327.                 if (sel == this || sel == null)
    328.                     continue;
    329.  
    330.                 if (!sel.IsInteractable() || sel.navigation.mode == Navigation.Mode.None)
    331.                     continue;
    332.  
    333.                 var selRect = sel.transform as RectTransform;
    334.                 Vector3 selCenter = selRect != null ? (Vector3)selRect.rect.center : Vector3.zero;
    335.                 Vector3 myVector = sel.transform.TransformPoint(selCenter) - pos;
    336.  
    337.                 // Value that is the distance out along the direction.
    338.                 float dot = Vector3.Dot(dir, myVector);
    339.  
    340.                 // Skip elements that are in the wrong direction or which have zero distance.
    341.                 // This also ensures that the scoring formula below will not have a division by zero error.
    342.                 if (dot <= 0)
    343.                     continue;
    344.  
    345.                 // This scoring function has two priorities:
    346.                 // - Score higher for positions that are closer.
    347.                 // - Score higher for positions that are located in the right direction.
    348.                 // This scoring function combines both of these criteria.
    349.                 // It can be seen as this:
    350.                 //   Dot (dir, myVector.normalized) / myVector.magnitude
    351.                 // The first part equals 1 if the direction of myVector is the same as dir, and 0 if it's orthogonal.
    352.                 // The second part scores lower the greater the distance is by dividing by the distance.
    353.                 // The formula below is equivalent but more optimized.
    354.                 //
    355.                 // If a given score is chosen, the positions that evaluate to that score will form a circle
    356.                 // that touches pos and whose center is located along dir. A way to visualize the resulting functionality is this:
    357.                 // From the position pos, blow up a circular balloon so it grows in the direction of dir.
    358.                 // The first Selectable whose center the circular balloon touches is the one that's chosen.
    359.                 float score = dot / myVector.sqrMagnitude;
    360.  
    361.                 if (score > maxScore)
    362.                 {
    363.                     maxScore = score;
    364.                     bestPick = sel;
    365.                 }
    366.             }
    367.             return bestPick;
    368.         }
    369.  
    370.         private static Vector3 GetPointOnRectEdge(RectTransform rect, Vector2 dir)
    371.         {
    372.             if (rect == null)
    373.                 return Vector3.zero;
    374.             if (dir != Vector2.zero)
    375.                 dir /= Mathf.Max(Mathf.Abs(dir.x), Mathf.Abs(dir.y));
    376.             dir = rect.rect.center + Vector2.Scale(rect.rect.size, dir * 0.5f);
    377.             return dir;
    378.         }
    379.  
    380.         // Convenience function -- change the selection to the specified object if it's not null and happens to be active.
    381.         void Navigate(AxisEventData eventData, Selectable sel)
    382.         {
    383.             if (sel != null && sel.IsActive())
    384.                 eventData.selectedObject = sel.gameObject;
    385.         }
    386.  
    387.         // Find the selectable object to the left of this one.
    388.         public virtual Selectable FindSelectableOnLeft()
    389.         {
    390.             if (m_Navigation.mode == Navigation.Mode.Explicit)
    391.             {
    392.                 return m_Navigation.selectOnLeft; //At 392,17, Cannot implicitly convert type UnityEngine.UI.Selectable to UnityEngine.UI.Selectable
    393.             }
    394.             if ((m_Navigation.mode & Navigation.Mode.Horizontal) != 0)
    395.             {
    396.                 return FindSelectable(transform.rotation * Vector3.left);
    397.             }
    398.             return null;
    399.         }
    400.  
    401.         // Find the selectable object to the right of this one.
    402.         public virtual Selectable FindSelectableOnRight()
    403.         {
    404.             if (m_Navigation.mode == Navigation.Mode.Explicit)
    405.             {
    406.                 return m_Navigation.selectOnRight; //At 406,17, Cannot implicitly convert type UnityEngine.UI.Selectable to UnityEngine.UI.Selectable
    407.             }
    408.             if ((m_Navigation.mode & Navigation.Mode.Horizontal) != 0)
    409.             {
    410.                 return FindSelectable(transform.rotation * Vector3.right);
    411.             }
    412.             return null;
    413.         }
    414.  
    415.         // Find the selectable object above this one
    416.         public virtual Selectable FindSelectableOnUp()
    417.         {
    418.             if (m_Navigation.mode == Navigation.Mode.Explicit)
    419.             {
    420.                 return m_Navigation.selectOnUp; //At 420,17, Cannot implicitly convert type UnityEngine.UI.Selectable to UnityEngine.UI.Selectable
    421.             }
    422.             if ((m_Navigation.mode & Navigation.Mode.Vertical) != 0)
    423.             {
    424.                 return FindSelectable(transform.rotation * Vector3.up);
    425.             }
    426.             return null;
    427.         }
    428.  
    429.         // Find the selectable object below this one.
    430.         public virtual Selectable FindSelectableOnDown()
    431.         {
    432.             if (m_Navigation.mode == Navigation.Mode.Explicit)
    433.             {
    434.                 return m_Navigation.selectOnDown; //At 434,17, Cannot implicitly convert type UnityEngine.UI.Selectable to UnityEngine.UI.Selectable
    435.             }
    436.             if ((m_Navigation.mode & Navigation.Mode.Vertical) != 0)
    437.             {
    438.                 return FindSelectable(transform.rotation * Vector3.down);
    439.             }
    440.             return null;
    441.         }
    442.  
    443.         public virtual void OnMove(AxisEventData eventData)
    444.         {
    445.             switch (eventData.moveDir)
    446.             {
    447.                 case MoveDirection.Right:
    448.                     Navigate(eventData, FindSelectableOnRight());
    449.                     break;
    450.  
    451.                 case MoveDirection.Up:
    452.                     Navigate(eventData, FindSelectableOnUp());
    453.                     break;
    454.  
    455.                 case MoveDirection.Left:
    456.                     Navigate(eventData, FindSelectableOnLeft());
    457.                     break;
    458.  
    459.                 case MoveDirection.Down:
    460.                     Navigate(eventData, FindSelectableOnDown());
    461.                     break;
    462.             }
    463.         }
    464.  
    465.         void StartColorTween(Color targetColor, bool instant)
    466.         {
    467.             if (m_TargetGraphic == null)
    468.                 return;
    469.  
    470.             m_TargetGraphic.CrossFadeColor(targetColor, instant ? 0f : m_Colors.fadeDuration, true, true);
    471.         }
    472.  
    473.         void DoSpriteSwap(Sprite newSprite)
    474.         {
    475.             if (image == null)
    476.                 return;
    477.  
    478.             image.overrideSprite = newSprite;
    479.         }
    480.  
    481.         void TriggerAnimation(string triggername)
    482.         {
    483.             if (animator == null || !animator.enabled || !animator.isActiveAndEnabled || animator.runtimeAnimatorController == null || string.IsNullOrEmpty(triggername))
    484.                 return;
    485.  
    486.             animator.ResetTrigger(m_AnimationTriggers.normalTrigger);
    487.             animator.ResetTrigger(m_AnimationTriggers.pressedTrigger);
    488.             animator.ResetTrigger(m_AnimationTriggers.highlightedTrigger);
    489.             animator.ResetTrigger(m_AnimationTriggers.disabledTrigger);
    490.             animator.SetTrigger(triggername);
    491.         }
    492.  
    493.         // Whether the control should be 'selected'.
    494.         protected bool IsHighlighted(BaseEventData eventData)
    495.         {
    496.             if (!IsActive())
    497.                 return false;
    498.  
    499.             if (IsPressed())
    500.                 return false;
    501.  
    502.             bool selected = hasSelection;
    503.             if (eventData is PointerEventData)
    504.             {
    505.                 var pointerData = eventData as PointerEventData;
    506.                 selected |=
    507.                     (isPointerDown && !isPointerInside && pointerData.pointerPress == gameObject) // This object pressed, but pointer moved off
    508.                     || (!isPointerDown && isPointerInside && pointerData.pointerPress == gameObject) // This object pressed, but pointer released over (PointerUp event)
    509.                     || (!isPointerDown && isPointerInside && pointerData.pointerPress == null); // Nothing pressed, but pointer is over
    510.             }
    511.             else
    512.             {
    513.                 selected |= isPointerInside;
    514.             }
    515.             return selected;
    516.         }
    517.  
    518.         [Obsolete("Is Pressed no longer requires eventData", false)]
    519.         protected bool IsPressed(BaseEventData eventData)
    520.         {
    521.             return IsPressed();
    522.         }
    523.  
    524.         // Whether the control should be pressed.
    525.         protected bool IsPressed()
    526.         {
    527.             if (!IsActive())
    528.                 return false;
    529.  
    530.             return isPointerInside && isPointerDown;
    531.         }
    532.  
    533.         // The current visual state of the control.
    534.         protected void UpdateSelectionState(BaseEventData eventData)
    535.         {
    536.             if (IsPressed())
    537.             {
    538.                 m_CurrentSelectionState = SelectionState.Pressed;
    539.                 return;
    540.             }
    541.  
    542.             if (IsHighlighted(eventData))
    543.             {
    544.                 m_CurrentSelectionState = SelectionState.Highlighted;
    545.                 return;
    546.             }
    547.  
    548.             m_CurrentSelectionState = SelectionState.Normal;
    549.         }
    550.  
    551.         // Change the button to the correct state
    552.         private void EvaluateAndTransitionToSelectionState(BaseEventData eventData)
    553.         {
    554.             if (!IsActive())
    555.                 return;
    556.  
    557.             UpdateSelectionState(eventData);
    558.             InternalEvaluateAndTransitionToSelectionState(false);
    559.         }
    560.  
    561.         private void InternalEvaluateAndTransitionToSelectionState(bool instant)
    562.         {
    563.             var transitionState = m_CurrentSelectionState;
    564.             if (IsActive() && !IsInteractable())
    565.                 transitionState = SelectionState.Disabled;
    566.             DoStateTransition(transitionState, instant);
    567.         }
    568.  
    569.         public virtual void OnPointerDown(PointerEventData eventData)
    570.         {
    571.             if (eventData.button != PointerEventData.InputButton.Left)
    572.                 return;
    573.  
    574.             // Selection tracking
    575.             if (IsInteractable() && navigation.mode != Navigation.Mode.None)
    576.                 EventSystem.current.SetSelectedGameObject(gameObject, eventData);
    577.  
    578.             isPointerDown = true;
    579.             EvaluateAndTransitionToSelectionState(eventData);
    580.         }
    581.  
    582.         public virtual void OnPointerUp(PointerEventData eventData)
    583.         {
    584.             if (eventData.button != PointerEventData.InputButton.Left)
    585.                 return;
    586.  
    587.             isPointerDown = false;
    588.             EvaluateAndTransitionToSelectionState(eventData);
    589.         }
    590.  
    591.         public virtual void OnPointerEnter(PointerEventData eventData)
    592.         {
    593.             isPointerInside = true;
    594.             EvaluateAndTransitionToSelectionState(eventData);
    595.         }
    596.  
    597.         public virtual void OnPointerExit(PointerEventData eventData)
    598.         {
    599.             isPointerInside = false;
    600.             EvaluateAndTransitionToSelectionState(eventData);
    601.         }
    602.  
    603.         public virtual void OnSelect(BaseEventData eventData)
    604.         {
    605.             hasSelection = true;
    606.             EvaluateAndTransitionToSelectionState(eventData);
    607.         }
    608.  
    609.         public virtual void OnDeselect(BaseEventData eventData)
    610.         {
    611.             hasSelection = false;
    612.             EvaluateAndTransitionToSelectionState(eventData);
    613.         }
    614.  
    615.         public virtual void Select()
    616.         {
    617.             if (EventSystem.current.alreadySelecting)
    618.                 return;
    619.  
    620.             EventSystem.current.SetSelectedGameObject(gameObject);
    621.         }
    622.     }
    623. }
    624.  
     
  2. generatedname

    generatedname

    Joined:
    Sep 15, 2015
    Posts:
    7
    what is the method's (or one of them) return type where these return statements exist?

    are either the return type or returned values nullable?
     
    Last edited: Oct 21, 2015
  3. kenaochreous

    kenaochreous

    Joined:
    Sep 7, 2012
    Posts:
    395
    Here are the methods that the return types are in. There is only one instance where they return null and that isn't causing the error. It is specifying the return I mentioned previously are causing the error.
    Code (CSharp):
    1.  public virtual Selectable FindSelectableOnLeft()
    2.         {
    3.             if (m_Navigation.mode == Navigation.Mode.Explicit)
    4.             {
    5.                 return m_Navigation.selectOnLeft;//At 392,17, Cannot implicitly convert type UnityEngine.UI.Selectable to UnityEngine.UI.Selectable
    6.             }
    7.             if ((m_Navigation.mode & Navigation.Mode.Horizontal) != 0)
    8.             {
    9.                 return FindSelectable(transform.rotation * Vector3.left);
    10.             }
    11.             return null;
    12.         }
    13.  
    14.         // Find the selectable object to the right of this one.
    15.         public virtual Selectable FindSelectableOnRight()
    16.         {
    17.             if (m_Navigation.mode == Navigation.Mode.Explicit)
    18.             {
    19.                 return m_Navigation.selectOnRight;//At 406,17, Cannot implicitly convert type UnityEngine.UI.Selectable to UnityEngine.UI.Selectable
    20.             }
    21.             if ((m_Navigation.mode & Navigation.Mode.Horizontal) != 0)
    22.             {
    23.                 return FindSelectable(transform.rotation * Vector3.right);
    24.             }
    25.             return null;
    26.         }
    27.  
    28.         // Find the selectable object above this one
    29.         public virtual Selectable FindSelectableOnUp()
    30.         {
    31.             if (m_Navigation.mode == Navigation.Mode.Explicit)
    32.             {
    33.                 return m_Navigation.selectOnUp; //At 420,17, Cannot implicitly convert type UnityEngine.UI.Selectable to UnityEngine.UI.Selectable
    34.             }
    35.             if ((m_Navigation.mode & Navigation.Mode.Vertical) != 0)
    36.             {
    37.                 return FindSelectable(transform.rotation * Vector3.up);
    38.             }
    39.             return null;
    40.         }
    41.  
    42.         // Find the selectable object below this one.
    43.         public virtual Selectable FindSelectableOnDown()
    44.         {
    45.             if (m_Navigation.mode == Navigation.Mode.Explicit)
    46.             {
    47.                 return m_Navigation.selectOnDown;//At 434,17, Cannot implicitly convert type UnityEngine.UI.Selectable to UnityEngine.UI.Selectable
    48.             }
    49.             if ((m_Navigation.mode & Navigation.Mode.Vertical) != 0)
    50.             {
    51.                 return FindSelectable(transform.rotation * Vector3.down);
    52.             }
    53.             return null;
    54.         }
     
  4. generatedname

    generatedname

    Joined:
    Sep 15, 2015
    Posts:
    7
    Last edited: Oct 22, 2015