private void SendOnResourceAmountChangedEvent() { if (OnResourceAmountChanged != null) { OnResourceAmountChanged.Invoke(null, EventArgs.Empty); } }
public void AddResource(ResourceTypeSO resourceType, int amount) { _resourceAmountDictionary[resourceType] += amount; OnResourceAmountChanged?.Invoke(this, EventArgs.Empty); TestLogResourceAmountDictionary(); }
//更新对应的资源类数量 public void AddResource(ResourceTypeSO resourceType, int amount) { resourceAmountDictionary[resourceType] += amount; /* * 广播该事件,this 表示事件发送者 * 问号无条件运算符,判断OnResourceAmountChanged 事件是否为null,不为null将其触发 * Invoke 事件重复调用 */ OnResourceAmountChanged?.Invoke(this, EventArgs.Empty); }
public void AddResource(ResourceTypeSO resourceType, int amount) { if (resourceAmountDictionary[resourceType] >= 99) { Debug.Log(resourceType.nameString + " capacity is full"); } else { resourceAmountDictionary[resourceType] += amount; OnResourceAmountChanged?.Invoke(this, EventArgs.Empty); TestLogResourceAmountDictionary(); } }
public void AddResource(ResourceTypeSO resourceType, int amount) { resourceAmountDictionary[resourceType] += amount; //use ?.Invoke to check the field before it, and only going to run when its not null -> has listner /* * if(OnResourceAmountChanged != null) * { * OnResourceAmountChanged(this, EventArgs.Empty); * } */ OnResourceAmountChanged?.Invoke(this, EventArgs.Empty); //event handeler signature :: take obj center and an opitinal arg, we use EventArgs.Empty becuase we not want to send any extra info.. //TestLogResourceAmountDictionary(); }
public void AddResource(ResourceTypeSO resourceType, int amount) { resourceAmountDictionary[resourceType] += amount; // ? means if not null, so if object isnt null, then run (is null if no listerners to event) OnResourceAmountChanged?.Invoke(this, EventArgs.Empty); }
public void AddResource(ResourceTypeSO resourceType, int amount) { resourceAmoutDic[resourceType] += amount; OnResourceAmountChanged?.Invoke(this, EventArgs.Empty); }