add weather and time
This commit is contained in:
@@ -0,0 +1,88 @@
|
||||
/// <summary>
|
||||
/// This component can be used to synchronize time and weather in games where server is a player too.
|
||||
/// </summary>
|
||||
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
#if ENVIRO_MIRROR_SUPPORT
|
||||
using Mirror;
|
||||
#endif
|
||||
|
||||
namespace Enviro
|
||||
{
|
||||
#if ENVIRO_MIRROR_SUPPORT
|
||||
[AddComponentMenu("Enviro 3/Integrations/Mirror Player")]
|
||||
[RequireComponent(typeof (NetworkIdentity))]
|
||||
public class EnviroMirrorPlayer : NetworkBehaviour
|
||||
{
|
||||
#else
|
||||
public class EnviroMirrorPlayer : MonoBehaviour
|
||||
{
|
||||
#endif
|
||||
#if ENVIRO_MIRROR_SUPPORT
|
||||
public bool assignOnStart = true;
|
||||
public bool findSceneCamera = true;
|
||||
|
||||
public Camera Camera;
|
||||
|
||||
public void Start()
|
||||
{
|
||||
// Deactivate if it isn't ours!
|
||||
if (!isLocalPlayer && !isServer) {
|
||||
this.enabled = false;
|
||||
return;
|
||||
}
|
||||
|
||||
if (Camera == null && findSceneCamera)
|
||||
Camera = Camera.main;
|
||||
|
||||
if (isLocalPlayer)
|
||||
{
|
||||
if (assignOnStart && Camera != null)
|
||||
EnviroManager.instance.Camera = Camera;
|
||||
|
||||
Cmd_RequestSeason ();
|
||||
Cmd_RequestCurrentWeather ();
|
||||
}
|
||||
}
|
||||
|
||||
[Command]
|
||||
void Cmd_RequestSeason ()
|
||||
{
|
||||
if(EnviroManager.instance.Environment != null)
|
||||
RpcRequestSeason((int)EnviroManager.instance.Environment.Settings.season);
|
||||
}
|
||||
|
||||
[ClientRpc]
|
||||
void RpcRequestSeason (int season)
|
||||
{
|
||||
if(EnviroManager.instance.Environment != null)
|
||||
EnviroManager.instance.Environment.ChangeSeason((EnviroEnvironment.Seasons)season);
|
||||
}
|
||||
|
||||
[Command]
|
||||
void Cmd_RequestCurrentWeather ()
|
||||
{
|
||||
if(EnviroManager.instance.Weather != null)
|
||||
{
|
||||
//for (int i = 0; i < EnviroSkyMgr.instance.Weather.zones.Count; i++)
|
||||
//{
|
||||
for (int w = 0; w < EnviroManager.instance.Weather.Settings.weatherTypes.Count; w++)
|
||||
{
|
||||
if (EnviroManager.instance.Weather.Settings.weatherTypes[w] == EnviroManager.instance.Weather.targetWeatherType)
|
||||
RpcRequestCurrentWeather(w);
|
||||
}
|
||||
//}
|
||||
}
|
||||
}
|
||||
|
||||
[ClientRpc]
|
||||
void RpcRequestCurrentWeather (int weather)
|
||||
{
|
||||
if(EnviroManager.instance.Weather != null)
|
||||
EnviroManager.instance.Weather.ChangeWeatherInstant(EnviroManager.instance.Weather.Settings.weatherTypes[weather]);
|
||||
}
|
||||
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3d95b72a2e3fe9c43b3bd9530a383745
|
||||
timeCreated: 1480502929
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 236601
|
||||
packageName: Enviro 3 - Sky and Weather
|
||||
packageVersion: 3.1.2
|
||||
assetPath: Assets/Enviro 3 - Sky and Weather/Scripts/ThirdPartySupport/Mirror/EnviroMirrorPlayer.cs
|
||||
uploadId: 660896
|
||||
@@ -0,0 +1,122 @@
|
||||
/// <summary>
|
||||
/// This component can be used to synchronize time and weather.
|
||||
/// </summary>
|
||||
|
||||
using UnityEngine;
|
||||
#if ENVIRO_MIRROR_SUPPORT
|
||||
using Mirror;
|
||||
#endif
|
||||
using System.Collections;
|
||||
namespace Enviro
|
||||
{
|
||||
#if ENVIRO_MIRROR_SUPPORT
|
||||
[AddComponentMenu("Enviro 3/Integrations/Mirror Server")]
|
||||
[RequireComponent(typeof (NetworkIdentity))]
|
||||
public class EnviroMirrorServer : NetworkBehaviour {
|
||||
#else
|
||||
public class EnviroMirrorServer : MonoBehaviour {
|
||||
#endif
|
||||
#if ENVIRO_MIRROR_SUPPORT
|
||||
public float updateSmoothing = 15f;
|
||||
|
||||
[SyncVar] private float networkHours;
|
||||
[SyncVar] private int networkDays;
|
||||
[SyncVar] private int networkMonths;
|
||||
[SyncVar] private int networkYears;
|
||||
|
||||
public override void OnStartServer()
|
||||
{
|
||||
EnviroManager.instance.OnSeasonChanged += (EnviroEnvironment.Seasons season) => {
|
||||
SendSeasonToClient (season);
|
||||
};
|
||||
EnviroManager.instance.OnZoneWeatherChanged += (EnviroWeatherType type, EnviroZone zone) => {
|
||||
SendWeatherToClient (type, zone);
|
||||
};
|
||||
}
|
||||
|
||||
public void Start ()
|
||||
{
|
||||
if (!isServer)
|
||||
{
|
||||
if(EnviroManager.instance.Time != null)
|
||||
EnviroManager.instance.Time.Settings.simulate = false;
|
||||
|
||||
if(EnviroManager.instance.Weather != null)
|
||||
EnviroManager.instance.Weather.globalAutoWeatherChange = false;
|
||||
|
||||
if(EnviroManager.instance.Environment != null)
|
||||
EnviroManager.instance.Environment.Settings.changeSeason = false;
|
||||
}
|
||||
}
|
||||
|
||||
void SendWeatherToClient (EnviroWeatherType w, EnviroZone z)
|
||||
{
|
||||
int weatherID = 0;
|
||||
int zoneID = -1;
|
||||
|
||||
for(int i = 0; i < EnviroManager.instance.Weather.Settings.weatherTypes.Count; i++)
|
||||
{
|
||||
if (EnviroManager.instance.Weather.Settings.weatherTypes [i] == w)
|
||||
weatherID = i;
|
||||
}
|
||||
|
||||
for (int i = 0; i < EnviroManager.instance.zones.Count; i++)
|
||||
{
|
||||
if (EnviroManager.instance.zones [i] == z)
|
||||
zoneID = i;
|
||||
}
|
||||
RpcWeatherUpdate(weatherID,zoneID);
|
||||
}
|
||||
|
||||
void SendSeasonToClient (EnviroEnvironment.Seasons s)
|
||||
{
|
||||
RpcSeasonUpdate((int)s);
|
||||
}
|
||||
|
||||
[ClientRpc]
|
||||
void RpcSeasonUpdate (int season)
|
||||
{
|
||||
if(EnviroManager.instance.Environment != null)
|
||||
EnviroManager.instance.Environment.ChangeSeason((EnviroEnvironment.Seasons)season);
|
||||
}
|
||||
|
||||
[ClientRpc]
|
||||
void RpcWeatherUpdate (int weather, int zone)
|
||||
{
|
||||
if(EnviroManager.instance.Weather != null)
|
||||
{
|
||||
if(zone == -1)
|
||||
EnviroManager.instance.Weather.ChangeWeather(weather);
|
||||
else
|
||||
EnviroManager.instance.Weather.ChangeZoneWeather(weather,zone);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Update ()
|
||||
{
|
||||
if (EnviroManager.instance == null || EnviroManager.instance.Time == null)
|
||||
return;
|
||||
|
||||
if (!isServer)
|
||||
{
|
||||
if (networkHours < 1f && EnviroManager.instance.Time.GetTimeOfDay() > 23f)
|
||||
EnviroManager.instance.Time.SetTimeOfDay(networkHours);
|
||||
|
||||
EnviroManager.instance.Time.SetTimeOfDay(Mathf.Lerp(EnviroManager.instance.Time.GetTimeOfDay(), (float)networkHours, Time.deltaTime * updateSmoothing));
|
||||
EnviroManager.instance.Time.years = networkYears;
|
||||
EnviroManager.instance.Time.months = networkMonths;
|
||||
EnviroManager.instance.Time.days = networkDays;
|
||||
|
||||
} else {
|
||||
networkHours = EnviroManager.instance.Time.GetTimeOfDay();
|
||||
networkDays = EnviroManager.instance.Time.days;
|
||||
networkMonths = EnviroManager.instance.Time.months;
|
||||
networkYears = EnviroManager.instance.Time.years;
|
||||
}
|
||||
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 16fa76d7b5adcb14f894e96a517beec7
|
||||
timeCreated: 1491610098
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 236601
|
||||
packageName: Enviro 3 - Sky and Weather
|
||||
packageVersion: 3.1.2
|
||||
assetPath: Assets/Enviro 3 - Sky and Weather/Scripts/ThirdPartySupport/Mirror/EnviroMirrorServer.cs
|
||||
uploadId: 660896
|
||||
Reference in New Issue
Block a user