StartFightCardItem.cs 2.2 KB

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