protected override void OnUpdate() { float deltaTime = Time.DeltaTime; var ecb = _endSimulationEcbSystem.CreateCommandBuffer().AsParallelWriter(); Entities .WithName("RestManagementSystem") .WithAll <RestDefaultSystemTag>() .ForEach((ref RestState state, in RestData data) => { //calculate current hunger state.Value += data.RestLps * deltaTime; }).ScheduleParallel(); var job2 = Entities .WithName("RestScoreSystem") .ForEach((Entity entity, int entityInQueryIndex, ref RestScore score, ref RestState state, ref CurrentBrainState currentState, in StateCompleteTag completeTag, in RestData data) => { if (completeTag.Progress == StateCompleteProgress.removingOldStateCurrentTag) { Debug.Log("Rest, removeing old tag"); if (currentState.State == BrainStates.Rest) { ecb.RemoveComponent <RestStateCurrent>(entityInQueryIndex, entity); } } else if (completeTag.Progress == StateCompleteProgress.loadingNewState) { if (currentState.State == BrainStates.Rest) { Debug.Log("Rest Hunger State"); ecb.AddComponent <RestStateCurrent>(entityInQueryIndex, entity); } } else if (completeTag.Progress == StateCompleteProgress.choosingNewState) { if (state.SkipNextStateSelection) { state.SkipNextStateSelection = false; score.Value = 0; } else if (state.Value < data.ValueThreshold) //if not hungry just return 0 { score.Value = 0; } else { score.Value = ScoreUtils.CalculateDefaultScore(state.Value); if (score.Value > currentState.Score) { currentState.Score = score.Value; currentState.State = BrainStates.Rest; } } } }).Schedule(Dependency);
protected override void OnUpdate() { float deltaTime = Time.DeltaTime; var ecb = _endSimulationEcbSystem.CreateCommandBuffer().AsParallelWriter(); Entities .WithName("ThirstrManagementSystem") .WithAll <ThirstDefaultSystemTag>() .ForEach((ref ThirstState state, in ThirstData data) => { //calculate current thirst state.Value += data.ThirstLps * deltaTime; }).Schedule(); var job2 = Entities .WithName("ThirstScoreSystem") .ForEach((Entity entity, int entityInQueryIndex, ref ThirstScore score, ref ThirstState state, ref CurrentBrainState currentState, in StateCompleteTag completeTag, in ThirstData data) => { if (completeTag.Progress == StateCompleteProgress.removingOldStateCurrentTag) { Debug.Log("Thirst, removeing old tag"); if (currentState.State == BrainStates.Drink) { ecb.RemoveComponent <ThirstStateCurrent>(entityInQueryIndex, entity); } } else if (completeTag.Progress == StateCompleteProgress.loadingNewState) { Debug.Log("Is it Thirst"); if (currentState.State == BrainStates.Drink) { Debug.Log("============ Loading Thirst State"); ecb.AddComponent <ThirstStateCurrent>(entityInQueryIndex, entity); } } else if (completeTag.Progress == StateCompleteProgress.choosingNewState) { if (state.SkipNextStateSelection) { state.SkipNextStateSelection = false; score.Value = 0; } else if (state.Value < data.ThirstThreshold) //if not hungry just return 0 { score.Value = 0; } else { score.Value = ScoreUtils.CalculateDefaultScore(state.Value); if (score.Value > currentState.Score) { currentState.Score = score.Value; currentState.State = BrainStates.Drink; } } Debug.Log($"Score Thirst::: {currentState.Score}, {currentState.State}"); } //calculate current thirst Debug.Log("Updated thirstScore"); if (state.SkipNextStateSelection) { state.SkipNextStateSelection = false; score.Value = 0; } else if (state.Value < data.ThirstThreshold) //if not thirsy just return 0 { score.Value = 0; return; } //see if we have any food available // score.Value = ScoreUtils.CalculateDefaultScore(state.Value); }).Schedule(Dependency);