CapchaCheck.cs 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. using System;
  2. using UnityEngine;
  3. using System.Collections;
  4. using Random = UnityEngine.Random;
  5. public class CapchaCheck : MonoBehaviour {
  6. [SerializeField]
  7. private UISprite[] Symbol1;
  8. [SerializeField]
  9. private UISprite[] Symbol2;
  10. [SerializeField]
  11. private UISprite[] Symbol3;
  12. [SerializeField]
  13. private UISprite[] Symbol4;
  14. [SerializeField]
  15. private UIButton _refresh;
  16. private string _value;
  17. // Use this for initialization
  18. void Start ()
  19. {
  20. Refresh();
  21. _refresh.onClick.Add(new EventDelegate(Refresh));
  22. }
  23. public void Refresh()
  24. {
  25. _value = Random.Range(1000, 9999).ToString();
  26. for (int i = 0; i < _value.Length; i++)
  27. {
  28. Activate(i, Int32.Parse(_value[i].ToString()));
  29. }
  30. }
  31. private void Activate(int leter, int index)
  32. {
  33. UISprite[] arr = null;
  34. switch (leter)
  35. {
  36. case 0:
  37. arr = Symbol1;
  38. break;
  39. case 1:
  40. arr = Symbol2;
  41. break;
  42. case 2:
  43. arr = Symbol3;
  44. break;
  45. case 3:
  46. arr = Symbol4;
  47. break;
  48. }
  49. if (arr != null)
  50. {
  51. for (int i = 0; i < arr.Length; i++)
  52. {
  53. arr[i].gameObject.SetActive(i==index);
  54. }
  55. }
  56. }
  57. public bool Check(string capcha)
  58. {
  59. return _value.Equals(capcha.Trim());
  60. }
  61. private void OnEnable()
  62. {
  63. Refresh();
  64. }
  65. }