DressUpRemoveOperation.cs 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. using System;
  2. using UnityEngine;
  3. using YooAsset;
  4. using static FairyGUI.ControllerAction;
  5. namespace GFGGame
  6. {
  7. //换装部件移除行为的操作器,负责缓存一个移除行为,有可能在后续的逻辑中被覆盖或取消
  8. public class DressUpRemoveOperation : DressUpOperationBase
  9. {
  10. internal int itemID;
  11. internal GameObject parentObj;
  12. public DressUpRemoveOperation(int itemID, GameObject parentObj)
  13. {
  14. this.itemID = itemID;
  15. this.parentObj = parentObj;
  16. //LogUtil.LogEditor($"remove init {itemID}");
  17. }
  18. internal override void Release()
  19. {
  20. this.parentObj = null;
  21. }
  22. internal override void Start()
  23. {
  24. Status = EOperationStatus.Succeed;
  25. }
  26. internal override void Update()
  27. {
  28. }
  29. internal override void Cancel()
  30. {
  31. Status = EOperationStatus.Failed;
  32. Error = "User cancel.";
  33. }
  34. internal override bool CheckRepeated(DressUpOperationBase t)
  35. {
  36. DressUpLayerOperation layerOperation = t as DressUpLayerOperation;
  37. if (layerOperation != null && layerOperation.actionType == DressUpLayerOperation.EAction.Layer)
  38. {
  39. return (layerOperation.itemCfg != null
  40. && this.itemID == layerOperation.itemCfg.Id
  41. && this.parentObj == layerOperation.parentObj);
  42. }
  43. var removeOperation = t as DressUpRemoveOperation;
  44. return (removeOperation != null
  45. && removeOperation.itemID == this.itemID
  46. && removeOperation.parentObj == this.parentObj);
  47. }
  48. internal override void UpdateView(Action action = null)
  49. {
  50. if(parentObj == null)
  51. {
  52. this.Release();
  53. return;
  54. }
  55. //LogUtil.LogEditor($"remove UpdateView {itemID}");
  56. DressUpUtil.RemoveItem(this.itemID, this.parentObj);
  57. action?.Invoke();
  58. }
  59. }
  60. }