Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Unity Technologies committed Apr 3, 2019
1 parent 659abec commit de28455
Show file tree
Hide file tree
Showing 5 changed files with 112 additions and 37 deletions.
37 changes: 37 additions & 0 deletions Unity.Entities.Hybrid.Tests/DefaultWorldInitializationTests.cs
Original file line number Diff line number Diff line change
@@ -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;

}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

88 changes: 55 additions & 33 deletions Unity.Entities.Hybrid/Injection/DefaultWorldInitialization.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using UnityEngine;
Expand Down Expand Up @@ -37,54 +38,75 @@ public static void Initialize(string worldName, bool editorWorld)

PlayerLoopManager.RegisterDomainUnload(DomainUnloadShutdown, 10000);

IEnumerable<Type> 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<Type> 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<Type> 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);
}
}
}
}
5 changes: 5 additions & 0 deletions Unity.Entities/Stubs/Unity/Debug.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}

0 comments on commit de28455

Please sign in to comment.