EnviroMirrorPlayer.cs 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /// <summary>
  2. /// This component can be used to synchronize time and weather in games where server is a player too.
  3. /// </summary>
  4. using UnityEngine;
  5. using System.Collections;
  6. #if ENVIRO_MIRROR_SUPPORT
  7. using Mirror;
  8. #endif
  9. namespace Enviro
  10. {
  11. #if ENVIRO_MIRROR_SUPPORT
  12. [AddComponentMenu("Enviro 3/Integrations/Mirror Player")]
  13. [RequireComponent(typeof (NetworkIdentity))]
  14. public class EnviroMirrorPlayer : NetworkBehaviour
  15. {
  16. #else
  17. public class EnviroMirrorPlayer : MonoBehaviour
  18. {
  19. #endif
  20. #if ENVIRO_MIRROR_SUPPORT
  21. public bool assignOnStart = true;
  22. public bool findSceneCamera = true;
  23. public Camera Camera;
  24. public void Start()
  25. {
  26. // Deactivate if it isn't ours!
  27. if (!isLocalPlayer && !isServer) {
  28. this.enabled = false;
  29. return;
  30. }
  31. if (Camera == null && findSceneCamera)
  32. Camera = Camera.main;
  33. if (isLocalPlayer)
  34. {
  35. if (assignOnStart && Camera != null)
  36. EnviroManager.instance.Camera = Camera;
  37. Cmd_RequestSeason ();
  38. Cmd_RequestCurrentWeather ();
  39. }
  40. }
  41. [Command]
  42. void Cmd_RequestSeason ()
  43. {
  44. if(EnviroManager.instance.Environment != null)
  45. RpcRequestSeason((int)EnviroManager.instance.Environment.Settings.season);
  46. }
  47. [ClientRpc]
  48. void RpcRequestSeason (int season)
  49. {
  50. if(EnviroManager.instance.Environment != null)
  51. EnviroManager.instance.Environment.ChangeSeason((EnviroEnvironment.Seasons)season);
  52. }
  53. [Command]
  54. void Cmd_RequestCurrentWeather ()
  55. {
  56. if(EnviroManager.instance.Weather != null)
  57. {
  58. //for (int i = 0; i < EnviroSkyMgr.instance.Weather.zones.Count; i++)
  59. //{
  60. for (int w = 0; w < EnviroManager.instance.Weather.Settings.weatherTypes.Count; w++)
  61. {
  62. if (EnviroManager.instance.Weather.Settings.weatherTypes[w] == EnviroManager.instance.Weather.targetWeatherType)
  63. RpcRequestCurrentWeather(w);
  64. }
  65. //}
  66. }
  67. }
  68. [ClientRpc]
  69. void RpcRequestCurrentWeather (int weather)
  70. {
  71. if(EnviroManager.instance.Weather != null)
  72. EnviroManager.instance.Weather.ChangeWeatherInstant(EnviroManager.instance.Weather.Settings.weatherTypes[weather]);
  73. }
  74. #endif
  75. }
  76. }