Seven is the number.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

143 lines
3.1 KiB

3 years ago
4 years ago
3 years ago
4 years ago
3 years ago
4 years ago
3 years ago
4 years ago
3 years ago
4 years ago
3 years ago
4 years ago
3 years ago
4 years ago
3 years ago
4 years ago
3 years ago
4 years ago
3 years ago
4 years ago
3 years ago
4 years ago
3 years ago
4 years ago
3 years ago
4 years ago
3 years ago
4 years ago
3 years ago
4 years ago
3 years ago
4 years ago
3 years ago
4 years ago
3 years ago
4 years ago
3 years ago
4 years ago
3 years ago
4 years ago
3 years ago
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Reflection;
  5. using Photon.Bolt.Collections;
  6. using Photon.Bolt.Internal;
  7. using Photon.Bolt.Utils;
  8. using UnityEngine;
  9. using UnityEngine.SceneManagement;
  10. using UnityEngine.Scripting;
  11. namespace Photon.Bolt
  12. {
  13. [Preserve]
  14. public static class BoltDynamicData
  15. {
  16. private static Dictionary<string, Assembly> _assemblies;
  17. private static List<STuple<BoltGlobalBehaviourAttribute, Type>> _globalBehaviours;
  18. private static Dictionary<string, Assembly> GetAssemblies
  19. {
  20. get
  21. {
  22. if (_assemblies == null)
  23. {
  24. _assemblies = new Dictionary<string, Assembly>();
  25. foreach (var asm in AppDomain.CurrentDomain.GetAssemblies())
  26. {
  27. var name = asm.GetName().Name;
  28. if (_assemblies.ContainsKey(name) == false)
  29. {
  30. _assemblies.Add(name, asm);
  31. }
  32. }
  33. }
  34. return _assemblies;
  35. }
  36. }
  37. public static void Setup()
  38. {
  39. BoltNetworkInternal.DebugDrawer = new UnityDebugDrawer();
  40. #if UNITY_PRO_LICENSE
  41. BoltNetworkInternal.UsingUnityPro = true;
  42. #else
  43. BoltNetworkInternal.UsingUnityPro = false;
  44. #endif
  45. BoltNetworkInternal.GetActiveSceneIndex = GetActiveSceneIndex;
  46. BoltNetworkInternal.GetSceneName = GetSceneName;
  47. BoltNetworkInternal.GetSceneIndex = GetSceneIndex;
  48. BoltNetworkInternal.GetGlobalBehaviourTypes = GetGlobalBehaviourTypes;
  49. BoltNetworkInternal.EnvironmentSetup = BoltNetworkInternal_User.EnvironmentSetup;
  50. BoltNetworkInternal.EnvironmentReset = BoltNetworkInternal_User.EnvironmentReset;
  51. // Setup Unity Config
  52. #if ENABLE_IL2CPP
  53. UnitySettings.IsBuildIL2CPP = true;
  54. #elif ENABLE_MONO
  55. UnitySettings.IsBuildMono = true;
  56. #elif ENABLE_DOTNET
  57. UnitySettings.IsBuildDotNet = true;
  58. #endif
  59. UnitySettings.CurrentPlatform = Application.platform;
  60. }
  61. private static int GetActiveSceneIndex()
  62. {
  63. return GetSceneIndex(SceneManager.GetActiveScene().name);
  64. }
  65. private static int GetSceneIndex(string name)
  66. {
  67. try
  68. {
  69. return BoltScenes_Internal.GetSceneIndex(name);
  70. }
  71. catch
  72. {
  73. return -1;
  74. }
  75. }
  76. private static string GetSceneName(int index)
  77. {
  78. try
  79. {
  80. return BoltScenes_Internal.GetSceneName(index);
  81. }
  82. catch
  83. {
  84. return null;
  85. }
  86. }
  87. private static List<STuple<BoltGlobalBehaviourAttribute, Type>> GetGlobalBehaviourTypes()
  88. {
  89. if (_globalBehaviours == null)
  90. {
  91. _globalBehaviours = new List<STuple<BoltGlobalBehaviourAttribute, Type>>();
  92. }
  93. else
  94. {
  95. _globalBehaviours.Clear();
  96. }
  97. try
  98. {
  99. var asmIter = BoltAssemblies.AllAssemblies;
  100. while (asmIter.MoveNext())
  101. {
  102. if (GetAssemblies.TryGetValue(asmIter.Current, out var asm))
  103. {
  104. foreach (Type type in asm.GetTypes())
  105. {
  106. if (typeof(MonoBehaviour).IsAssignableFrom(type))
  107. {
  108. var attrs = (BoltGlobalBehaviourAttribute[])type.GetCustomAttributes(typeof(BoltGlobalBehaviourAttribute), false);
  109. if (attrs.Length == 1)
  110. {
  111. _globalBehaviours.Add(new STuple<BoltGlobalBehaviourAttribute, Type>(attrs[0], type));
  112. }
  113. }
  114. }
  115. }
  116. }
  117. }
  118. catch (Exception e)
  119. {
  120. BoltLog.Exception(e);
  121. }
  122. return _globalBehaviours;
  123. }
  124. }
  125. }