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.

98 lines
2.5 KiB

4 years ago
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Reflection;
  5. using BoltInternal;
  6. using UnityEngine;
  7. using UnityEngine.SceneManagement;
  8. using UnityEngine.Scripting;
  9. namespace Bolt
  10. {
  11. [Preserve]
  12. public static class BoltDynamicData
  13. {
  14. public static void Setup()
  15. {
  16. BoltNetworkInternal.DebugDrawer = new BoltInternal.UnityDebugDrawer();
  17. #if UNITY_PRO_LICENSE
  18. BoltNetworkInternal.UsingUnityPro = true;
  19. #else
  20. BoltNetworkInternal.UsingUnityPro = false;
  21. #endif
  22. BoltNetworkInternal.GetActiveSceneIndex = GetActiveSceneIndex;
  23. BoltNetworkInternal.GetSceneName = GetSceneName;
  24. BoltNetworkInternal.GetSceneIndex = GetSceneIndex;
  25. BoltNetworkInternal.GetGlobalBehaviourTypes = GetGlobalBehaviourTypes;
  26. BoltNetworkInternal.EnvironmentSetup = BoltInternal.BoltNetworkInternal_User.EnvironmentSetup;
  27. BoltNetworkInternal.EnvironmentReset = BoltInternal.BoltNetworkInternal_User.EnvironmentReset;
  28. // Setup Unity Config
  29. #if ENABLE_IL2CPP
  30. UnitySettings.IsBuildIL2CPP = true;
  31. #elif ENABLE_MONO
  32. UnitySettings.IsBuildMono = true;
  33. #elif ENABLE_DOTNET
  34. UnitySettings.IsBuildDotNet = true;
  35. #endif
  36. UnitySettings.CurrentPlatform = Application.platform;
  37. }
  38. static int GetActiveSceneIndex()
  39. {
  40. return SceneManager.GetActiveScene().buildIndex;
  41. }
  42. static int GetSceneIndex(string name)
  43. {
  44. return BoltInternal.BoltScenes_Internal.GetSceneIndex(name);
  45. }
  46. static string GetSceneName(int index)
  47. {
  48. return BoltInternal.BoltScenes_Internal.GetSceneName(index);
  49. }
  50. static public List<STuple<BoltGlobalBehaviourAttribute, Type>> GetGlobalBehaviourTypes()
  51. {
  52. List<STuple<BoltGlobalBehaviourAttribute, Type>> result = new List<STuple<BoltGlobalBehaviourAttribute, Type>>();
  53. try
  54. {
  55. var asmIter = BoltAssemblies.AllAssemblies;
  56. while (asmIter.MoveNext())
  57. {
  58. var asm = GetAssemblyByName(asmIter.Current);
  59. if (asm == null) { continue; }
  60. foreach (Type type in asm.GetTypes())
  61. {
  62. if (typeof(MonoBehaviour).IsAssignableFrom(type))
  63. {
  64. var attrs = (BoltGlobalBehaviourAttribute[]) type.GetCustomAttributes(typeof(BoltGlobalBehaviourAttribute), false);
  65. if (attrs.Length == 1)
  66. {
  67. result.Add(new STuple<BoltGlobalBehaviourAttribute, Type>(attrs[0], type));
  68. }
  69. }
  70. }
  71. }
  72. }
  73. catch (Exception e)
  74. {
  75. BoltLog.Exception(e);
  76. }
  77. return result;
  78. }
  79. static Assembly GetAssemblyByName(string name)
  80. {
  81. return AppDomain.CurrentDomain.GetAssemblies().SingleOrDefault(assembly => assembly.GetName().Name == name);
  82. }
  83. }
  84. }