StartFightCardItem.cs 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. Log.Error("@@@@@。。。放下");
  26. GetDown();
  27. }
  28. else
  29. {
  30. Log.Error("@@@@@。。。抬起");
  31. StandUp();
  32. }
  33. });
  34. icon.gameObject.OnDoubleClick(() =>
  35. {
  36. Log.Error("@@@@@。。。出牌");
  37. this.cb?.Invoke(this.val);
  38. });
  39. }
  40. public void StandUp()
  41. {
  42. if (IsSelect)
  43. {
  44. return;
  45. }
  46. IsSelect = true;
  47. RectTransform rt = icon.gameObject.GetComponent<RectTransform>();
  48. rt.localPosition = new Vector3(rt.localPosition.x, rt.localPosition.y + 30, rt.localPosition.z);
  49. GameObjectPool.Instance.OperatoRarealySelCardList(0, this.val);
  50. }
  51. public void GetDown()
  52. {
  53. if (!IsSelect)
  54. return;
  55. IsSelect = false;
  56. RectTransform rt = icon.gameObject.GetComponent<RectTransform>();
  57. rt.localPosition = new Vector3(rt.localPosition.x, rt.localPosition.y - 30, rt.localPosition.z);
  58. GameObjectPool.Instance.OperatoRarealySelCardList(1, this.val);
  59. }
  60. }
  61. }