private void OnChangeActiveStateComponent(ComponentActor beh, bool state) { var hash = beh.GetHashCode(); if (_components.ContainsKey(hash)) { var data = _components[hash]; if (state) { if (data.tick != null && !_ticks.Contains(data.tick)) { _ticks.Add(data.tick); _countTicks++; } if (data.tickFixed != null && !_ticksFixed.Contains(data.tickFixed)) { _ticksFixed.Add(data.tickFixed); _countTicksFixed++; } if (data.tickLate != null && !_ticksLate.Contains(data.tickLate)) { _ticksLate.Add(data.tickLate); _countTicksLate++; } } else { if (data.tick != null) { _ticks.Remove(data.tick); _countTicks--; } if (data.tickFixed != null) { _ticksFixed.Remove(data.tickFixed); _countTicksFixed--; } if (data.tickLate != null) { _ticksLate.Remove(data.tickLate); _countTicksLate--; } } } else { LogSystem.Print(AlertLevel.Error, "System", $"Cell for {beh.GetType().Name}:{hash} not found"); } }
private ComponentActorMeta AddComponent(ComponentActor beh) { beh.onChangeActiveState -= OnChangeActiveStateComponent; beh.onChangeActiveState += OnChangeActiveStateComponent; var compData = new ComponentActorMeta(); compData.behaviour = beh; compData.component = beh; if (beh.enabled) { compData.tick = beh as ITick; compData.tickFixed = beh as ITickFixed; compData.tickLate = beh as ITickLate; if (compData.tick != null) { _ticks.Add(compData.tick); _countTicks++; } if (compData.tickFixed != null) { _ticksFixed.Add(compData.tickFixed); _countTicksFixed++; } if (compData.tickLate != null) { _ticksLate.Add(compData.tickLate); _countTicksLate++; } } _behaviours.Add(compData); _countBehaviours++; return(compData); }