StartFightCardItem.cs 2.2 KB

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