Exemplo n.º 1
0
        private void OnTriggerExit(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))
            {
                List <WeatherMakerWeatherZoneScript> playerZones;
                if (!playersAndZones.TryGetValue(other.transform, out playerZones))
                {
                    playersAndZones[other.transform] = playerZones = new List <WeatherMakerWeatherZoneScript>();
                }

                if (!playerZones.Contains(this))
                {
                    // not in this zone, exit out - sometimes OnTriggerExit is called twice in a row
                    return;
                }

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

                // if entering a new zone, begin transition to the new zone's current weather
                WeatherMakerProfileScript previousProfile = (playerZones.Count == 0 ? null : playerZones[playerZones.Count - 1].currentProfile);
                WeatherMakerProfileScript newProfile      = null;

                // remove zone from the player zone stack
                playerZones.Remove(this);

                // remove player from the zone player list
                zonePlayers.Remove(other.transform);

                float transitionDuration = 0.0f;

                // add the player to the previous weather zone if any
                WeatherMakerWeatherZoneScript newZone = null;
                if (playerZones.Count != 0)
                {
                    newZone = playerZones[playerZones.Count - 1];
                    if (!zonesAndPlayers.TryGetValue(newZone, out zonePlayers))
                    {
                        zonePlayers = new List <Transform>();
                    }
                    zonePlayers.Add(other.transform);

                    // pick a new duration for the transition
                    if (newZone.currentProfile != null)
                    {
                        transitionDuration = newZone.currentProfile.RandomTransitionDuration();
                        newProfile         = newZone.currentProfile;
                    }
                }
                else
                {
                    Debug.LogError("Exited weather zone into no more zones, please add a global weather zone as a catch all zone");
                    return;
                }

                if (WeatherMakerScript.IsLocalPlayer(other.transform))
                {
                    WeatherMakerScript.Instance.LastLocalProfile = newProfile;
                    WeatherMakerScript.Instance.WeatherZoneChanged.Invoke(newZone);
                }

                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, newProfile, transitionDuration * (previousProfile == null ? 1.0f : TransitionDurationMultiplier),
                                                                       secondsRemainingHold, false, (connectionId == null ? null : new string[1] {
                    connectionId
                }));
            }
        }
Exemplo n.º 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
                }));
            }
        }