protected override void Awake() { base.Awake(); currentState = MechanicState.Idle; hasJob = false; }
private IEnumerator RepairMachine(Machine brokenMachine) { currentState = MechanicState.Repairing; brokenMachine.OnRepair(); yield return(new WaitForSeconds(repairTime)); currentState = MechanicState.Idle; }
public MechanicInfo(int id, int count) { this.Id = id; this.Count = count; //this.Interval = 1f / speed; //if (Interval < 10) { // Interval = 10; //} this.State = MechanicState.MoveToLoad; }
public MechanicInfo(MechanicInfoSave save) { this.Id = save.id; this.Count = save.count; //this.Interval = save.interval; this.State = save.state; this.timer = save.timer; //if(save.adSave != null ) { // adInfo.Load(save.adSave); //} }
private void OnMechanicStateChanged(MechanicState oldState, MechanicState newState, MechanicInfo mechanic) { if (isInitialized) { if (Mechanic != null && (Mechanic.Id == mechanic.Id)) { UpdateState(newState); //Debug.Log($"new mechanic => {newState}"); } } }
private void OnMechanicStateChanged(MechanicState oldState, MechanicState newState, MechanicInfo mechanic) { //if(mechanic.Count > 0 ) { // if(mechanic.State == MechanicState.Completed ) { // int brokenedCount = Services.TransportService.GetUnitBrokenedCount(mechanic.Id); // if(brokenedCount > 0 ) { // int repairCount = Mathf.Min(brokenedCount, mechanic.Count); // int repaired = Services.TransportService.Repair(mechanic.Id, repairCount); // UDebug.Log($"mechanic => {mechanic.Id} was repaired => {repaired} transports...".Colored(ConsoleTextColor.green)); // } // } //} }
private void ChangeState(MechanicState newState) { MechanicState oldState = State; if (State != newState) { if (newState == MechanicState.MoveToLoad) { timer = 0; State = MechanicState.MoveToLoad; GameEvents.OnMechanicStateChanged(oldState, newState, this); } else if (newState == MechanicState.Loading) { timer -= MoveInterval; State = MechanicState.Loading; GameEvents.OnMechanicStateChanged(oldState, newState, this); if (timer >= LoadInterval) { ChangeState(MechanicState.MoveToUnload); } } else if (newState == MechanicState.MoveToUnload) { timer -= LoadInterval; State = MechanicState.MoveToUnload; GameEvents.OnMechanicStateChanged(oldState, newState, this); if (timer >= MoveInterval) { ChangeState(MechanicState.Unloading); } } else if (newState == MechanicState.Unloading) { timer -= MoveInterval; State = MechanicState.Unloading; GameEvents.OnMechanicStateChanged(oldState, newState, this); if (timer > UnloadInterval) { ChangeState(MechanicState.Completed); } } else if (newState == MechanicState.Completed) { State = MechanicState.Completed; timer = 0; GameEvents.OnMechanicStateChanged(oldState, newState, this); GameEvents.OnMechanicWorkCircleCompleted(this, 1); } } }
protected override void Update() { if (currentState == MechanicState.GotTarget) { unitController.SetTarget(currentMachine.GetUsePosition()); unitController.GetNewPath(); currentState = MechanicState.Moving; } else if (currentState == MechanicState.Moving) { if (unitController.ReachedTarget) { StartCoroutine("RepairMachine", currentMachine); } } base.Update(); }
private void UpdateState(MechanicState state) { print($"update state => {state}"); switch (state) { case MechanicState.MoveToLoad: { progressParent.Deactivate(); rectTransform.localScale = new Vector3(-1, 1, 1); animator.SetTrigger(animNames[Direction.Left]); rectTransform.anchoredPosition = Vector2.Lerp(rightPosition, leftPosition, Mechanic.NormalizedTimer); } break; case MechanicState.Loading: { animator.SetTrigger(animNames[Direction.StayLeft]); rectTransform.anchoredPosition = leftPosition; progressParent.Activate(); } break; case MechanicState.MoveToUnload: { progressParent.Activate(); rectTransform.localScale = Vector3.one; animator.SetTrigger(animNames[Direction.Right]); rectTransform.anchoredPosition = Vector2.Lerp(leftPosition, rightPosition, Mechanic.NormalizedTimer); } break; case MechanicState.Unloading: { rectTransform.localScale = Vector3.one; progressParent.Activate(); animator.SetTrigger(animNames[Direction.StayRight]); rectTransform.anchoredPosition = rightPosition; } break; } }
public static void OnMechanicStateChanged(MechanicState oldState, MechanicState newState, MechanicInfo mechanic) => MechanicStateChanged?.Invoke(oldState, newState, mechanic);
public void AssignMachine(Machine newMachine) { currentMachine = newMachine; currentState = MechanicState.GotTarget; }