StartFightCardItem.cs 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. using System;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. namespace ET.Client
  6. {
  7. public class StartFightCardItem : MonoBehaviour
  8. {
  9. public Image icon;
  10. public int val;
  11. public Action<int> cb;
  12. private bool isSelect = false;
  13. public bool IsSelect{ get => isSelect; set => isSelect = value; }
  14. public async void Init(Image icon,int val,Action<int> cb)
  15. {
  16. this.icon = icon;
  17. this.val = val;
  18. this.cb = cb;
  19. var sprite = await GameObjectPool.Instance.AcquireSprite(string.Concat(GameSetting.Instance.selfPlayCardSpiteName, this.val));
  20. this.icon.sprite = sprite;
  21. this.icon.gameObject.OnClick(() =>
  22. {
  23. if (isSelect)
  24. {
  25. GetDown();
  26. }
  27. else
  28. {
  29. StandUp();
  30. }
  31. });
  32. icon.gameObject.OnDoubleClick(() =>
  33. {
  34. this.cb?.Invoke(this.val);
  35. });
  36. }
  37. public void StandUp()
  38. {
  39. if (IsSelect)
  40. {
  41. return;
  42. }
  43. IsSelect = true;
  44. RectTransform rt = icon.gameObject.GetComponent<RectTransform>();
  45. rt.localPosition = new Vector3(rt.localPosition.x, rt.localPosition.y + 30, rt.localPosition.z);
  46. GameObjectPool.Instance.OperatoRarealySelCardList(0, this.val);
  47. }
  48. public void GetDown()
  49. {
  50. if (!IsSelect)
  51. return;
  52. IsSelect = false;
  53. RectTransform rt = icon.gameObject.GetComponent<RectTransform>();
  54. rt.localPosition = new Vector3(rt.localPosition.x, rt.localPosition.y - 30, rt.localPosition.z);
  55. GameObjectPool.Instance.OperatoRarealySelCardList(1, this.val);
  56. }
  57. }
  58. }