private void UpdateCounters(ElevatorLift lift, PowerCounter[] counters) { // Get the elevator on every update, since the lift can be re-parented var elevator = lift.GetParentEntity() as Elevator; if (elevator == null || counters == null) { return; } var floor = elevator.LiftPositionToFloor() + 1; foreach (var counter in counters) { if (counter.counterNumber == floor) { continue; } counter.counterNumber = floor; counter.targetCounterNumber = floor; counter.currentEnergy = floor; counter.SendNetworkUpdate(); } }
private void StartUpdatingLiftCounters(ElevatorLift lift, PowerCounter[] counters, float timeToTravel) { Action existingTimerAction; if (liftTimerActions.TryGetValue(lift.net.ID, out existingTimerAction)) { lift.CancelInvoke(existingTimerAction); } var lastCounterUpdateTime = Time.time; Action timerAction = null; var stepsRemaining = timeToTravel / MaxCounterUpdateFrequency; timerAction = () => { stepsRemaining--; var reachedEnd = stepsRemaining <= 0; if (reachedEnd || Time.time >= lastCounterUpdateTime + MaxCounterUpdateFrequency) { UpdateCounters(lift, counters); lastCounterUpdateTime = Time.time; } if (reachedEnd) { lift.CancelInvoke(timerAction); liftTimerActions.Remove(lift.net.ID); } }; lift.InvokeRepeating(timerAction, MaxCounterUpdateFrequency, MaxCounterUpdateFrequency); liftTimerActions[lift.net.ID] = timerAction; }
private float GetTravelTime(ElevatorLift lift) { var tweens = LeanTween.descriptions(lift.gameObject); if (tweens.Length == 0) { return(0); } return(tweens[0].time); }
public void FindExistingLiftChild() { foreach (BaseEntity child in children) { ElevatorLift elevatorLift; if ((object)(elevatorLift = child as ElevatorLift) != null) { liftEntity = elevatorLift; break; } } }
public void UpdateChildEntities(bool isTop) { if (isTop) { if (liftEntity == null) { FindExistingLiftChild(); } if (liftEntity == null) { liftEntity = GameManager.server.CreateEntity(LiftEntityPrefab.resourcePath, GetWorldSpaceFloorPosition(Floor), LiftRoot.rotation) as ElevatorLift; liftEntity.SetParent(this, true); liftEntity.Spawn(); } if (ioEntity == null) { FindExistingIOChild(); } if (ioEntity == null && IoEntityPrefab.isValid) { ioEntity = GameManager.server.CreateEntity(IoEntityPrefab.resourcePath, IoEntitySpawnPoint.position, IoEntitySpawnPoint.rotation) as IOEntity; ioEntity.SetParent(this, true); ioEntity.Spawn(); } } else { if (liftEntity != null) { liftEntity.Kill(); } if (ioEntity != null) { ioEntity.Kill(); } } }
private void OnEntityKill(ElevatorLift lift) { liftTimerActions.Remove(lift.net.ID); }