コード例 #1
0
        private void UpdateProfile()
        {
            // clients will get the transition sent to them via network extension
            if (WeatherMakerScript.Instance == null || !WeatherMakerScript.Instance.NetworkConnection.IsServer || (SingleProfile == null && ProfileGroup == null))
            {
                return;
            }
            else if (SingleProfile == null)
            {
                if (secondsRemainingTransition <= 0.0f || currentProfileSingle != null)
                {
                    secondsRemainingTransition = 0.0f;
                    if (currentProfileSingle != null)
                    {
                        secondsRemainingHold = 0.0f;
                    }

                    if ((secondsRemainingHold -= Time.deltaTime) <= 0.0f)
                    {
                        // setup new transition
                        WeatherMakerProfileScript oldProfile = (currentProfileSingle == null ? currentProfile : currentProfileSingle);
                        currentProfile           = ProfileGroup.PickWeightedProfile();
                        PreviousLastLocalProfile = (oldProfile == null || WeatherMakerScript.Instance.LastLocalProfile == null ? "None" : WeatherMakerScript.Instance.LastLocalProfile.name);
                        LastLocalProfile         = (currentProfile == null ? "None" : currentProfile.name);
                        RangeOfFloats duration = TransitionDuration;
                        currentProfile = WeatherMakerProfileGroupScript.OverrideProfile(currentProfile, CloudProfile, SkyProfile, AuroraProfile,
                                                                                        PrecipitationProfile, FogProfile, WindProfile, LightningProfile, SoundProfile, duration, HoldDuration);
                        secondsRemainingTransition = currentProfile.RandomTransitionDuration();
                        secondsRemainingHold       = currentProfile.RandomHoldDuration();
                        NotifyThoseInZoneOfProfileChange(oldProfile, currentProfile, secondsRemainingTransition);
                        CleanupProfile(oldProfile);
                    }
                }
                else
                {
                    // else let the transition continue
                    secondsRemainingTransition -= Time.deltaTime;
                }
                currentProfileSingle = null;
            }
            else if (SingleProfile != currentProfileSingle)
            {
                currentProfileSingle = SingleProfile;
                WeatherMakerProfileScript oldProfile = currentProfile;
                RangeOfFloats             duration   = TransitionDuration;
                currentProfile = WeatherMakerProfileGroupScript.OverrideProfile(SingleProfile, CloudProfile, SkyProfile, AuroraProfile,
                                                                                PrecipitationProfile, FogProfile, WindProfile, LightningProfile, SoundProfile, duration, HoldDuration);
                PreviousLastLocalProfile   = (oldProfile == null || WeatherMakerScript.Instance.LastLocalProfile == null ? "None" : WeatherMakerScript.Instance.LastLocalProfile.name);
                LastLocalProfile           = (currentProfile == null ? "None" : currentProfile.name);
                secondsRemainingTransition = currentProfile.RandomTransitionDuration();
                NotifyThoseInZoneOfProfileChange(oldProfile, SingleProfile, secondsRemainingTransition);
                CleanupProfile(oldProfile);
            }
        }
コード例 #2
0
        private void OnTriggerEnter(Collider other)
        {
            if (SingleProfile == null && ProfileGroup == null)
            {
                return;
            }

            bool isServer = WeatherMakerScript.Instance != null && WeatherMakerScript.Instance.NetworkConnection.IsServer;

            if (isServer && gameObject.activeInHierarchy && enabled && WeatherMakerScript.IsPlayer(other.transform))
            {
                // ensure we have player zones and zone players lists
                List <WeatherMakerWeatherZoneScript> playerZones;
                if (!playersAndZones.TryGetValue(other.transform, out playerZones))
                {
                    playersAndZones[other.transform] = playerZones = new List <WeatherMakerWeatherZoneScript>();
                }

                if (playerZones.Contains(this))
                {
                    // already in the zone, don't re-process, sometimes OnTriggerEnter is called twice in a row
                    return;
                }

                List <Transform> zonePlayers;
                if (!zonesAndPlayers.TryGetValue(this, out zonePlayers))
                {
                    zonesAndPlayers[this] = zonePlayers = new List <Transform>();
                }

                // remove player from their previous zone
                WeatherMakerWeatherZoneScript prevZone = null;
                if (playerZones.Count != 0)
                {
                    // remove player from previous weather zone
                    prevZone = playerZones[playerZones.Count - 1];
                    List <Transform> prevZonePlayers;
                    if (zonesAndPlayers.TryGetValue(prevZone, out prevZonePlayers))
                    {
                        prevZonePlayers.Remove(other.transform);
                    }
                }

                // see if we have a previous zone, if so we have a previous profile to transition from
                WeatherMakerProfileScript previousProfile = (playerZones.Count == 0 ? null : playerZones[playerZones.Count - 1].currentProfile);
                float transitionDuration = (previousProfile == null ? 0.001f : currentProfile.RandomTransitionDuration());

                // add zone to the player zone stack
                playerZones.Add(this);

                // add player to the zone player list
                zonePlayers.Add(other.transform);

                if (WeatherMakerScript.IsLocalPlayer(other.transform))
                {
                    WeatherMakerScript.Instance.LastLocalProfile = currentProfile;
                    if (prevZone != this)
                    {
                        WeatherMakerScript.Instance.WeatherZoneChanged.Invoke(this);
                    }
                }

                // pick a new duration for the transition
                string connectionId = WeatherMakerScript.Instance.NetworkConnection.GetConnectionId(other.transform);

                // transition to new weather zone
                // if transition from another zone, multiply the transition duration so we get to the new weather zone weather more quickly
                WeatherMakerScript.Instance.RaiseWeatherProfileChanged(previousProfile, currentProfile, transitionDuration * (previousProfile == null ? 1.0f : TransitionDurationMultiplier),
                                                                       secondsRemainingHold, false, (connectionId == null ? null : new string[1] {
                    connectionId
                }));
            }
        }