diff --git a/Unity.Entities.Hybrid.Tests/DefaultWorldInitializationTests.cs b/Unity.Entities.Hybrid.Tests/DefaultWorldInitializationTests.cs new file mode 100644 index 00000000..520dca66 --- /dev/null +++ b/Unity.Entities.Hybrid.Tests/DefaultWorldInitializationTests.cs @@ -0,0 +1,37 @@ +using System; +using System.Collections; +using NUnit.Framework; +using UnityEditor; +using UnityEditor.TestTools; +using UnityEngine; +using UnityEngine.TestTools; + +namespace Unity.Entities.Tests +{ + public class DefaultWorldInitializationTests + { + + [SetUp] + public void Setup() + { + } +// TODO: [case 1040539] Remove this when entering playmode in an editmode test works in 2018.2+ +#if UNITY_2018_1_OR_NEWER && !UNITY_2018_2_OR_NEWER + [UnityTest] + public IEnumerator Initialize_WhenEnteringPlaymode_ShouldLogNothing() + { + EditorApplication.isPlaying = true; + yield return null; + + + LogAssert.NoUnexpectedReceived(); + } +#endif + [TearDown] + public void TearDown() + { + EditorApplication.isPlaying = false; + + } + } +} diff --git a/Unity.Entities.Hybrid.Tests/DefaultWorldInitializationTests.cs.meta b/Unity.Entities.Hybrid.Tests/DefaultWorldInitializationTests.cs.meta new file mode 100644 index 00000000..ac3862f2 --- /dev/null +++ b/Unity.Entities.Hybrid.Tests/DefaultWorldInitializationTests.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: e56cae007ac8d4879b5459a5bde872dc +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Unity.Entities.Hybrid/Injection/DefaultWorldInitialization.cs b/Unity.Entities.Hybrid/Injection/DefaultWorldInitialization.cs index 244bf47d..1d653c91 100644 --- a/Unity.Entities.Hybrid/Injection/DefaultWorldInitialization.cs +++ b/Unity.Entities.Hybrid/Injection/DefaultWorldInitialization.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Linq; using System.Reflection; using UnityEngine; @@ -37,54 +38,75 @@ public static void Initialize(string worldName, bool editorWorld) PlayerLoopManager.RegisterDomainUnload(DomainUnloadShutdown, 10000); + IEnumerable allTypes; + foreach (var ass in AppDomain.CurrentDomain.GetAssemblies()) { try { - var allTypes = ass.GetTypes(); - - // Create all ComponentSyste - var systemTypes = allTypes.Where(t => - t.IsSubclassOf(typeof(ComponentSystemBase)) && - !t.IsAbstract && - !t.ContainsGenericParameters && - (t.GetCustomAttributes(typeof(ComponentSystemPatchAttribute), true).Length == 0) && - t.GetCustomAttributes(typeof(DisableAutoCreationAttribute), true).Length == 0); - foreach (var type in systemTypes) - { - if (editorWorld && type.GetCustomAttributes(typeof(ExecuteInEditMode), true).Length == 0) - continue; - - GetBehaviourManagerAndLogException(world, type); - } + allTypes = ass.GetTypes(); + } - catch (ReflectionTypeLoadException) + catch (ReflectionTypeLoadException e) { - // Can happen for certain assembly during the GetTypes() step + allTypes = e.Types.Where(t => t != null); + Debug.LogWarning("DefaultWorldInitialization failed loading assembly: " + ass.Location); } + + // Create all ComponentSystem + CreateBehaviourManagersForMatchingTypes(editorWorld, allTypes, world); } - + foreach (var ass in AppDomain.CurrentDomain.GetAssemblies()) { - var allTypes = ass.GetTypes(); - - // Create all ComponentSystem - var systemTypes = allTypes.Where(t => - t.IsSubclassOf(typeof(ComponentSystemBase)) && - !t.IsAbstract && - !t.ContainsGenericParameters && - (t.GetCustomAttributes(typeof(ComponentSystemPatchAttribute), true).Length > 0) && - t.GetCustomAttributes(typeof(DisableAutoCreationAttribute), true).Length == 0); - foreach (var type in systemTypes) + try { - if (editorWorld && type.GetCustomAttributes(typeof(ExecuteInEditMode), true).Length == 0) - continue; - - world.AddComponentSystemPatch(type); + allTypes = ass.GetTypes(); } + catch (ReflectionTypeLoadException e) + { + allTypes = e.Types.Where(t => t != null); + Debug.LogWarning("DefaultWorldInitialization failed loading assembly: " + ass.Location); + } + + AddComponentSystemPatchesForMatchingTypes(editorWorld, allTypes, world); } ScriptBehaviourUpdateOrder.UpdatePlayerLoop(world); } + + static void CreateBehaviourManagersForMatchingTypes(bool editorWorld, IEnumerable allTypes, World world) + { + var systemTypes = allTypes.Where(t => + t.IsSubclassOf(typeof(ComponentSystemBase)) && + !t.IsAbstract && + !t.ContainsGenericParameters && + t.GetCustomAttributes(typeof(ComponentSystemPatchAttribute), true).Length == 0 && + t.GetCustomAttributes(typeof(DisableAutoCreationAttribute), true).Length == 0); + foreach (var type in systemTypes) + { + if (editorWorld && type.GetCustomAttributes(typeof(ExecuteInEditMode), true).Length == 0) + continue; + + GetBehaviourManagerAndLogException(world, type); + } + } + + static void AddComponentSystemPatchesForMatchingTypes(bool editorWorld, IEnumerable allTypes, World world) + { + var systemTypes = allTypes.Where(t => + t.IsSubclassOf(typeof(ComponentSystemBase)) && + !t.IsAbstract && + !t.ContainsGenericParameters && + t.GetCustomAttributes(typeof(ComponentSystemPatchAttribute), true).Length > 0 && + t.GetCustomAttributes(typeof(DisableAutoCreationAttribute), true).Length == 0); + foreach (var type in systemTypes) + { + if (editorWorld && type.GetCustomAttributes(typeof(ExecuteInEditMode), true).Length == 0) + continue; + + world.AddComponentSystemPatch(type); + } + } } } diff --git a/Unity.Entities/Stubs/Unity/Debug.cs b/Unity.Entities/Stubs/Unity/Debug.cs index e329d3bb..9145b0af 100644 --- a/Unity.Entities/Stubs/Unity/Debug.cs +++ b/Unity.Entities/Stubs/Unity/Debug.cs @@ -10,6 +10,11 @@ public static void LogError(object message) UnityEngine.Debug.LogError(message); } + public static void LogWarning(object message) + { + UnityEngine.Debug.LogWarning(message); + } + public static void Log(object message) { UnityEngine.Debug.Log(message); diff --git a/package.json b/package.json index 5fded592..61c0a688 100644 --- a/package.json +++ b/package.json @@ -3,14 +3,14 @@ "entities", "unity" ], - "version": "0.0.12-preview.2", + "version": "0.0.12-preview.4", "name": "com.unity.entities", "dependencies": { "com.unity.collections": "0.0.9-preview.1", - "com.unity.properties": "0.1.18-preview.2", - "com.unity.burst": "0.2.4-preview.5", + "com.unity.properties": "0.1.14-preview.2", + "com.unity.burst": "0.2.4-preview.7", "com.unity.jobs": "0.0.7-preview.1", - "com.unity.mathematics": "0.0.12-preview.2" + "com.unity.mathematics": "0.0.12-preview.5" }, "description": "Unity Entity Component System - Core Entity Component System, New Transform components, basic Instance Mesh Renderer" } \ No newline at end of file