Advertisement
Saxy_Guy

InputField nullchecking fix

Jul 4th, 2016
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 50.01 KB | None | 0 0
  1. //  Copyright 2016 MaterialUI for Unity http://materialunity.com
  2. //  Please see license file for terms and conditions of use, and more information.
  3.  
  4.  
  5. using System;
  6. using System.Linq;
  7. #if UNITY_EDITOR
  8. using UnityEditor;
  9. #endif
  10. using UnityEngine;
  11. using UnityEngine.EventSystems;
  12. using UnityEngine.UI;
  13.  
  14. namespace MaterialUI
  15. {
  16. #if UNITY_EDITOR
  17.     [InitializeOnLoad]
  18. #endif
  19.     [ExecuteInEditMode]
  20.     [RequireComponent(typeof(InputField))]
  21.     [RequireComponent(typeof(CanvasGroup))]
  22.     [AddComponentMenu("MaterialUI/Material Input Field", 100)]
  23.     public class MaterialInputField : UIBehaviour, ILayoutGroup, ILayoutElement, ISelectHandler, IDeselectHandler
  24.     {
  25.         public enum ColorSelectionState
  26.         {
  27.             EnabledSelected,
  28.             EnabledDeselected,
  29.             DisabledSelected,
  30.             DisabledDeselected
  31.         }
  32.  
  33.         //  Options
  34.         [SerializeField]
  35.         private string m_HintText;
  36.         public string hintText
  37.         {
  38.             get { return m_HintText; }
  39.             set
  40.             {
  41.                 m_HintText = value;
  42.                 hintTextObject.text = value;
  43.  
  44. #if UNITY_EDITOR
  45.                 m_LastHintText = value;
  46. #endif
  47.             }
  48.         }
  49.  
  50.         [SerializeField]
  51.         private bool m_FloatingHint = true;
  52.         public bool floatingHint
  53.         {
  54.             get { return m_FloatingHint; }
  55.             set
  56.             {
  57.                 m_FloatingHint = value;
  58.                 SetLayoutDirty();
  59.             }
  60.         }
  61.  
  62.         [SerializeField]
  63.         private bool m_HasValidation = true;
  64.         public bool hasValidation
  65.         {
  66.             get { return m_HasValidation; }
  67.             set
  68.             {
  69.                 m_HasValidation = value;
  70.                 SetLayoutDirty();
  71.                 ValidateText();
  72.             }
  73.         }
  74.  
  75.         [SerializeField]
  76.         private bool m_ValidateOnStart;
  77.  
  78.         public bool validateOnStart
  79.         {
  80.             get { return m_ValidateOnStart; }
  81.             set
  82.             {
  83.                 m_ValidateOnStart = value;
  84.                 if (value)
  85.                 {
  86.                     ValidateText();
  87.                 }
  88.             }
  89.         }
  90.  
  91.         [SerializeField]
  92.         private bool m_HasCharacterCounter = true;
  93.         public bool hasCharacterCounter
  94.         {
  95.             get { return m_HasCharacterCounter; }
  96.             set
  97.             {
  98.                 m_HasCharacterCounter = value;
  99.                 m_CounterText.gameObject.SetActive(m_HasCharacterCounter);
  100.                 SetLayoutDirty();
  101.                 UpdateCounter();
  102.             }
  103.         }
  104.  
  105.         [SerializeField]
  106.         private bool m_MatchInputFieldCharacterLimit = true;
  107.         public bool matchInputFieldCharacterLimit
  108.         {
  109.             get { return m_MatchInputFieldCharacterLimit; }
  110.             set
  111.             {
  112.                 m_MatchInputFieldCharacterLimit = value;
  113.                 SetLayoutDirty();
  114.                 UpdateCounter();
  115.             }
  116.         }
  117.  
  118.         [SerializeField]
  119.         private int m_CharacterLimit;
  120.         public int characterLimit
  121.         {
  122.             get { return m_CharacterLimit; }
  123.             set
  124.             {
  125.                 m_CharacterLimit = value;
  126.                 SetLayoutDirty();
  127.                 UpdateCounter();
  128.             }
  129.         }
  130.  
  131.         //  Layout
  132.         [SerializeField]
  133.         private int m_FloatingHintFontSize = 12;
  134.         public int floatingHintFontSize
  135.         {
  136.             get { return m_FloatingHintFontSize; }
  137.             set
  138.             {
  139.                 m_FloatingHintFontSize = value;
  140.                 SetLayoutDirty();
  141.             }
  142.         }
  143.  
  144.         [SerializeField]
  145.         private bool m_FitHeightToContent = true;
  146.         public bool fitHeightToContent
  147.         {
  148.             get { return m_FitHeightToContent; }
  149.             set
  150.             {
  151.                 m_FitHeightToContent = value;
  152.                 SetLayoutDirty();
  153.             }
  154.         }
  155.  
  156.         [SerializeField]
  157.         private Vector2 m_LeftContentOffset;
  158.  
  159.         [SerializeField]
  160.         private Vector2 m_RightContentOffset;
  161.  
  162.         [SerializeField]
  163.         private bool m_ManualPreferredWidth;
  164.         public bool manualPreferredWidth
  165.         {
  166.             get { return m_ManualPreferredWidth; }
  167.             set
  168.             {
  169.                 m_ManualPreferredWidth = value;
  170.                 SetLayoutDirty();
  171.             }
  172.         }
  173.  
  174.         [SerializeField]
  175.         private bool m_ManualPreferredHeight;
  176.         public bool manualPreferredHeight
  177.         {
  178.             get { return m_ManualPreferredHeight; }
  179.             set
  180.             {
  181.                 m_ManualPreferredHeight = value;
  182.                 SetLayoutDirty();
  183.             }
  184.         }
  185.  
  186.         [SerializeField]
  187.         private Vector2 m_ManualSize;
  188.         public Vector2 manualSize
  189.         {
  190.             get { return m_ManualSize; }
  191.             set
  192.             {
  193.                 m_ManualSize = value;
  194.                 SetLayoutDirty();
  195.             }
  196.         }
  197.  
  198.         //  References
  199.  
  200.         [SerializeField]
  201.         private GameObject m_TextValidator;
  202.         public GameObject textValidator
  203.         {
  204.             get { return m_TextValidator; }
  205.             set
  206.             {
  207.                 m_TextValidator = value;
  208.                 ValidateText();
  209.             }
  210.         }
  211.  
  212.         [SerializeField]
  213.         private RectTransform m_RectTransform;
  214.         public RectTransform rectTransform
  215.         {
  216.             get
  217.             {
  218.                 if (m_RectTransform == null)
  219.                 {
  220.                     m_RectTransform = (RectTransform)transform;
  221.                 }
  222.                 return m_RectTransform;
  223.             }
  224.         }
  225.  
  226.         [SerializeField]
  227.         private InputField m_InputField;
  228.         public InputField inputField
  229.         {
  230.             get
  231.             {
  232.                 if (m_InputField == null)
  233.                 {
  234.                     m_InputField = GetComponent<InputField>();
  235.                 }
  236.                 return m_InputField;
  237.             }
  238.         }
  239.  
  240.         [SerializeField]
  241.         private RectTransform m_InputTextTransform;
  242.         public RectTransform inputTextTransform
  243.         {
  244.             get
  245.             {
  246.                 if (m_InputTextTransform == null)
  247.                 {
  248.                     if (m_InputField != null)
  249.                     {
  250.                         if (m_InputField.textComponent != null)
  251.                         {
  252.                             m_InputTextTransform = m_InputField.textComponent.GetComponent<RectTransform>();
  253.                         }
  254.                     }
  255.                 }
  256.  
  257.                 return m_InputTextTransform;
  258.             }
  259.         }
  260.  
  261.         [SerializeField]
  262.         private RectTransform m_HintTextTransform;
  263.         public RectTransform hintTextTransform
  264.         {
  265.             get { return m_HintTextTransform; }
  266.             set
  267.             {
  268.                 m_HintTextTransform = value;
  269.                 SetLayoutDirty();
  270.                 UpdateCounter();
  271.                 UpdateSelectionState();
  272.                 ValidateText();
  273.             }
  274.         }
  275.  
  276.         [SerializeField]
  277.         private RectTransform m_CounterTextTransform;
  278.         public RectTransform counterTextTransform
  279.         {
  280.             get { return m_CounterTextTransform; }
  281.             set
  282.             {
  283.                 m_CounterTextTransform = value;
  284.                 SetLayoutDirty();
  285.                 UpdateCounter();
  286.                 UpdateSelectionState();
  287.                 ValidateText();
  288.             }
  289.         }
  290.  
  291.         [SerializeField]
  292.         private RectTransform m_ValidationTextTransform;
  293.         public RectTransform validationTextTransform
  294.         {
  295.             get { return m_ValidationTextTransform; }
  296.             set
  297.             {
  298.                 m_ValidationTextTransform = value;
  299.                 SetLayoutDirty();
  300.                 UpdateCounter();
  301.                 UpdateSelectionState();
  302.                 ValidateText();
  303.             }
  304.         }
  305.  
  306.         [SerializeField]
  307.         private RectTransform m_LineTransform;
  308.         public RectTransform lineTransform
  309.         {
  310.             get { return m_LineTransform; }
  311.             set
  312.             {
  313.                 m_LineTransform = value;
  314.                 SetLayoutDirty();
  315.                 UpdateSelectionState();
  316.             }
  317.         }
  318.  
  319.         [SerializeField]
  320.         private RectTransform m_ActiveLineTransform;
  321.         public RectTransform activeLineTransform
  322.         {
  323.             get { return m_ActiveLineTransform; }
  324.             set
  325.             {
  326.                 m_ActiveLineTransform = value;
  327.                 SetLayoutDirty();
  328.                 UpdateSelectionState();
  329.             }
  330.         }
  331.  
  332.         [SerializeField]
  333.         private RectTransform m_LeftContentTransform;
  334.         public RectTransform leftContentTransform
  335.         {
  336.             get { return m_LeftContentTransform; }
  337.             set
  338.             {
  339.                 m_LeftContentTransform = value;
  340.                 SetLayoutDirty();
  341.                 UpdateSelectionState();
  342.             }
  343.         }
  344.  
  345.         [SerializeField]
  346.         private RectTransform m_RightContentTransform;
  347.         public RectTransform rightContentTransform
  348.         {
  349.             get { return m_RightContentTransform; }
  350.             set
  351.             {
  352.                 m_RightContentTransform = value;
  353.                 SetLayoutDirty();
  354.                 UpdateSelectionState();
  355.             }
  356.         }
  357.  
  358.         [SerializeField]
  359.         private Text m_InputText;
  360.         public Text inputText
  361.         {
  362.             get
  363.             {
  364.                 if (m_InputText == null)
  365.                 {
  366.                     if (inputTextTransform != null)
  367.                     {
  368.                         m_InputText = inputTextTransform.GetComponent<Text>();
  369.                     }
  370.                 }
  371.                 return m_InputText;
  372.             }
  373.         }
  374.  
  375.         [SerializeField]
  376.         private Text m_HintTextObject;
  377.         public Text hintTextObject
  378.         {
  379.             get
  380.             {
  381.                 if (m_HintTextObject == null)
  382.                 {
  383.                     if (m_HintTextTransform != null)
  384.                     {
  385.                         m_HintTextObject = m_HintTextTransform.GetComponent<Text>();
  386.                     }
  387.                 }
  388.                 return m_HintTextObject;
  389.             }
  390.         }
  391.  
  392.         [SerializeField]
  393.         private Text m_CounterText;
  394.         public Text counterText
  395.         {
  396.             get
  397.             {
  398.                 if (m_CounterText == null)
  399.                 {
  400.                     if (m_CounterTextTransform != null)
  401.                     {
  402.                         m_CounterText = m_CounterTextTransform.GetComponent<Text>();
  403.                     }
  404.                 }
  405.                 return m_CounterText;
  406.             }
  407.         }
  408.  
  409.         [SerializeField]
  410.         private Text m_ValidationText;
  411.         public Text validationText
  412.         {
  413.             get
  414.             {
  415.                 if (m_ValidationText == null)
  416.                 {
  417.                     if (m_ValidationTextTransform != null)
  418.                     {
  419.                         m_ValidationText = m_ValidationTextTransform.GetComponent<Text>();
  420.                     }
  421.                 }
  422.                 return m_ValidationText;
  423.             }
  424.         }
  425.  
  426.         [SerializeField]
  427.         private Image m_LineImage;
  428.         public Image lineImage
  429.         {
  430.             get
  431.             {
  432.                 if (m_LineImage == null)
  433.                 {
  434.                     if (m_LineTransform != null)
  435.                     {
  436.                         m_LineImage = m_LineTransform.GetComponent<Image>();
  437.                     }
  438.                 }
  439.                 return m_LineImage;
  440.             }
  441.         }
  442.  
  443.         [SerializeField]
  444.         private CanvasGroup m_ActiveLineCanvasGroup;
  445.         public CanvasGroup activeLineCanvasGroup
  446.         {
  447.             get
  448.             {
  449.                 if (m_ActiveLineCanvasGroup == null)
  450.                 {
  451.                     if (m_ActiveLineTransform != null)
  452.                     {
  453.                         m_ActiveLineCanvasGroup = m_ActiveLineTransform.GetComponent<CanvasGroup>();
  454.                     }
  455.                 }
  456.                 return m_ActiveLineCanvasGroup;
  457.             }
  458.         }
  459.  
  460.         [SerializeField]
  461.         private CanvasGroup m_HintTextCanvasGroup;
  462.         public CanvasGroup hintTextCanvasGroup
  463.         {
  464.             get
  465.             {
  466.                 if (m_HintTextCanvasGroup == null)
  467.                 {
  468.                     if (m_HintTextTransform != null)
  469.                     {
  470.                         m_HintTextCanvasGroup = m_HintTextTransform.GetComponent<CanvasGroup>();
  471.                     }
  472.                 }
  473.                 return m_HintTextCanvasGroup;
  474.             }
  475.         }
  476.  
  477.         [SerializeField]
  478.         private CanvasGroup m_ValidationCanvasGroup;
  479.         public CanvasGroup validationCanvasGroup
  480.         {
  481.             get
  482.             {
  483.                 if (m_ValidationCanvasGroup == null)
  484.                 {
  485.                     if (m_ValidationTextTransform != null)
  486.                     {
  487.                         m_ValidationCanvasGroup = m_ValidationTextTransform.GetComponent<CanvasGroup>();
  488.                     }
  489.                 }
  490.                 return m_ValidationCanvasGroup;
  491.             }
  492.         }
  493.  
  494.         private MaterialUIScaler m_MaterialUiScaler;
  495.         public MaterialUIScaler materialUiScaler
  496.         {
  497.             get
  498.             {
  499.                 if (m_MaterialUiScaler == null)
  500.                 {
  501.                     m_MaterialUiScaler = MaterialUIScaler.GetParentScaler(transform);
  502.                 }
  503.                 return m_MaterialUiScaler;
  504.             }
  505.         }
  506.  
  507.         private RectTransform m_CaretTransform;
  508.         public RectTransform caretTransform
  509.         {
  510.             get
  511.             {
  512.                 if (m_CaretTransform == null)
  513.                 {
  514.                     LayoutElement[] elements = GetComponentsInChildren<LayoutElement>();
  515.  
  516.                     for (int i = 0; i < elements.Length; i++)
  517.                     {
  518.                         if (elements[i].name == name + " Input Caret")
  519.                         {
  520.                             m_CaretTransform = (RectTransform)elements[i].transform;
  521.                         }
  522.                     }
  523.                 }
  524.                 return m_CaretTransform;
  525.             }
  526.         }
  527.  
  528.         [SerializeField]
  529.         private Color m_LeftContentActiveColor = MaterialColor.iconDark;
  530.         public Color leftContentActiveColor
  531.         {
  532.             get { return m_LeftContentActiveColor; }
  533.             set { m_LeftContentActiveColor = value; }
  534.         }
  535.  
  536.         [SerializeField]
  537.         private Color m_LeftContentInactiveColor = MaterialColor.disabledDark;
  538.         public Color leftContentInactiveColor
  539.         {
  540.             get { return m_LeftContentInactiveColor; }
  541.             set { m_LeftContentInactiveColor = value; }
  542.         }
  543.  
  544.         [SerializeField]
  545.         private Color m_RightContentActiveColor = MaterialColor.iconDark;
  546.         public Color rightContentActiveColor
  547.         {
  548.             get { return m_RightContentActiveColor; }
  549.             set { m_RightContentActiveColor = value; }
  550.         }
  551.  
  552.         [SerializeField]
  553.         private Color m_RightContentInactiveColor = MaterialColor.disabledDark;
  554.         public Color rightContentInactiveColor
  555.         {
  556.             get { return m_RightContentInactiveColor; }
  557.             set { m_RightContentInactiveColor = value; }
  558.         }
  559.  
  560.         [SerializeField]
  561.         private Color m_HintTextActiveColor = MaterialColor.textHintDark;
  562.         public Color hintTextActiveColor
  563.         {
  564.             get { return m_HintTextActiveColor; }
  565.             set { m_HintTextActiveColor = value; }
  566.         }
  567.  
  568.         [SerializeField]
  569.         private Color m_HintTextInactiveColor = MaterialColor.disabledDark;
  570.         public Color hintTextInactiveColor
  571.         {
  572.             get { return m_HintTextInactiveColor; }
  573.             set { m_HintTextInactiveColor = value; }
  574.         }
  575.  
  576.         [SerializeField]
  577.         private Color m_LineActiveColor = Color.black;
  578.         public Color lineActiveColor
  579.         {
  580.             get { return m_LineActiveColor; }
  581.             set { m_LineActiveColor = value; }
  582.         }
  583.  
  584.         [SerializeField]
  585.         private Color m_LineInactiveColor = MaterialColor.disabledDark;
  586.         public Color lineInactiveColor
  587.         {
  588.             get { return m_LineInactiveColor; }
  589.             set { m_LineInactiveColor = value; }
  590.         }
  591.  
  592.         [SerializeField]
  593.         private Color m_ValidationActiveColor = MaterialColor.red500;
  594.         public Color validationActiveColor
  595.         {
  596.             get { return m_ValidationActiveColor; }
  597.             set { m_ValidationActiveColor = value; }
  598.         }
  599.  
  600.         [SerializeField]
  601.         private Color m_ValidationInactiveColor = MaterialColor.disabledDark;
  602.         public Color validationInactiveColor
  603.         {
  604.             get { return m_ValidationInactiveColor; }
  605.             set { m_ValidationInactiveColor = value; }
  606.         }
  607.  
  608.         [SerializeField]
  609.         private Color m_CounterActiveColor = MaterialColor.textSecondaryDark;
  610.         public Color counterActiveColor
  611.         {
  612.             get { return m_CounterActiveColor; }
  613.             set { m_CounterActiveColor = value; }
  614.         }
  615.  
  616.         [SerializeField]
  617.         private Color m_CounterInactiveColor = MaterialColor.disabledDark;
  618.         public Color counterInactiveColor
  619.         {
  620.             get { return m_CounterInactiveColor; }
  621.             set { m_CounterInactiveColor = value; }
  622.         }
  623.  
  624.         [SerializeField]
  625.         private Graphic m_LeftContentGraphic;
  626.         public Graphic leftContentGraphic
  627.         {
  628.             get { return m_LeftContentGraphic; }
  629.             set { m_LeftContentGraphic = value; }
  630.         }
  631.  
  632.         [SerializeField]
  633.         private Graphic m_RightContentGraphic;
  634.         public Graphic rightContentGraphic
  635.         {
  636.             get { return m_RightContentGraphic; }
  637.             set { m_RightContentGraphic = value; }
  638.         }
  639.  
  640.         [SerializeField]
  641.         private float m_HintTextFloatingValue;
  642.         public float hintTextFloatingValue
  643.         {
  644.             get { return m_HintTextFloatingValue; }
  645.             set { m_HintTextFloatingValue = value; }
  646.         }
  647.  
  648.         [SerializeField]
  649.         private bool m_Interactable = true;
  650.         public bool interactable
  651.         {
  652.             get { return m_Interactable; }
  653.             set
  654.             {
  655.                 m_Interactable = value;
  656.                 UpdateSelectionState();
  657.                 inputField.interactable = value;
  658.             }
  659.         }
  660.  
  661.         private CanvasGroup m_CanvasGroup;
  662.         public CanvasGroup canvasGroup
  663.         {
  664.             get
  665.             {
  666.                 if (!m_CanvasGroup)
  667.                 {
  668.                     m_CanvasGroup = gameObject.GetComponent<CanvasGroup>();
  669.                 }
  670.                 return m_CanvasGroup;
  671.             }
  672.         }
  673.  
  674.         private static Sprite m_LineDisabledSprite;
  675.         private static Sprite lineDisabledSprite
  676.         {
  677.             get
  678.             {
  679.                 if (m_LineDisabledSprite == null)
  680.                 {
  681.                     Color[] colors =
  682.                     {
  683.                         Color.white,
  684.                         Color.white,
  685.                         Color.clear,
  686.                         Color.clear,
  687.                         Color.white,
  688.                         Color.white,
  689.                         Color.clear,
  690.                         Color.clear
  691.                     };
  692.  
  693.                     Texture2D texture = new Texture2D(4, 2, TextureFormat.ARGB32, false);
  694.                     texture.filterMode = FilterMode.Point;
  695.                     texture.SetPixels(colors);
  696.                     texture.hideFlags = HideFlags.HideAndDontSave;
  697.  
  698.                     Sprite sprite = Sprite.Create(texture, new Rect(0, 0, 4, 2), new Vector2(0.5f, 0.5f));
  699.                     sprite.hideFlags = HideFlags.HideAndDontSave;
  700.  
  701.                     m_LineDisabledSprite = sprite;
  702.                 }
  703.  
  704.                 return m_LineDisabledSprite;
  705.             }
  706.         }
  707.  
  708.         private ITextValidator m_CustomTextValidator;
  709.         public ITextValidator customTextValidator
  710.         {
  711.             get { return m_CustomTextValidator; }
  712.             set
  713.             {
  714.                 m_CustomTextValidator = value;
  715.                 m_CustomTextValidator.Init(this);
  716.             }
  717.         }
  718.  
  719.         [SerializeField]
  720.         private bool m_LastCounterState;
  721.  
  722.         private bool m_AnimateHintText;
  723.  
  724.         private bool m_HasBeenSelected;
  725.  
  726.         private int m_LeftContentTweener;
  727.         private int m_RightContentTweener;
  728.         private int m_HintTextTweener;
  729.         private int m_ValidationColorTweener;
  730.         private int m_CounterTweener;
  731.  
  732.         private Vector2 m_LastSize;
  733.         private bool m_LastFocussedState;
  734.         private ColorSelectionState m_CurrentSelectionState;
  735.         private ColorSelectionState m_LastSelectionState;
  736.  
  737.         private float m_TopSectionHeight;
  738.         private float m_BottomSectionHeight;
  739.         private float m_LeftSectionWidth;
  740.         private float m_RightSectionWidth;
  741.  
  742.         //  Animation
  743.         [SerializeField]
  744.         private float m_AnimationDuration = 0.25f;
  745.         private int m_ActiveLinePosTweener;
  746.         private int m_ActiveLineSizeTweener;
  747.         private int m_ActiveLineAlphaTweener;
  748.         private int m_HintTextFloatingValueTweener;
  749.         private int m_ValidationTweener;
  750.  
  751.         private Vector2 m_LastRectPosition;
  752.         private Vector2 m_LastRectSize;
  753.         private Vector2 m_LayoutSize;
  754.  
  755. #if UNITY_EDITOR
  756.         private string m_LastHintText;
  757. #endif
  758.  
  759. #if UNITY_EDITOR
  760.         public MaterialInputField()
  761.         {
  762.             EditorUpdate.Init();
  763.             EditorUpdate.onEditorUpdate += OnEditorUpdate;
  764.         }
  765.  
  766.         private void OnEditorUpdate()
  767.         {
  768.             if (IsDestroyed())
  769.             {
  770.                 EditorUpdate.onEditorUpdate -= OnEditorUpdate;
  771.                 return;
  772.             }
  773.  
  774.             if (inputField == null)
  775.             {
  776.                 Debug.LogWarning("Please attach the InputField reference!");
  777.                 EditorUpdate.onEditorUpdate -= OnEditorUpdate;
  778.                 return;
  779.             }
  780.  
  781.             if (m_LastSize != m_LayoutSize)
  782.             {
  783.                 m_LastSize = m_LayoutSize;
  784.                 SetLayoutDirty();
  785.             }
  786.  
  787.             if (m_LastRectPosition != rectTransform.anchoredPosition)
  788.             {
  789.                 m_LastRectPosition = rectTransform.anchoredPosition;
  790.                 SetLayoutDirty();
  791.  
  792.                 if (!Application.isPlaying)
  793.                 {
  794.                     EditorUtility.SetDirty(gameObject);
  795.                 }
  796.             }
  797.             if (m_LastRectSize != rectTransform.sizeDelta)
  798.             {
  799.                 m_LastRectSize = rectTransform.sizeDelta;
  800.                 SetLayoutDirty();
  801.  
  802.                 if (!Application.isPlaying)
  803.                 {
  804.                     EditorUtility.SetDirty(gameObject);
  805.                 }
  806.             }
  807.             UpdateCounter();
  808.             CheckHintText();
  809.         }
  810. #endif
  811.  
  812.         protected override void OnEnable()
  813.         {
  814.             UpdateSelectionState();
  815.             OnTextChanged();
  816.             CheckHintText();
  817.             SetLayoutDirty();
  818.         }
  819.  
  820.         protected override void OnDisable()
  821.         {
  822.             UpdateSelectionState();
  823.             OnTextChanged();
  824.             CheckHintText();
  825.             SetLayoutDirty();
  826.         }
  827.  
  828.         protected override void OnRectTransformDimensionsChange()
  829.         {
  830.             SetLayoutDirty();
  831.  
  832. #if UNITY_EDITOR
  833.             if (!Application.isPlaying)
  834.             {
  835.                 EditorUtility.SetDirty(gameObject);
  836.             }
  837. #endif
  838.         }
  839.  
  840.         protected override void OnDidApplyAnimationProperties()
  841.         {
  842.             UpdateSelectionState();
  843.             OnTextChanged();
  844.             CheckHintText();
  845.             SetLayoutDirty();
  846.         }
  847.  
  848. #if UNITY_EDITOR
  849.         protected override void OnValidate()
  850.         {
  851.             UpdateSelectionState();
  852.             OnTextChanged();
  853.             SetLayoutDirty();
  854.  
  855.             if (hintTextObject)
  856.             {
  857.                 if (m_HintText != hintTextObject.text)
  858.                 {
  859.                     if (m_LastHintText != hintText)
  860.                     {
  861.                         hintTextObject.text = m_HintText;
  862.                         m_LastHintText = m_HintText;
  863.                     }
  864.                 }
  865.             }
  866.  
  867.             if (m_LeftContentGraphic)
  868.             {
  869.                 m_LeftContentGraphic.color = IsSelected()
  870.                     ? m_LeftContentActiveColor
  871.                     : m_LeftContentInactiveColor;
  872.             }
  873.  
  874.             if (m_RightContentGraphic)
  875.             {
  876.                 m_RightContentGraphic.color = IsSelected()
  877.                     ? m_RightContentActiveColor
  878.                     : m_RightContentInactiveColor;
  879.             }
  880.  
  881.             if (m_HasCharacterCounter != m_LastCounterState)
  882.             {
  883.                 m_LastCounterState = m_HasCharacterCounter;
  884.                 m_CounterText.gameObject.SetActive(m_LastCounterState);
  885.             }
  886.  
  887.             m_HintTextObject.color = IsSelected() ? m_HintTextActiveColor : m_HintTextInactiveColor;
  888.  
  889.             if (m_CounterText != null)
  890.             {
  891.                 m_CounterText.color = IsSelected() ? m_CounterActiveColor : m_CounterInactiveColor;
  892.             }
  893.  
  894.             if (m_ValidationText != null)
  895.             {
  896.                 m_ValidationText.color = IsSelected() ? m_ValidationActiveColor : m_ValidationInactiveColor;
  897.             }
  898.  
  899.             m_LineTransform.GetComponent<Graphic>().color = m_LineInactiveColor;
  900.             m_ActiveLineTransform.GetComponent<Graphic>().color = m_LineActiveColor;
  901.  
  902.             canvasGroup.alpha = inputField.interactable ? 1 : 0.5f;
  903.             canvasGroup.interactable = inputField.interactable;
  904.             canvasGroup.blocksRaycasts = inputField.interactable;
  905.         }
  906. #endif
  907.  
  908.         protected override void Start()
  909.         {
  910.             UpdateSelectionState();
  911.             OnTextChanged();
  912.             CheckHintText();
  913.             SetLayoutDirty();
  914.         }
  915.  
  916.         void Update()
  917.         {
  918.             if (Application.isPlaying)
  919.             {
  920.                 if (inputField.isFocused)
  921.                 {
  922.                     m_LastFocussedState = true;
  923.                 }
  924.                 else
  925.                 {
  926.                     if (m_LastFocussedState)
  927.                     {
  928.                         m_LastFocussedState = false;
  929.                         OnDeselect(new PointerEventData(EventSystem.current));
  930.                     }
  931.                 }
  932.  
  933.                 UpdateSelectionState();
  934.                 CheckHintText();
  935.  
  936.                 if (m_AnimateHintText)
  937.                 {
  938.                     SetHintLayoutToFloatingValue();
  939.                 }
  940.             }
  941.         }
  942.  
  943.         public void ClearText()
  944.         {
  945.             inputField.text = "";
  946.             OnTextChanged();
  947.             SetLayoutDirty();
  948.         }
  949.  
  950.         public void OnTextChanged()
  951.         {
  952.             UpdateCounter();
  953.             ValidateText();
  954.         }
  955.  
  956.         private void CheckHintText()
  957.         {
  958.             if (hintTextObject == null) return;
  959.  
  960.             if (m_HintText != hintTextObject.text)
  961.             {
  962.                 m_HintText = hintTextObject.text;
  963.  
  964. #if UNITY_EDITOR
  965.                 m_LastHintText = m_HintText;
  966. #endif
  967.             }
  968.         }
  969.  
  970.         private void ValidateText()
  971.         {
  972.             if (validationText == null) return;
  973.  
  974.             if (!m_ValidateOnStart && !m_HasBeenSelected) return;
  975.  
  976.             m_ValidationText.color = IsSelected() ? m_ValidationActiveColor : m_ValidationInactiveColor;
  977.  
  978.             ITextValidator validator = null;
  979.             if (m_TextValidator != null && m_TextValidator.GetComponent<ITextValidator>() != null)
  980.             {
  981.                 validator = m_TextValidator.GetComponent<ITextValidator>();
  982.                 validator.Init(this);
  983.             }
  984.  
  985.             if (m_CustomTextValidator != null)
  986.             {
  987.                 validator = customTextValidator;
  988.                 m_HasValidation = true;
  989.             }
  990.  
  991.             if (validator != null && m_HasValidation)
  992.             {
  993.                 TweenManager.EndTween(m_ValidationTweener);
  994.  
  995.                 if (!validator.IsTextValid())
  996.                 {
  997.                     if (Application.isPlaying)
  998.                     {
  999.                         validationCanvasGroup.gameObject.SetActive(true);
  1000.                         validationCanvasGroup.interactable = true;
  1001.                         validationCanvasGroup.blocksRaycasts = true;
  1002.  
  1003.                         m_ValidationTweener = TweenManager.TweenFloat(f => validationCanvasGroup.alpha = f, validationCanvasGroup.alpha, 1f, m_AnimationDuration / 2, tweenType: Tween.TweenType.Linear);
  1004.                         return;
  1005.                     }
  1006.                 }
  1007.                 else
  1008.                 {
  1009.                     if (Application.isPlaying)
  1010.                     {
  1011.                         m_ValidationTweener = TweenManager.TweenFloat(f => validationCanvasGroup.alpha = f, validationCanvasGroup.alpha, 0f, m_AnimationDuration / 2, 0, () =>
  1012.                         {
  1013.                             validationCanvasGroup.interactable = false;
  1014.                             validationCanvasGroup.blocksRaycasts = false;
  1015.                             validationCanvasGroup.gameObject.SetActive(false);
  1016.                         }, false, Tween.TweenType.Linear);
  1017.                         return;
  1018.                     }
  1019.                 }
  1020.             }
  1021.  
  1022.             validationCanvasGroup.alpha = 0;
  1023.             validationCanvasGroup.interactable = false;
  1024.             validationCanvasGroup.blocksRaycasts = false;
  1025.             validationCanvasGroup.gameObject.SetActive(false);
  1026.         }
  1027.  
  1028.         private void UpdateCounter()
  1029.         {
  1030.             if (counterText == null)
  1031.             {
  1032.                 return;
  1033.             }
  1034.  
  1035.             int limit = m_MatchInputFieldCharacterLimit ? inputField.characterLimit : m_CharacterLimit;
  1036.  
  1037.             string outOf = limit > 0 ? " / " + limit : "";
  1038.  
  1039.             counterText.text = inputField.text.Length + outOf;
  1040.         }
  1041.  
  1042.         private void UpdateSelectionState()
  1043.         {
  1044.             if (m_Interactable)
  1045.             {
  1046.                 m_CurrentSelectionState = inputField.isFocused ? ColorSelectionState.EnabledSelected : ColorSelectionState.EnabledDeselected;
  1047.  
  1048.                 if (lineImage != null)
  1049.                 {
  1050.                     lineImage.sprite = null;
  1051.                 }
  1052.             }
  1053.             else
  1054.             {
  1055.                 m_CurrentSelectionState = inputField.isFocused ? ColorSelectionState.DisabledSelected : ColorSelectionState.DisabledDeselected;
  1056.  
  1057.                 if (lineImage != null)
  1058.                 {
  1059.                     lineImage.sprite = lineDisabledSprite;
  1060.                     lineImage.type = Image.Type.Tiled;
  1061.                 }
  1062.             }
  1063.  
  1064.             if (m_CurrentSelectionState != m_LastSelectionState)
  1065.             {
  1066.                 m_LastSelectionState = m_CurrentSelectionState;
  1067.  
  1068.                 TweenManager.EndTween(m_LeftContentTweener);
  1069.  
  1070.                 if (Application.isPlaying)
  1071.                 {
  1072.                     if (m_LeftContentGraphic)
  1073.                     {
  1074.                         m_LeftContentTweener = TweenManager.TweenColor(color => m_LeftContentGraphic.color = color,
  1075.                             m_LeftContentGraphic.color,
  1076.                             IsSelected() ? m_LeftContentActiveColor : m_LeftContentInactiveColor, m_AnimationDuration);
  1077.                     }
  1078.                 }
  1079.                 else
  1080.                 {
  1081.                     if (m_LeftContentGraphic)
  1082.                     {
  1083.                         m_LeftContentGraphic.color = IsSelected()
  1084.                             ? m_LeftContentActiveColor
  1085.                             : m_LeftContentInactiveColor;
  1086.                     }
  1087.                 }
  1088.  
  1089.                 TweenManager.EndTween(m_RightContentTweener);
  1090.  
  1091.                 if (Application.isPlaying)
  1092.                 {
  1093.                     if (m_RightContentGraphic)
  1094.                     {
  1095.                         m_RightContentTweener = TweenManager.TweenColor(color => m_RightContentGraphic.color = color,
  1096.                             m_RightContentGraphic.color,
  1097.                             IsSelected() ? m_RightContentActiveColor : m_RightContentInactiveColor, m_AnimationDuration);
  1098.                     }
  1099.                 }
  1100.                 else
  1101.                 {
  1102.                     if (m_RightContentGraphic)
  1103.                     {
  1104.                         m_RightContentGraphic.color = IsSelected()
  1105.                             ? m_RightContentActiveColor
  1106.                             : m_RightContentInactiveColor;
  1107.                     }
  1108.                 }
  1109.  
  1110.                 TweenManager.EndTween(m_HintTextTweener);
  1111.  
  1112.                 if (Application.isPlaying)
  1113.                 {
  1114.                     m_HintTextTweener = TweenManager.TweenColor(color => m_HintTextObject.color = color,
  1115.                         m_HintTextObject.color, IsSelected() ? m_HintTextActiveColor : m_HintTextInactiveColor,
  1116.                         m_AnimationDuration);
  1117.                 }
  1118.                 else
  1119.                 {
  1120.                     m_HintTextObject.color = IsSelected() ? m_HintTextActiveColor : m_HintTextInactiveColor;
  1121.                 }
  1122.  
  1123.                 TweenManager.EndTween(m_CounterTweener);
  1124.  
  1125.                 if (m_CounterText != null)
  1126.                 {
  1127.                     if (Application.isPlaying)
  1128.                     {
  1129.                         m_CounterTweener = TweenManager.TweenColor(color => m_CounterText.color = color,
  1130.                         m_CounterText.color, IsSelected() ? m_CounterActiveColor : m_CounterInactiveColor,
  1131.                         m_AnimationDuration);
  1132.                     }
  1133.                     else
  1134.                     {
  1135.                         m_CounterText.color = IsSelected() ? m_CounterActiveColor : m_CounterInactiveColor;
  1136.                     }
  1137.                 }
  1138.                 TweenManager.EndTween(m_ValidationColorTweener);
  1139.  
  1140.                 if (m_ValidationText != null)
  1141.                 {
  1142.                     if (Application.isPlaying)
  1143.                     {
  1144.  
  1145.                         m_ValidationColorTweener = TweenManager.TweenColor(color => m_ValidationText.color = color,
  1146.                             m_ValidationText.color, IsSelected() ? m_ValidationActiveColor : m_ValidationInactiveColor,
  1147.                             m_AnimationDuration);
  1148.                     }
  1149.                     else
  1150.                     {
  1151.                         m_ValidationText.color = IsSelected() ? m_ValidationActiveColor : m_ValidationInactiveColor;
  1152.                     }
  1153.                 }
  1154.  
  1155.                 m_LineTransform.GetComponent<Graphic>().color = m_LineInactiveColor;
  1156.                 m_ActiveLineTransform.GetComponent<Graphic>().color = m_LineActiveColor;
  1157.  
  1158.                 canvasGroup.alpha = m_Interactable ? 1 : 0.5f;
  1159.                 canvasGroup.interactable = m_Interactable;
  1160.                 canvasGroup.blocksRaycasts = m_Interactable;
  1161.             }
  1162.         }
  1163.  
  1164.         private bool IsSelected()
  1165.         {
  1166.             return m_CurrentSelectionState == ColorSelectionState.DisabledSelected ||
  1167.                    m_CurrentSelectionState == ColorSelectionState.EnabledSelected;
  1168.         }
  1169.  
  1170.         private float GetTextHeight()
  1171.         {
  1172.             string layoutText = inputField.text;
  1173.             Vector2 generationSize = new Vector2();
  1174.  
  1175.             if (inputField.lineType == InputField.LineType.SingleLine)
  1176.             {
  1177.                 generationSize = new Vector2(float.MaxValue, float.MaxValue);
  1178.                 layoutText = layoutText.Replace("\n", "");
  1179.             }
  1180.             else
  1181.             {
  1182.                 generationSize = new Vector2(inputText.rectTransform.rect.width, float.MaxValue);
  1183.             }
  1184.  
  1185.             TextGenerator textGenerator = inputText.cachedTextGeneratorForLayout;
  1186.             TextGenerationSettings textGenerationSettings = inputText.GetGenerationSettings(generationSize);
  1187.  
  1188.             if (materialUiScaler == null)
  1189.             {
  1190.                 Debug.LogError("Must have a MaterialUIScaler atached to root canvas");
  1191.                 return 0;
  1192.             }
  1193.  
  1194.             return textGenerator.GetPreferredHeight(layoutText, textGenerationSettings) / materialUiScaler.scaleFactor;
  1195.         }
  1196.  
  1197.         private float GetSmallHintTextHeight()
  1198.         {
  1199.             if (hintTextObject == null)
  1200.             {
  1201.                 return 0;
  1202.             }
  1203.  
  1204.             if (materialUiScaler == null)
  1205.             {
  1206.                 return 0;
  1207.             }
  1208.  
  1209.             TextGenerator textGenerator = hintTextObject.cachedTextGeneratorForLayout;
  1210.             TextGenerationSettings textGenerationSettings = inputText.GetGenerationSettings(new Vector2(float.MaxValue, float.MaxValue));
  1211.             textGenerationSettings.fontSize = m_FloatingHintFontSize;
  1212.             return textGenerator.GetPreferredHeight(hintTextObject.text, textGenerationSettings) / materialUiScaler.scaleFactor;
  1213.         }
  1214.  
  1215.         public void OnSelect(BaseEventData eventData)
  1216.         {
  1217.             m_HasBeenSelected = true;
  1218.  
  1219.             AnimateActiveLineSelect();
  1220.             AnimateHintTextSelect();
  1221.             UpdateSelectionState();
  1222.  
  1223.             ValidateText();
  1224.         }
  1225.  
  1226.         public void OnDeselect(BaseEventData eventData)
  1227.         {
  1228.             AnimateActiveLineDeselect();
  1229.             AnimateHintTextDeselect();
  1230.             UpdateSelectionState();
  1231.         }
  1232.  
  1233.         private void AnimateHintTextSelect()
  1234.         {
  1235.             CancelHintTextTweeners();
  1236.  
  1237.             m_HintTextFloatingValueTweener = TweenManager.TweenFloat(f => hintTextFloatingValue = f, hintTextFloatingValue, 1f, m_AnimationDuration, 0, () =>
  1238.             {
  1239.                 m_AnimateHintText = false;
  1240.                 SetHintLayoutToFloatingValue();
  1241.             });
  1242.             m_AnimateHintText = true;
  1243.         }
  1244.  
  1245.         private void AnimateHintTextDeselect()
  1246.         {
  1247.             CancelHintTextTweeners();
  1248.  
  1249.             if (!inputField.isFocused && inputField.text.Length == 0)
  1250.             {
  1251.                 m_HintTextFloatingValueTweener = TweenManager.TweenFloat(f => hintTextFloatingValue = f,
  1252.                     () => hintTextFloatingValue, 0f, m_AnimationDuration, 0f, () =>
  1253.                     {
  1254.                         m_AnimateHintText = false;
  1255.                         SetHintLayoutToFloatingValue();
  1256.                     });
  1257.                 m_AnimateHintText = true;
  1258.             }
  1259.         }
  1260.  
  1261.         private void AnimateActiveLineSelect(bool instant = false)
  1262.         {
  1263.             CancelActivelineTweeners();
  1264.  
  1265.             if (m_LineTransform == null || m_ActiveLineTransform == null) return;
  1266.  
  1267.             if (instant)
  1268.             {
  1269.                 m_ActiveLineTransform.anchoredPosition = Vector2.zero;
  1270.                 m_ActiveLineTransform.sizeDelta = new Vector2(m_LineTransform.GetProperSize().x, m_ActiveLineTransform.sizeDelta.y);
  1271.                 activeLineCanvasGroup.alpha = 1;
  1272.             }
  1273.             else
  1274.             {
  1275.                 float lineLength = m_LineTransform.GetProperSize().x;
  1276.  
  1277.                 m_ActiveLineTransform.sizeDelta = new Vector2(0, m_ActiveLineTransform.sizeDelta.y);
  1278.                 m_ActiveLineTransform.position = Input.mousePosition;
  1279.                 m_ActiveLineTransform.anchoredPosition = new Vector2(Mathf.Clamp(m_ActiveLineTransform.anchoredPosition.x, -lineLength / 2, lineLength / 2), 0);
  1280.                 activeLineCanvasGroup.alpha = 1;
  1281.  
  1282.                 m_ActiveLinePosTweener = TweenManager.TweenFloat(f => m_ActiveLineTransform.anchoredPosition = new Vector2(f, m_ActiveLineTransform.anchoredPosition.y), m_ActiveLineTransform.anchoredPosition.x, 0f, m_AnimationDuration * 2);
  1283.  
  1284.                 m_ActiveLineSizeTweener = TweenManager.TweenFloat(f => m_ActiveLineTransform.sizeDelta = new Vector2(f, m_ActiveLineTransform.sizeDelta.y), m_ActiveLineTransform.sizeDelta.x, m_LineTransform.GetProperSize().x, m_AnimationDuration * 2);
  1285.             }
  1286.         }
  1287.  
  1288.         private void AnimateActiveLineDeselect(bool instant = false)
  1289.         {
  1290.             CancelActivelineTweeners();
  1291.  
  1292.             if (activeLineTransform == null) return;
  1293.  
  1294.             if (instant)
  1295.             {
  1296.                 activeLineCanvasGroup.alpha = 0;
  1297.             }
  1298.             else
  1299.             {
  1300.                 activeLineCanvasGroup.alpha = 1;
  1301.  
  1302.                 m_ActiveLineAlphaTweener = TweenManager.TweenFloat(f => activeLineCanvasGroup.alpha = f, activeLineCanvasGroup.alpha, 0f, m_AnimationDuration * 2);
  1303.             }
  1304.         }
  1305.  
  1306.         private void CancelHintTextTweeners()
  1307.         {
  1308.             TweenManager.EndTween(m_HintTextFloatingValueTweener);
  1309.             m_AnimateHintText = false;
  1310.         }
  1311.  
  1312.         private void CancelActivelineTweeners()
  1313.         {
  1314.             TweenManager.EndTween(m_ActiveLineSizeTweener);
  1315.             TweenManager.EndTween(m_ActiveLinePosTweener);
  1316.             TweenManager.EndTween(m_ActiveLineAlphaTweener);
  1317.         }
  1318.  
  1319.         private void SetHintLayoutToFloatingValue()
  1320.         {
  1321.             if (m_HintTextTransform == null) return;
  1322.  
  1323.             if (m_FloatingHint)
  1324.             {
  1325.                 m_HintTextTransform.offsetMin = new Vector2(m_LeftSectionWidth, m_BottomSectionHeight);
  1326.                 m_HintTextTransform.offsetMax = new Vector2(-m_RightSectionWidth, -Tween.Linear(m_TopSectionHeight, 0, hintTextFloatingValue, 1));
  1327.                 hintTextObject.fontSize = Mathf.RoundToInt(Tween.Linear(inputText.fontSize, m_FloatingHintFontSize, hintTextFloatingValue, 1));
  1328.  
  1329.                 float realFontSize = Tween.Linear(inputText.fontSize, m_FloatingHintFontSize, hintTextFloatingValue, 1);
  1330.  
  1331.                 float scaleFactor = realFontSize / hintTextObject.fontSize;
  1332.  
  1333.                 m_HintTextTransform.localScale = new Vector3(scaleFactor, scaleFactor, scaleFactor);
  1334.                 hintTextCanvasGroup.alpha = 1;
  1335.             }
  1336.             else
  1337.             {
  1338.                 m_HintTextTransform.offsetMin = new Vector2(m_LeftSectionWidth, m_BottomSectionHeight);
  1339.                 m_HintTextTransform.offsetMax = new Vector2(-m_RightSectionWidth, 0);
  1340.                 hintTextObject.fontSize = inputText.fontSize;
  1341.                 m_HintTextTransform.localScale = Vector3.one;
  1342.  
  1343.                 hintTextCanvasGroup.alpha = 1 - hintTextFloatingValue;
  1344.             }
  1345.         }
  1346.  
  1347.         #region Layout
  1348.  
  1349.         public void SetLayoutDirty()
  1350.         {
  1351.             LayoutRebuilder.MarkLayoutForRebuild(rectTransform);
  1352.         }
  1353.  
  1354.         public void SetLayoutHorizontal()
  1355.         {
  1356.             if (!TweenManager.TweenIsActive(m_HintTextFloatingValueTweener))
  1357.             {
  1358.                 hintTextFloatingValue = (inputField.isFocused || inputField.text.Length > 0) ? 1 : 0;
  1359.                 SetHintLayoutToFloatingValue();
  1360.             }
  1361.  
  1362.             inputTextTransform.offsetMin = new Vector2(m_LeftSectionWidth, inputTextTransform.offsetMin.y);
  1363.             inputTextTransform.offsetMax = new Vector2(-m_RightSectionWidth, inputTextTransform.offsetMax.y);
  1364.  
  1365.             if (m_LineTransform != null)
  1366.             {
  1367.                 m_LineTransform.offsetMin = new Vector2(m_LeftSectionWidth, m_LineTransform.offsetMin.y);
  1368.                 m_LineTransform.offsetMax = new Vector2(-m_RightSectionWidth, m_LineTransform.offsetMax.y);
  1369.             }
  1370.  
  1371.             if (m_ValidationTextTransform != null)
  1372.             {
  1373.                 m_ValidationTextTransform.offsetMin = new Vector2(m_LeftSectionWidth,
  1374.                     m_ValidationTextTransform.offsetMin.y);
  1375.                 m_ValidationTextTransform.offsetMax = new Vector2(-m_RightSectionWidth,
  1376.                     m_ValidationTextTransform.offsetMax.y);
  1377.             }
  1378.  
  1379.             if (m_CounterTextTransform != null)
  1380.             {
  1381.                 m_CounterTextTransform.offsetMin = new Vector2(m_LeftSectionWidth, m_CounterTextTransform.offsetMin.y);
  1382.                 m_CounterTextTransform.offsetMax = new Vector2(-m_RightSectionWidth, m_CounterTextTransform.offsetMax.y);
  1383.             }
  1384.  
  1385.             if (caretTransform != null)
  1386.             {
  1387.                 caretTransform.offsetMin = new Vector2(inputTextTransform.offsetMin.x, caretTransform.offsetMin.y);
  1388.                 caretTransform.offsetMax = new Vector2(inputTextTransform.offsetMax.x, caretTransform.offsetMax.y);
  1389.             }
  1390.         }
  1391.  
  1392.         public void SetLayoutVertical()
  1393.         {
  1394.             inputTextTransform.offsetMax = new Vector2(inputTextTransform.offsetMax.x, -m_TopSectionHeight);
  1395.  
  1396.             if (!TweenManager.TweenIsActive(m_HintTextFloatingValueTweener))
  1397.             {
  1398.                 hintTextFloatingValue = (inputField.isFocused || inputField.text.Length > 0) ? 1 : 0;
  1399.                 SetHintLayoutToFloatingValue();
  1400.             }
  1401.  
  1402.             if (m_LeftContentTransform)
  1403.             {
  1404.                 ILayoutController[] controllers = m_LeftContentTransform.GetComponentsInChildren<ILayoutController>();
  1405.                 for (int i = 0; i < controllers.Length; i++)
  1406.                 {
  1407.                     controllers[i].SetLayoutVertical();
  1408.                 }
  1409.  
  1410.                 m_LeftContentTransform.anchoredPosition = new Vector2(m_LeftContentOffset.x, (inputTextTransform.offsetMax.y - (m_InputText.fontSize / 2) - 2) + m_LeftContentOffset.y);
  1411.             }
  1412.  
  1413.             if (m_RightContentTransform)
  1414.             {
  1415.                 ILayoutController[] controllers = m_RightContentTransform.GetComponentsInChildren<ILayoutController>();
  1416.                 for (int i = 0; i < controllers.Length; i++)
  1417.                 {
  1418.                     controllers[i].SetLayoutVertical();
  1419.                 }
  1420.  
  1421.                 m_RightContentTransform.anchoredPosition = new Vector2(m_RightContentOffset.x, (inputTextTransform.offsetMax.y - (m_InputText.fontSize / 2) - 2) + m_RightContentOffset.y);
  1422.             }
  1423.  
  1424.             if (m_LineTransform != null)
  1425.             {
  1426.                 m_LineTransform.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Bottom, m_BottomSectionHeight, 1);
  1427.             }
  1428.  
  1429.             if (caretTransform != null)
  1430.             {
  1431.                 caretTransform.offsetMin = new Vector2(caretTransform.offsetMin.x, inputTextTransform.offsetMin.y);
  1432.                 caretTransform.offsetMax = new Vector2(caretTransform.offsetMax.x, inputTextTransform.offsetMax.y);
  1433.             }
  1434.         }
  1435.  
  1436.         public void CalculateLayoutInputHorizontal()
  1437.         {
  1438.             m_LayoutSize.x = m_ManualPreferredWidth ? m_ManualSize.x : -1;
  1439.  
  1440.             m_LeftSectionWidth = 0;
  1441.             m_RightSectionWidth = 0;
  1442.  
  1443.             if (m_LeftContentTransform != null)
  1444.             {
  1445.                 if (m_LeftContentTransform.gameObject.activeSelf)
  1446.                 {
  1447.                     m_LeftSectionWidth = m_LeftContentTransform.GetProperSize().x;
  1448.                     m_LeftSectionWidth += 8;
  1449.                 }
  1450.             }
  1451.  
  1452.             if (m_RightContentTransform != null)
  1453.             {
  1454.                 if (m_RightContentTransform.gameObject.activeSelf)
  1455.                 {
  1456.                     m_RightSectionWidth = m_RightContentTransform.GetProperSize().x;
  1457.                     m_RightSectionWidth += 8;
  1458.                 }
  1459.             }
  1460.         }
  1461.  
  1462.         public void CalculateLayoutInputVertical()
  1463.         {
  1464.             if (m_FloatingHint)
  1465.             {
  1466.                 m_TopSectionHeight = GetSmallHintTextHeight();
  1467.                 m_TopSectionHeight += 4;
  1468.             }
  1469.             else
  1470.             {
  1471.                 m_TopSectionHeight = 0;
  1472.             }
  1473.  
  1474.             if (m_HasCharacterCounter || m_HasValidation)
  1475.             {
  1476.                 m_BottomSectionHeight = 0;
  1477.  
  1478.                 if (m_HasCharacterCounter && counterText != null)
  1479.                 {
  1480.                     m_BottomSectionHeight = counterText.preferredHeight;
  1481.                 }
  1482.                 else if (m_HasValidation && validationText != null)
  1483.                 {
  1484.                     m_BottomSectionHeight = validationText.preferredHeight;
  1485.                 }
  1486.  
  1487.                 m_BottomSectionHeight += 4;
  1488.             }
  1489.             else
  1490.             {
  1491.                 m_BottomSectionHeight = 0;
  1492.             }
  1493.  
  1494.             if (m_FitHeightToContent)
  1495.             {
  1496.                 m_LayoutSize.y = GetTextHeight() + 4;
  1497.                 m_LayoutSize.y += m_TopSectionHeight;
  1498.                 m_LayoutSize.y += m_BottomSectionHeight;
  1499.             }
  1500.             else
  1501.             {
  1502.                 m_LayoutSize.y = m_ManualPreferredHeight ? m_ManualSize.y : -1;
  1503.             }
  1504.  
  1505.             if (m_LeftContentTransform)
  1506.             {
  1507.                 ILayoutElement[] elements = m_LeftContentTransform.GetComponentsInChildren<ILayoutElement>();
  1508.                 elements = elements.Reverse().ToArray();
  1509.                 for (int i = 0; i < elements.Length; i++)
  1510.                 {
  1511.                     elements[i].CalculateLayoutInputVertical();
  1512.                 }
  1513.             }
  1514.  
  1515.             if (m_RightContentTransform)
  1516.             {
  1517.                 ILayoutElement[] elements = m_RightContentTransform.GetComponentsInChildren<ILayoutElement>();
  1518.                 elements = elements.Reverse().ToArray();
  1519.                 for (int i = 0; i < elements.Length; i++)
  1520.                 {
  1521.                     elements[i].CalculateLayoutInputVertical();
  1522.                 }
  1523.             }
  1524.         }
  1525.  
  1526.         public float minWidth { get { return -1; } }
  1527.         public float preferredWidth { get { return m_LayoutSize.x; } }
  1528.         public float flexibleWidth { get { return -1; } }
  1529.         public float minHeight { get { return -1; } }
  1530.         public float preferredHeight { get { return m_LayoutSize.y; } }
  1531.         public float flexibleHeight { get { return -1; } }
  1532.         public int layoutPriority { get { return 1; } }
  1533.  
  1534.         #endregion
  1535.     }
  1536. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement