diff --git a/Editor.meta b/Editor.meta new file mode 100644 index 0000000..7d6be01 --- /dev/null +++ b/Editor.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 80e364ceab2d401ab3edd84b360d3c5b +timeCreated: 1689445285 \ No newline at end of file diff --git a/Editor/Scripts.meta b/Editor/Scripts.meta new file mode 100644 index 0000000..4e917c2 --- /dev/null +++ b/Editor/Scripts.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 17d8c7945efcf0041926d3576038d617 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Editor/Scripts/10101Software.DOTS.HybridSimulation.Editor.asmdef b/Editor/Scripts/10101Software.DOTS.HybridSimulation.Editor.asmdef new file mode 100644 index 0000000..84872fe --- /dev/null +++ b/Editor/Scripts/10101Software.DOTS.HybridSimulation.Editor.asmdef @@ -0,0 +1,19 @@ +{ + "name": "10101Software.DOTS.HybridSimulation.Editor", + "rootNamespace": "Software10101.DOTS.Editor", + "references": [ + "GUID:852fdcd981c08e249a237d901a75e290", + "GUID:e0cd26848372d4e5c891c569017e11f1" + ], + "includePlatforms": [ + "Editor" + ], + "excludePlatforms": [], + "allowUnsafeCode": false, + "overrideReferences": false, + "precompiledReferences": [], + "autoReferenced": true, + "defineConstraints": [], + "versionDefines": [], + "noEngineReferences": false +} \ No newline at end of file diff --git a/Editor/Scripts/10101Software.DOTS.HybridSimulation.Editor.asmdef.meta b/Editor/Scripts/10101Software.DOTS.HybridSimulation.Editor.asmdef.meta new file mode 100644 index 0000000..01e2135 --- /dev/null +++ b/Editor/Scripts/10101Software.DOTS.HybridSimulation.Editor.asmdef.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: da29fec2caed8674b93f4ba8fb7f707a +AssemblyDefinitionImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Editor/Scripts/Drawers.meta b/Editor/Scripts/Drawers.meta new file mode 100644 index 0000000..c1ff495 --- /dev/null +++ b/Editor/Scripts/Drawers.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 84a58156931905641aee1c74a6c9fb6e +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Editor/Scripts/Drawers/GraphSystemGroupDataDrawer.cs b/Editor/Scripts/Drawers/GraphSystemGroupDataDrawer.cs new file mode 100644 index 0000000..a1029f6 --- /dev/null +++ b/Editor/Scripts/Drawers/GraphSystemGroupDataDrawer.cs @@ -0,0 +1,29 @@ +using Software10101.DOTS.Editor.GraphEditor; +using Software10101.DOTS.MonoBehaviours; +using UnityEditor; +using UnityEngine.UIElements; + +namespace Software10101.DOTS.Editor.Drawers { + [CustomPropertyDrawer(typeof(WorldBehaviour.GraphSystemGroupData))] + public class GraphSystemGroupDataDrawer : PropertyDrawer { + public override VisualElement CreatePropertyGUI(SerializedProperty property) { + // Create property container element. + VisualElement container = new(); + + // Create property fields. + Button editButton = new(() => { + GraphSystemGroupEditorWindow window = EditorWindow.GetWindow(); + + WorldBehaviour wb = (WorldBehaviour)property.serializedObject.targetObject; + window.Initialize(wb, property.name); + }) { + text = $"Edit {property.displayName}" + }; + + // Add fields to the container. + container.Add(editButton); + + return container; + } + } +} diff --git a/Runtime/Scripts/MonoBehaviours/ResetDotsOnDestroy.cs.meta b/Editor/Scripts/Drawers/GraphSystemGroupDataDrawer.cs.meta similarity index 74% rename from Runtime/Scripts/MonoBehaviours/ResetDotsOnDestroy.cs.meta rename to Editor/Scripts/Drawers/GraphSystemGroupDataDrawer.cs.meta index 955b827..8b453f2 100644 --- a/Runtime/Scripts/MonoBehaviours/ResetDotsOnDestroy.cs.meta +++ b/Editor/Scripts/Drawers/GraphSystemGroupDataDrawer.cs.meta @@ -1,10 +1,10 @@ fileFormatVersion: 2 -guid: c0c5bf2b9a434df5a83972fc29185f0a +guid: e0f1e415526cee64f94fe79c0ab8e922 MonoImporter: externalObjects: {} serializedVersion: 2 defaultReferences: [] - executionOrder: 9000 + executionOrder: 0 icon: {instanceID: 0} userData: assetBundleName: diff --git a/Editor/Scripts/GraphEditor.meta b/Editor/Scripts/GraphEditor.meta new file mode 100644 index 0000000..f6214fb --- /dev/null +++ b/Editor/Scripts/GraphEditor.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: a67b7480b7bd7c84a9f97feccdb0dfc5 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Editor/Scripts/GraphEditor/GraphSystemGroupEditorWindow.cs b/Editor/Scripts/GraphEditor/GraphSystemGroupEditorWindow.cs new file mode 100644 index 0000000..bc599e4 --- /dev/null +++ b/Editor/Scripts/GraphEditor/GraphSystemGroupEditorWindow.cs @@ -0,0 +1,292 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using Software10101.DOTS.MonoBehaviours; +using Unity.Collections; +using UnityEditor; +using UnityEditor.Experimental.GraphView; +using UnityEditor.UIElements; +using UnityEngine; +using UnityEngine.UIElements; +using Object = UnityEngine.Object; + +namespace Software10101.DOTS.Editor.GraphEditor { + public class GraphSystemGroupEditorWindow : EditorWindow { + private Object _serializedObjectPrev; + private bool _worldBehaviourPrevExist; + private string _propertyNamePrev; + + private Object _serializedObject; + private string _propertyName; + + private Toolbar _toolbar; + private Label _loadedLabel; + + private GraphSystemGroupGraphView _graphView; + + private readonly List _addNodeChoices = new(); + + private bool _populateNodeCreationChoices = false; + + private void CreateGUI() { + titleContent = new GUIContent("Graph System Group"); + + _graphView = new GraphSystemGroupGraphView { + name = "World Name > System Name" + }; + _graphView.StretchToParentSize(); + _graphView.graphViewChanged += change => { + if (change.elementsToRemove != null) { + _populateNodeCreationChoices = true; + } + + return change; + }; + rootVisualElement.Add(_graphView); + + Node selectGraphNode = new() { + title = "Open a graph system group to use the editor." + }; + + selectGraphNode.SetPosition(new Rect(0, 20, 150, 100)); + selectGraphNode.RefreshExpandedState(); + selectGraphNode.RefreshPorts(); + + _graphView.AddElement(selectGraphNode); + _graphView.UpdateViewTransform(Vector3.zero, Vector3.one); + _graphView.SetEnabled(false); + + _toolbar = new(); + + PopulateNodeCreationChoices(); + DropdownField nodeCreateDropDown = new("Create Node", _addNodeChoices, -1); + nodeCreateDropDown.RegisterValueChangedCallback(evt => { + if (string.IsNullOrEmpty(evt.newValue)) { + return; + } + + SystemTypeReference systemReference = AssetDatabase.LoadAssetAtPath(evt.newValue); + _graphView.AddSystemNode(systemReference.GetInstanceID()); + nodeCreateDropDown.index = -1; + PopulateNodeCreationChoices(); + }); + _toolbar.Add(nodeCreateDropDown); + + _loadedLabel = new Label(""); + _toolbar.Add(_loadedLabel); + + Button saveButton = new(Save) { + text = "Save" + }; + _toolbar.Add(saveButton); + + rootVisualElement.Add(_toolbar); + _toolbar.SetEnabled(false); + } + + private void OnFocus() { + PopulateNodeCreationChoices(); + } + + private void PopulateNodeCreationChoices() { + if (_graphView == null) { + return; + } + + _addNodeChoices.Clear(); + + int[] existingInstanceIds = _graphView.nodes + .Where(node => node is SystemNode systemNode && systemNode.InstanceId.HasValue) + // ReSharper disable once PossibleInvalidOperationException // HasValue check is on the line above + .Select(node => ((SystemNode)node).InstanceId.Value) + .ToArray(); + NativeArray existingInstanceIdsNative = new(existingInstanceIds.Length, Allocator.Persistent); + for (int i = 0; i < existingInstanceIds.Length; i++) { + int existingInstanceId = existingInstanceIds[i]; + existingInstanceIdsNative[i] = existingInstanceId; + } + + NativeArray existingNodeGuidsNative = new(existingInstanceIds.Length, Allocator.Persistent); + + AssetDatabase.InstanceIDsToGUIDs(existingInstanceIdsNative, existingNodeGuidsNative); + + existingInstanceIdsNative.Dispose(); + + HashSet existingNodeGuids = new(); + for (int i = 0; i < existingNodeGuidsNative.Length; i++) { + GUID existingGuid = existingNodeGuidsNative[i]; + existingNodeGuids.Add(existingGuid.ToString()); + } + + _addNodeChoices.AddRange( + AssetDatabase.FindAssets($"t:{nameof(SystemTypeReference)}") + .Where(guid => !existingNodeGuids.Contains(guid)) + .Select(AssetDatabase.GUIDToAssetPath) + ); + + existingNodeGuidsNative.Dispose(); + } + + private void OnGUI() { + if (_graphView == null) { + return; + } + + if (_populateNodeCreationChoices) { + _populateNodeCreationChoices = false; + PopulateNodeCreationChoices(); + } + + if (EditorPrefs.HasKey("graph_editing_world_instance")) { + int instanceId = EditorPrefs.GetInt("graph_editing_world_instance"); + _serializedObject = (WorldBehaviour)EditorUtility.InstanceIDToObject(instanceId); + + if (_serializedObject) { + if (EditorPrefs.HasKey("graph_editing_save_callback")) { + _propertyName = EditorPrefs.GetString("graph_editing_save_callback"); + } + } + } + + if (_serializedObjectPrev != _serializedObject || _propertyNamePrev != _propertyName || _worldBehaviourPrevExist != _serializedObject) { + _graphView.DeleteElements(_graphView.graphElements); + + if (!_serializedObject) { + _toolbar.SetEnabled(false); + + Node selectGraphNode = new() { + title = "Open a graph system group to use the editor." + }; + + selectGraphNode.SetPosition(new Rect(0, 20, 150, 100)); + selectGraphNode.RefreshExpandedState(); + selectGraphNode.RefreshPorts(); + + _graphView.AddElement(selectGraphNode); + _graphView.UpdateViewTransform(Vector3.zero, Vector3.one); + _graphView.SetEnabled(false); + } else { + _toolbar.SetEnabled(true); + _graphView.SetEnabled(true); + + Load(); + } + } else if (_serializedObject && _graphView.enabledSelf == false) { + _graphView.DeleteElements(_graphView.graphElements); + + _toolbar.SetEnabled(true); + _graphView.SetEnabled(true); + + Load(); + } + + if (_serializedObject) { + string dirtyFlag = _graphView.Dirty ? " *" : ""; + _loadedLabel.text = $"{_serializedObject.name} - {_propertyName}{dirtyFlag}"; + } else { + _loadedLabel.text = ""; + } + + _worldBehaviourPrevExist = _serializedObject; + _serializedObjectPrev = _serializedObject; + _propertyNamePrev = _propertyName; + } + + public void Initialize(Object serializedObject, string propertyName) { + _serializedObject = serializedObject; + _propertyName = propertyName; + + EditorPrefs.SetInt("graph_editing_world_instance", serializedObject.GetInstanceID()); + EditorPrefs.SetString("graph_editing_save_callback", propertyName); + } + + private void OnDisable() { + rootVisualElement.Clear(); + _serializedObject = null; + _propertyName = null; + } + + private void Save() { + SerializedObject so = new(_serializedObject); + + WorldBehaviour.GraphSystemGroupData graphData = WorldBehaviour.GraphSystemGroupData.CreateEmpty(); + + HashSet rootDependencies = new(); + Dictionary> dependencies = new(); + + _graphView.edges.ForEach(edge => { + int? dependent = ((SystemNode)edge.input.node).InstanceId; + // ReSharper disable once PossibleInvalidOperationException // not possible - root is never a dependency + int dependency = ((SystemNode)edge.output.node).InstanceId.Value; + + HashSet existingDependencies; + + if (!dependent.HasValue) { + existingDependencies = rootDependencies; + } else if (!dependencies.TryGetValue(dependent.Value, out existingDependencies)) { + existingDependencies = new HashSet(); + dependencies[dependent.Value] = existingDependencies; + } + + existingDependencies.Add(dependency); + }); + + graphData.Nodes = _graphView.nodes + .OfType() + .Select(systemNode => new WorldBehaviour.GraphSystemGroupData.SystemNodeData( + systemNode.InstanceId.HasValue + ? (SystemTypeReference)EditorUtility.InstanceIDToObject(systemNode.InstanceId.Value) + : null, + systemNode.GetPosition().position, + systemNode.InstanceId.HasValue + ? dependencies.ContainsKey(systemNode.InstanceId.Value) + ? dependencies[systemNode.InstanceId.Value]? + .Select(instanceId => (SystemTypeReference)EditorUtility.InstanceIDToObject(instanceId)) + .ToArray() ?? Array.Empty() + : Array.Empty() + : rootDependencies + .Select(instanceId => (SystemTypeReference)EditorUtility.InstanceIDToObject(instanceId)) + .ToArray())) + .ToArray(); + + so.FindProperty(_propertyName).boxedValue = graphData; + so.ApplyModifiedProperties(); + + _graphView.Dirty = false; + } + + private void Load() { + SerializedObject so = new(_serializedObject); + object graphDataRaw = so.FindProperty(_propertyName).boxedValue; + WorldBehaviour.GraphSystemGroupData graphData = (WorldBehaviour.GraphSystemGroupData)graphDataRaw; + + SystemNode rootNode = null; + Dictionary nodesByInstanceId = new(); + + foreach (WorldBehaviour.GraphSystemGroupData.SystemNodeData systemNodeData in graphData.Nodes) { + if (systemNodeData.SystemReference) { + int instanceId = systemNodeData.SystemReference.GetInstanceID(); + + SystemNode node = _graphView.AddSystemNode(instanceId, systemNodeData.NodePosition); + nodesByInstanceId[instanceId] = node; + } else { + rootNode = _graphView.AddSystemNode(null, systemNodeData.NodePosition); + } + } + + foreach (WorldBehaviour.GraphSystemGroupData.SystemNodeData systemNodeData in graphData.Nodes) { + if (systemNodeData.SystemReference) { + SystemNode dependent = nodesByInstanceId[systemNodeData.SystemReference.GetInstanceID()]; + + foreach (SystemTypeReference systemTypeReference in systemNodeData.Dependencies) { + _graphView.AddSystemDependency(dependent, nodesByInstanceId[systemTypeReference.GetInstanceID()]); + } + } else { + foreach (SystemTypeReference systemTypeReference in systemNodeData.Dependencies) { + _graphView.AddSystemDependency(rootNode, nodesByInstanceId[systemTypeReference.GetInstanceID()]); + } + } + } + } + } +} diff --git a/Runtime/Scripts/MonoBehaviours/Bootstrapper.cs.meta b/Editor/Scripts/GraphEditor/GraphSystemGroupEditorWindow.cs.meta similarity index 74% rename from Runtime/Scripts/MonoBehaviours/Bootstrapper.cs.meta rename to Editor/Scripts/GraphEditor/GraphSystemGroupEditorWindow.cs.meta index 0ebe057..12dc4e6 100644 --- a/Runtime/Scripts/MonoBehaviours/Bootstrapper.cs.meta +++ b/Editor/Scripts/GraphEditor/GraphSystemGroupEditorWindow.cs.meta @@ -1,10 +1,10 @@ fileFormatVersion: 2 -guid: b33bdd720942b1e4099016162c3e3add +guid: 4846e549c68c9114aa30558bcfe98aa9 MonoImporter: externalObjects: {} serializedVersion: 2 defaultReferences: [] - executionOrder: -10000 + executionOrder: 0 icon: {instanceID: 0} userData: assetBundleName: diff --git a/Editor/Scripts/GraphEditor/GraphSystemGroupGraphView.cs b/Editor/Scripts/GraphEditor/GraphSystemGroupGraphView.cs new file mode 100644 index 0000000..80c307b --- /dev/null +++ b/Editor/Scripts/GraphEditor/GraphSystemGroupGraphView.cs @@ -0,0 +1,80 @@ +using System.Collections.Generic; +using System.Linq; +using UnityEditor; +using UnityEditor.Experimental.GraphView; +using UnityEngine; +using UnityEngine.UIElements; + +namespace Software10101.DOTS.Editor.GraphEditor { + public class GraphSystemGroupGraphView : GraphView { + public bool Dirty = false; + + public GraphSystemGroupGraphView() { + SetupZoom(ContentZoomer.DefaultMinScale, ContentZoomer.DefaultMaxScale); + + this.AddManipulator(new ContentDragger()); + this.AddManipulator(new SelectionDragger()); + this.AddManipulator(new RectangleSelector()); + + graphViewChanged += OnGraphChanged; + } + + private GraphViewChange OnGraphChanged(GraphViewChange change) { + Dirty = true; + return change; + } + + public override List GetCompatiblePorts(Port startPort, NodeAdapter nodeAdapter) { + return ports + .Where(port => startPort.node != port.node) + .Where(port => startPort.direction != port.direction) + .Where(port => startPort.portType == port.portType) + .ToList(); + + // TODO prevent circular dependencies + } + + public SystemNode AddSystemNode(int? instanceId, Vector2? position = null) { + SystemNode systemNode = new() { + title = instanceId.HasValue ? EditorUtility.InstanceIDToObject(instanceId.Value).name : "Root", + InstanceId = instanceId + }; + + Port inputPort = systemNode.InstantiatePort(Orientation.Horizontal, Direction.Input, Port.Capacity.Multi, typeof(object)); + inputPort.portName = "Depends On"; + systemNode.inputContainer.Add(inputPort); + systemNode.DependenciesInput = inputPort; + + if (instanceId.HasValue) { + Port outputPort = systemNode.InstantiatePort(Orientation.Horizontal, Direction.Output, Port.Capacity.Multi, + typeof(object)); + outputPort.portName = ""; + systemNode.outputContainer.Add(outputPort); + systemNode.SelfOutput = outputPort; + } + + systemNode.RefreshExpandedState(); + systemNode.RefreshPorts(); + + Vector2 viewportRect = viewTransform.position; + Vector2 nodePosition = position ?? (-viewportRect + 0.5f * contentRect.size); + systemNode.SetPosition(new Rect(nodePosition.x, nodePosition.y, 250, 100)); + + AddElement(systemNode); + + ClearSelection(); + AddToSelection(systemNode); + + return systemNode; + } + + public void AddSystemDependency(SystemNode dependent, SystemNode dependency) { + Edge edge = new() { + input = dependent.DependenciesInput, + output = dependency.SelfOutput + }; + + AddElement(edge); + } + } +} diff --git a/Editor/Scripts/GraphEditor/GraphSystemGroupGraphView.cs.meta b/Editor/Scripts/GraphEditor/GraphSystemGroupGraphView.cs.meta new file mode 100644 index 0000000..5641c14 --- /dev/null +++ b/Editor/Scripts/GraphEditor/GraphSystemGroupGraphView.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: f97b8c06cfa0cbf419fb8d65d1d397bd +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Editor/Scripts/GraphEditor/SystemNode.cs b/Editor/Scripts/GraphEditor/SystemNode.cs new file mode 100644 index 0000000..dd5d768 --- /dev/null +++ b/Editor/Scripts/GraphEditor/SystemNode.cs @@ -0,0 +1,9 @@ +using UnityEditor.Experimental.GraphView; + +namespace Software10101.DOTS.Editor.GraphEditor { + public class SystemNode : Node { + public Port SelfOutput; + public Port DependenciesInput; + public int? InstanceId; + } +} diff --git a/Editor/Scripts/GraphEditor/SystemNode.cs.meta b/Editor/Scripts/GraphEditor/SystemNode.cs.meta new file mode 100644 index 0000000..c1f412e --- /dev/null +++ b/Editor/Scripts/GraphEditor/SystemNode.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 4e277b0f831aa924d844b17037ab09e5 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Examples~/Hybrid Simulation Test Project/Assets/Scenes/Example.unity b/Examples~/Hybrid Simulation Test Project/Assets/Scenes/Example.unity index ba1af76..226483f 100644 --- a/Examples~/Hybrid Simulation Test Project/Assets/Scenes/Example.unity +++ b/Examples~/Hybrid Simulation Test Project/Assets/Scenes/Example.unity @@ -104,7 +104,7 @@ NavMeshSettings: serializedVersion: 2 m_ObjectHideFlags: 0 m_BuildSettings: - serializedVersion: 2 + serializedVersion: 3 agentTypeID: 0 agentRadius: 0.5 agentHeight: 2 @@ -117,7 +117,7 @@ NavMeshSettings: cellSize: 0.16666667 manualTileSize: 0 tileSize: 256 - accuratePlacement: 0 + buildHeightMesh: 0 maxJobWorkers: 0 preserveTilesOutsideBounds: 0 debug: @@ -149,6 +149,7 @@ Transform: m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} m_LocalPosition: {x: 0, y: 0, z: 0} m_LocalScale: {x: 1, y: 1, z: 1} + m_ConstrainProportionsScale: 0 m_Children: - {fileID: 550875472} - {fileID: 1990385108} @@ -185,9 +186,17 @@ SphereCollider: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 420832076} m_Material: {fileID: 0} + m_IncludeLayers: + serializedVersion: 2 + m_Bits: 0 + m_ExcludeLayers: + serializedVersion: 2 + m_Bits: 0 + m_LayerOverridePriority: 0 m_IsTrigger: 0 + m_ProvidesContacts: 0 m_Enabled: 1 - serializedVersion: 2 + serializedVersion: 3 m_Radius: 0.5 m_Center: {x: 0, y: 0, z: 0} --- !u!23 &420832078 @@ -201,6 +210,7 @@ MeshRenderer: m_CastShadows: 1 m_ReceiveShadows: 1 m_DynamicOccludee: 1 + m_StaticShadowCaster: 0 m_MotionVectors: 1 m_LightProbeUsage: 1 m_ReflectionProbeUsage: 2 @@ -249,6 +259,7 @@ Transform: m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} m_LocalPosition: {x: -1, y: 0, z: -1} m_LocalScale: {x: 1, y: 1, z: 1} + m_ConstrainProportionsScale: 0 m_Children: [] m_Father: {fileID: 267877101} m_RootOrder: 4 @@ -280,9 +291,17 @@ BoxCollider: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 550875468} m_Material: {fileID: 0} + m_IncludeLayers: + serializedVersion: 2 + m_Bits: 0 + m_ExcludeLayers: + serializedVersion: 2 + m_Bits: 0 + m_LayerOverridePriority: 0 m_IsTrigger: 0 + m_ProvidesContacts: 0 m_Enabled: 1 - serializedVersion: 2 + serializedVersion: 3 m_Size: {x: 1, y: 1.0000002, z: 0} m_Center: {x: 0, y: 0, z: 0} --- !u!23 &550875470 @@ -296,6 +315,7 @@ MeshRenderer: m_CastShadows: 1 m_ReceiveShadows: 1 m_DynamicOccludee: 1 + m_StaticShadowCaster: 0 m_MotionVectors: 1 m_LightProbeUsage: 1 m_ReflectionProbeUsage: 2 @@ -344,6 +364,7 @@ Transform: m_LocalRotation: {x: 0.7071068, y: -0, z: -0, w: 0.7071068} m_LocalPosition: {x: 0, y: 0, z: 0} m_LocalScale: {x: 5, y: 5, z: 5} + m_ConstrainProportionsScale: 0 m_Children: [] m_Father: {fileID: 267877101} m_RootOrder: 0 @@ -424,7 +445,9 @@ Canvas: m_OverrideSorting: 0 m_OverridePixelPerfect: 0 m_SortingBucketNormalizedSize: 0 + m_VertexColorAlwaysGammaSpace: 0 m_AdditionalShaderChannelsFlag: 0 + m_UpdateRectTransformForStandalone: 0 m_SortingLayerID: 0 m_SortingOrder: 0 m_TargetDisplay: 0 @@ -438,6 +461,7 @@ RectTransform: m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} m_LocalPosition: {x: 0, y: 0, z: 0} m_LocalScale: {x: 0, y: 0, z: 0} + m_ConstrainProportionsScale: 0 m_Children: - {fileID: 1568723653} m_Father: {fileID: 0} @@ -458,7 +482,6 @@ GameObject: m_Component: - component: {fileID: 899697410} - component: {fileID: 899697411} - - component: {fileID: 899697412} m_Layer: 0 m_Name: Simulation World m_TagString: Untagged @@ -476,6 +499,7 @@ Transform: m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} m_LocalPosition: {x: 0, y: 0, z: 0} m_LocalScale: {x: 1, y: 1, z: 1} + m_ConstrainProportionsScale: 0 m_Children: [] m_Father: {fileID: 0} m_RootOrder: 3 @@ -489,34 +513,35 @@ MonoBehaviour: m_GameObject: {fileID: 899697409} m_Enabled: 1 m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: b75e3d60c12d4d559cae47277faee063, type: 3} - m_Name: - m_EditorClassIdentifier: - _archetypeProducers: - - {fileID: 11400000, guid: 2edfc5aa963d22c4e8ea8e4795d2d3e8, type: 2} - _simulationResetSystems: [] - _mainSimulationSystems: - - {fileID: 11400000, guid: b55916dcf0ef8ed4a9c0aa675f60e447, type: 2} - _presentationPreUpdateSystems: - - {fileID: 11400000, guid: e8b4045ab457dba4f8c6c5031b4de4f7, type: 2} - - {fileID: 11400000, guid: a2c5f951bc7bf904cb32976be936ea2d, type: 2} - _presentationPostUpdateSystems: - - {fileID: 11400000, guid: e01661ff769361b4b937408c043acd78, type: 2} - _endOfFrameSystems: [] - EntitiesToGenerate: 2000 - SpeedMultiplier: 1 ---- !u!114 &899697412 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 899697409} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: c0c5bf2b9a434df5a83972fc29185f0a, type: 3} + m_Script: {fileID: 11500000, guid: b5f4b11a5ba74433a17c73d9bc92c177, type: 3} m_Name: m_EditorClassIdentifier: + _flags: 5 + _simResetGroup: + Nodes: + - SystemReference: {fileID: 0} + NodePosition: {x: 0, y: 0} + Dependencies: [] + _mainSimGroup: + Nodes: + - SystemReference: {fileID: 0} + NodePosition: {x: 0, y: 0} + Dependencies: [] + _presentationPreUpdateGroup: + Nodes: + - SystemReference: {fileID: 0} + NodePosition: {x: 0, y: 0} + Dependencies: [] + _presentationPostUpdateGroup: + Nodes: + - SystemReference: {fileID: 0} + NodePosition: {x: 0, y: 0} + Dependencies: [] + _endOfFrameGroup: + Nodes: + - SystemReference: {fileID: 0} + NodePosition: {x: 0, y: 0} + Dependencies: [] --- !u!1 &993198345 GameObject: m_ObjectHideFlags: 0 @@ -527,6 +552,7 @@ GameObject: m_Component: - component: {fileID: 993198347} - component: {fileID: 993198346} + - component: {fileID: 993198348} m_Layer: 0 m_Name: Directional Light m_TagString: Untagged @@ -606,10 +632,34 @@ Transform: m_LocalRotation: {x: 0.40821788, y: -0.23456968, z: 0.10938163, w: 0.8754261} m_LocalPosition: {x: 0, y: 10, z: 0} m_LocalScale: {x: 1, y: 1, z: 1} + m_ConstrainProportionsScale: 0 m_Children: [] m_Father: {fileID: 0} m_RootOrder: 1 m_LocalEulerAnglesHint: {x: 50, y: -30, z: 0} +--- !u!114 &993198348 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 993198345} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 474bcb49853aa07438625e644c072ee6, type: 3} + m_Name: + m_EditorClassIdentifier: + m_Version: 3 + m_UsePipelineSettings: 1 + m_AdditionalLightsShadowResolutionTier: 2 + m_LightLayerMask: 1 + m_RenderingLayers: 1 + m_CustomShadowLayers: 0 + m_ShadowLayerMask: 1 + m_ShadowRenderingLayers: 1 + m_LightCookieSize: {x: 1, y: 1} + m_LightCookieOffset: {x: 0, y: 0} + m_SoftShadowQuality: 0 --- !u!1 &1317645711 GameObject: m_ObjectHideFlags: 0 @@ -638,6 +688,7 @@ Transform: m_LocalRotation: {x: 0.066452265, y: -0.9098438, z: 0.16042997, w: 0.37686962} m_LocalPosition: {x: 6.75, y: 4, z: 6.75} m_LocalScale: {x: 1, y: 1, z: 1} + m_ConstrainProportionsScale: 0 m_Children: [] m_Father: {fileID: 0} m_RootOrder: 0 @@ -672,9 +723,20 @@ MonoBehaviour: m_Dithering: 0 m_ClearDepth: 1 m_AllowXRRendering: 1 + m_AllowHDROutput: 1 + m_UseScreenCoordOverride: 0 + m_ScreenSizeOverride: {x: 0, y: 0, z: 0, w: 0} + m_ScreenCoordScaleBias: {x: 0, y: 0, z: 0, w: 0} m_RequiresDepthTexture: 0 m_RequiresColorTexture: 0 m_Version: 2 + m_TaaSettings: + quality: 3 + frameInfluence: 0.1 + jitterScale: 1 + mipBias: 0 + varianceClampScale: 0.9 + contrastAdaptiveSharpening: 0 --- !u!20 &1317645714 Camera: m_ObjectHideFlags: 0 @@ -689,9 +751,17 @@ Camera: m_projectionMatrixMode: 1 m_GateFitMode: 2 m_FOVAxisMode: 0 + m_Iso: 200 + m_ShutterSpeed: 0.005 + m_Aperture: 16 + m_FocusDistance: 10 + m_FocalLength: 50 + m_BladeCount: 5 + m_Curvature: {x: 2, y: 11} + m_BarrelClipping: 0.25 + m_Anamorphism: 0 m_SensorSize: {x: 36, y: 24} m_LensShift: {x: 0, y: 0} - m_FocalLength: 50 m_NormalizedViewPortRect: serializedVersion: 2 x: 0 @@ -748,6 +818,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 01614664b831546d2ae94a42149d80ac, type: 3} m_Name: m_EditorClassIdentifier: + m_SendPointerHoverToParent: 1 m_MoveRepeatDelay: 0.5 m_MoveRepeatRate: 0.1 m_XRTrackingOrigin: {fileID: 0} @@ -764,6 +835,7 @@ MonoBehaviour: m_TrackedDeviceOrientationAction: {fileID: 1025543830046995696, guid: ca9f5fa95ffab41fb9a615ab714db018, type: 3} m_DeselectOnBackgroundClick: 1 m_PointerBehavior: 0 + m_CursorLockBehavior: 0 --- !u!114 &1325820873 MonoBehaviour: m_ObjectHideFlags: 0 @@ -789,6 +861,7 @@ Transform: m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} m_LocalPosition: {x: 0, y: 0, z: 0} m_LocalScale: {x: 1, y: 1, z: 1} + m_ConstrainProportionsScale: 0 m_Children: [] m_Father: {fileID: 0} m_RootOrder: 5 @@ -821,6 +894,7 @@ RectTransform: m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} m_LocalPosition: {x: 0, y: 0, z: 0} m_LocalScale: {x: 1, y: 1, z: 1} + m_ConstrainProportionsScale: 0 m_Children: [] m_Father: {fileID: 1568723653} m_RootOrder: 0 @@ -902,6 +976,7 @@ RectTransform: m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} m_LocalPosition: {x: 0, y: 0, z: 0} m_LocalScale: {x: 1, y: 1, z: 1} + m_ConstrainProportionsScale: 0 m_Children: - {fileID: 1427008782} m_Father: {fileID: 719490233} @@ -1045,9 +1120,17 @@ SphereCollider: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 1806501350} m_Material: {fileID: 0} + m_IncludeLayers: + serializedVersion: 2 + m_Bits: 0 + m_ExcludeLayers: + serializedVersion: 2 + m_Bits: 0 + m_LayerOverridePriority: 0 m_IsTrigger: 0 + m_ProvidesContacts: 0 m_Enabled: 1 - serializedVersion: 2 + serializedVersion: 3 m_Radius: 0.5 m_Center: {x: 0, y: 0, z: 0} --- !u!23 &1806501352 @@ -1061,6 +1144,7 @@ MeshRenderer: m_CastShadows: 1 m_ReceiveShadows: 1 m_DynamicOccludee: 1 + m_StaticShadowCaster: 0 m_MotionVectors: 1 m_LightProbeUsage: 1 m_ReflectionProbeUsage: 2 @@ -1109,6 +1193,7 @@ Transform: m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} m_LocalPosition: {x: 1, y: 0, z: -1} m_LocalScale: {x: 1, y: 1, z: 1} + m_ConstrainProportionsScale: 0 m_Children: [] m_Father: {fileID: 267877101} m_RootOrder: 3 @@ -1140,9 +1225,17 @@ SphereCollider: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 1838541128} m_Material: {fileID: 0} + m_IncludeLayers: + serializedVersion: 2 + m_Bits: 0 + m_ExcludeLayers: + serializedVersion: 2 + m_Bits: 0 + m_LayerOverridePriority: 0 m_IsTrigger: 0 + m_ProvidesContacts: 0 m_Enabled: 1 - serializedVersion: 2 + serializedVersion: 3 m_Radius: 0.5 m_Center: {x: 0, y: 0, z: 0} --- !u!23 &1838541130 @@ -1156,6 +1249,7 @@ MeshRenderer: m_CastShadows: 1 m_ReceiveShadows: 1 m_DynamicOccludee: 1 + m_StaticShadowCaster: 0 m_MotionVectors: 1 m_LightProbeUsage: 1 m_ReflectionProbeUsage: 2 @@ -1204,6 +1298,7 @@ Transform: m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} m_LocalPosition: {x: 1, y: 0, z: 1} m_LocalScale: {x: 1, y: 1, z: 1} + m_ConstrainProportionsScale: 0 m_Children: [] m_Father: {fileID: 267877101} m_RootOrder: 2 @@ -1235,9 +1330,17 @@ SphereCollider: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 1990385104} m_Material: {fileID: 0} + m_IncludeLayers: + serializedVersion: 2 + m_Bits: 0 + m_ExcludeLayers: + serializedVersion: 2 + m_Bits: 0 + m_LayerOverridePriority: 0 m_IsTrigger: 0 + m_ProvidesContacts: 0 m_Enabled: 1 - serializedVersion: 2 + serializedVersion: 3 m_Radius: 0.5 m_Center: {x: 0, y: 0, z: 0} --- !u!23 &1990385106 @@ -1251,6 +1354,7 @@ MeshRenderer: m_CastShadows: 1 m_ReceiveShadows: 1 m_DynamicOccludee: 1 + m_StaticShadowCaster: 0 m_MotionVectors: 1 m_LightProbeUsage: 1 m_ReflectionProbeUsage: 2 @@ -1299,6 +1403,7 @@ Transform: m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} m_LocalPosition: {x: -1, y: 0, z: 1} m_LocalScale: {x: 1, y: 1, z: 1} + m_ConstrainProportionsScale: 0 m_Children: [] m_Father: {fileID: 267877101} m_RootOrder: 1 diff --git a/Examples~/Hybrid Simulation Test Project/Assets/Scripts/MonoBehaviours/GameBootstrapper.cs b/Examples~/Hybrid Simulation Test Project/Assets/Scripts/MonoBehaviours/GameBootstrapper.cs deleted file mode 100644 index 6c1ae2b..0000000 --- a/Examples~/Hybrid Simulation Test Project/Assets/Scripts/MonoBehaviours/GameBootstrapper.cs +++ /dev/null @@ -1,25 +0,0 @@ -using Software10101.DOTS.Example.Data; -using Software10101.DOTS.MonoBehaviours; -using Unity.Entities; -using Unity.Mathematics; - -namespace Software10101.DOTS.Example.MonoBehaviours { - public class GameBootstrapper : Bootstrapper { - public ushort EntitiesToGenerate = 1; - public float SpeedMultiplier = 1.0f; - - protected override void Start() { - base.Start(); - - Random r = new Random(); - r.InitState(); - - for (ushort i = 0; i < EntitiesToGenerate; i++) { - (Entity entity, EntityCommandBuffer ecb) = Create(0); - ecb.SetComponent(entity, new VelocityComponentData { - Value = SpeedMultiplier * math.normalize(2.0f * (r.NextFloat3() - 0.5f)) * r.NextFloat() - }); - } - } - } -} diff --git a/Examples~/Hybrid Simulation Test Project/Assets/Scripts/MonoBehaviours/GameBootstrapper.cs.meta b/Examples~/Hybrid Simulation Test Project/Assets/Scripts/MonoBehaviours/GameBootstrapper.cs.meta deleted file mode 100644 index 9d4b3c9..0000000 --- a/Examples~/Hybrid Simulation Test Project/Assets/Scripts/MonoBehaviours/GameBootstrapper.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: b75e3d60c12d4d559cae47277faee063 -timeCreated: 1587167901 \ No newline at end of file diff --git a/Examples~/Hybrid Simulation Test Project/Assets/Scripts/MonoBehaviours/TestEntityBehaviour.cs b/Examples~/Hybrid Simulation Test Project/Assets/Scripts/MonoBehaviours/TestEntityBehaviour.cs deleted file mode 100644 index dca6c01..0000000 --- a/Examples~/Hybrid Simulation Test Project/Assets/Scripts/MonoBehaviours/TestEntityBehaviour.cs +++ /dev/null @@ -1,24 +0,0 @@ -using Software10101.DOTS.Example.Data; -using Software10101.DOTS.MonoBehaviours; -using Unity.Entities; -using UnityEngine; - -namespace Software10101.DOTS.Example.MonoBehaviours { - public class TestEntityBehaviour : EntityMonoBehaviour { - public bool DestroyMe = false; - - protected override void OnUpdate() { - base.OnUpdate(); - - transform.localPosition = EntityManager.GetComponentData(Entity).PresentationValue; - - if (DestroyMe) { - if (Entity == Entity.Null) { - Debug.LogWarning($"{name} has a null entity when trying to be destroyed!"); - } - - Bootstrapper.Destroy(Entity); - } - } - } -} diff --git a/Examples~/Hybrid Simulation Test Project/Assets/Scripts/MonoBehaviours/TestEntityBehaviour.cs.meta b/Examples~/Hybrid Simulation Test Project/Assets/Scripts/MonoBehaviours/TestEntityBehaviour.cs.meta deleted file mode 100644 index 9843699..0000000 --- a/Examples~/Hybrid Simulation Test Project/Assets/Scripts/MonoBehaviours/TestEntityBehaviour.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: 375e5906166d43e7adbd77db74139c2c -timeCreated: 1586819145 \ No newline at end of file diff --git a/Examples~/Hybrid Simulation Test Project/Assets/Scripts/Systems/SharedValueSystemReference.cs b/Examples~/Hybrid Simulation Test Project/Assets/Scripts/Systems/SharedValueSystemReference.cs index 626036d..0294348 100644 --- a/Examples~/Hybrid Simulation Test Project/Assets/Scripts/Systems/SharedValueSystemReference.cs +++ b/Examples~/Hybrid Simulation Test Project/Assets/Scripts/Systems/SharedValueSystemReference.cs @@ -12,11 +12,11 @@ public class SharedValueSystemReference : SystemTypeReference // ReSharper disable once RedundantExtendsListEntry public partial class SharedValueSystem : ReferenceCreatedSystemBase { protected override void OnUpdate() { - NativeReference nativeReference = new NativeReference(0, Allocator.TempJob); + NativeReference nativeReference = new(0, Allocator.TempJob); // do something to populate the value Entities - .ForEach((in PositionComponentData component) => { + .ForEach((in PositionComponentData _) => { nativeReference.Value++; }) .Schedule(); diff --git a/Examples~/Hybrid Simulation Test Project/ProjectSettings/PackageManagerSettings.asset b/Examples~/Hybrid Simulation Test Project/ProjectSettings/PackageManagerSettings.asset index bad0c21..d99e9e2 100644 --- a/Examples~/Hybrid Simulation Test Project/ProjectSettings/PackageManagerSettings.asset +++ b/Examples~/Hybrid Simulation Test Project/ProjectSettings/PackageManagerSettings.asset @@ -12,11 +12,11 @@ MonoBehaviour: m_Script: {fileID: 13964, guid: 0000000000000000e000000000000000, type: 0} m_Name: m_EditorClassIdentifier: - m_EnablePreReleasePackages: 1 - m_EnablePackageDependencies: 0 + m_EnablePreReleasePackages: 0 m_AdvancedSettingsExpanded: 1 m_ScopedRegistriesSettingsExpanded: 1 m_SeeAllPackageVersions: 0 + m_DismissPreviewPackagesInUse: 0 oneTimeWarningShown: 1 m_Registries: - m_Id: main @@ -31,6 +31,6 @@ MonoBehaviour: m_RegistryInfoDraft: m_Modified: 0 m_ErrorMessage: - m_UserModificationsInstanceId: -826 - m_OriginalInstanceId: -828 + m_UserModificationsInstanceId: -852 + m_OriginalInstanceId: -854 m_LoadAssets: 0 diff --git a/Examples~/Hybrid Simulation Test Project/ProjectSettings/ProjectSettings.asset b/Examples~/Hybrid Simulation Test Project/ProjectSettings/ProjectSettings.asset index 9f3e5e5..959df16 100644 --- a/Examples~/Hybrid Simulation Test Project/ProjectSettings/ProjectSettings.asset +++ b/Examples~/Hybrid Simulation Test Project/ProjectSettings/ProjectSettings.asset @@ -3,7 +3,7 @@ --- !u!129 &1 PlayerSettings: m_ObjectHideFlags: 0 - serializedVersion: 23 + serializedVersion: 26 productGUID: 64ee7c0f4a3065e409995cb0ef3617f3 AndroidProfiler: 0 AndroidFilterTouchesWhenObscured: 0 @@ -48,14 +48,15 @@ PlayerSettings: defaultScreenHeightWeb: 600 m_StereoRenderingPath: 0 m_ActiveColorSpace: 1 + m_SpriteBatchVertexThreshold: 300 m_MTRendering: 1 mipStripping: 0 numberOfMipsStripped: 0 + numberOfMipsStrippedPerMipmapLimitGroup: {} m_StackTraceTypes: 010000000100000001000000010000000100000001000000 iosShowActivityIndicatorOnLoading: -1 androidShowActivityIndicatorOnLoading: -1 iosUseCustomAppBackgroundBehavior: 0 - iosAllowHTTPDownload: 1 allowedAutorotateToPortrait: 1 allowedAutorotateToPortraitUpsideDown: 1 allowedAutorotateToLandscapeRight: 1 @@ -119,8 +120,11 @@ PlayerSettings: switchNVNShaderPoolsGranularity: 33554432 switchNVNDefaultPoolsGranularity: 16777216 switchNVNOtherPoolsGranularity: 16777216 + switchGpuScratchPoolGranularity: 2097152 + switchAllowGpuScratchShrinking: 0 switchNVNMaxPublicTextureIDCount: 0 switchNVNMaxPublicSamplerIDCount: 0 + switchNVNGraphicsFirmwareMemory: 32 stadiaPresentMode: 0 stadiaTargetFramerate: 0 vulkanNumSwapchainBuffers: 3 @@ -128,12 +132,7 @@ PlayerSettings: vulkanEnablePreTransform: 0 vulkanEnableLateAcquireNextImage: 0 vulkanEnableCommandBufferRecycling: 1 - m_SupportedAspectRatios: - 4:3: 1 - 5:4: 1 - 16:10: 1 - 16:9: 1 - Others: 1 + loadStoreDebugModeEnabled: 0 bundleVersion: 1.0 preloadedAssets: [] metroInputSource: 0 @@ -147,7 +146,7 @@ PlayerSettings: enableFrameTimingStats: 1 enableOpenGLProfilerGPURecorders: 1 useHDRDisplay: 0 - D3DHDRBitDepth: 0 + hdrBitDepth: 0 m_ColorGamuts: 0000000003000000 targetPixelDensity: 30 resolutionScalingMode: 0 @@ -157,6 +156,7 @@ PlayerSettings: applicationIdentifier: Standalone: com.10101-Software.Hybrid-Simulation-Test-Project buildNumber: + Bratwurst: 0 Standalone: 0 iPhone: 0 tvOS: 0 @@ -175,12 +175,15 @@ PlayerSettings: APKExpansionFiles: 0 keepLoadedShadersAlive: 0 StripUnusedMeshComponents: 0 + strictShaderVariantMatching: 0 VertexChannelCompressionMask: 4054 iPhoneSdkVersion: 988 - iOSTargetOSVersionString: 11.0 + iOSTargetOSVersionString: 12.0 tvOSSdkVersion: 0 tvOSRequireExtendedGameController: 0 - tvOSTargetOSVersionString: 11.0 + tvOSTargetOSVersionString: 12.0 + bratwurstSdkVersion: 0 + bratwurstTargetOSVersionString: 16.4 uIPrerenderedIcon: 0 uIRequiresPersistentWiFi: 0 uIRequiresFullScreen: 1 @@ -228,8 +231,10 @@ PlayerSettings: appleDeveloperTeamID: iOSManualSigningProvisioningProfileID: tvOSManualSigningProvisioningProfileID: + bratwurstManualSigningProvisioningProfileID: iOSManualSigningProvisioningProfileType: 0 tvOSManualSigningProvisioningProfileType: 0 + bratwurstManualSigningProvisioningProfileType: 0 appleEnableAutomaticSigning: 0 iOSRequireARKit: 0 iOSAutomaticallyDetectAndAddCapabilities: 1 @@ -244,6 +249,7 @@ PlayerSettings: useCustomLauncherGradleManifest: 0 useCustomBaseGradleTemplate: 0 useCustomGradlePropertiesTemplate: 0 + useCustomGradleSettingsTemplate: 0 useCustomProguardFile: 0 AndroidTargetArchitectures: 1 AndroidTargetDevices: 0 @@ -251,6 +257,7 @@ PlayerSettings: androidSplashScreen: {fileID: 0} AndroidKeystoreName: AndroidKeyaliasName: + AndroidEnableArmv9SecurityFeatures: 0 AndroidBuildApkPerCpuArchitecture: 0 AndroidTVCompatibility: 0 AndroidIsGame: 1 @@ -264,7 +271,6 @@ PlayerSettings: banner: {fileID: 0} androidGamepadSupportLevel: 0 chromeosInputEmulation: 1 - AndroidMinifyWithR8: 0 AndroidMinifyRelease: 0 AndroidMinifyDebug: 0 AndroidValidateAppBundleSize: 1 @@ -287,6 +293,7 @@ PlayerSettings: - m_BuildTarget: WebGL m_StaticBatching: 0 m_DynamicBatching: 0 + m_BuildTargetShaderSettings: [] m_BuildTargetGraphicsJobs: - m_BuildTarget: MacStandaloneSupport m_GraphicsJobs: 0 @@ -333,7 +340,7 @@ PlayerSettings: m_APIs: 0b000000 m_Automatic: 0 - m_BuildTarget: WindowsStandaloneSupport - m_APIs: 1500000002000000 + m_APIs: 150000001200000002000000 m_Automatic: 0 - m_BuildTarget: MacStandaloneSupport m_APIs: 10000000 @@ -342,6 +349,8 @@ PlayerSettings: m_APIs: 1500000011000000 m_Automatic: 0 m_BuildTargetVRSettings: [] + m_DefaultShaderChunkSizeInMB: 16 + m_DefaultShaderChunkCount: 0 openGLRequireES31: 0 openGLRequireES31AEP: 0 openGLRequireES32: 0 @@ -353,10 +362,14 @@ PlayerSettings: m_BuildTargetGroupLightmapEncodingQuality: - m_BuildTarget: Standalone m_EncodingQuality: 0 + m_BuildTargetGroupHDRCubemapEncodingQuality: + - m_BuildTarget: Standalone + m_EncodingQuality: 2 m_BuildTargetGroupLightmapSettings: - m_BuildTarget: Standalone m_TextureStreamingEnabled: 0 m_TextureStreamingPriority: 0 + m_BuildTargetGroupLoadStoreDebugModeSettings: [] m_BuildTargetNormalMapEncoding: [] m_BuildTargetDefaultTextureCompressionFormat: [] playModeTestRunnerEnabled: 0 @@ -369,6 +382,7 @@ PlayerSettings: locationUsageDescription: microphoneUsageDescription: bluetoothUsageDescription: + macOSTargetOSVersion: 10.13.0 switchNMETAOverride: switchNetLibKey: switchSocketMemoryPoolSize: 6144 @@ -380,6 +394,7 @@ PlayerSettings: switchLTOSetting: 0 switchApplicationID: 0x01004b9000490000 switchNSODependencies: + switchCompilerFlags: switchTitleNames_0: switchTitleNames_1: switchTitleNames_2: @@ -453,7 +468,6 @@ PlayerSettings: switchReleaseVersion: 0 switchDisplayVersion: 1.0.0 switchStartupUserAccount: 0 - switchTouchScreenUsage: 0 switchSupportedLanguagesMask: 0 switchLogoType: 0 switchApplicationErrorCodeCategory: @@ -495,6 +509,7 @@ PlayerSettings: switchNativeFsCacheSize: 32 switchIsHoldTypeHorizontal: 0 switchSupportedNpadCount: 8 + switchEnableTouchScreen: 1 switchSocketConfigEnabled: 0 switchTcpInitialSendBufferSize: 32 switchTcpInitialReceiveBufferSize: 64 @@ -507,6 +522,7 @@ PlayerSettings: switchNetworkInterfaceManagerInitializeEnabled: 1 switchPlayerConnectionEnabled: 1 switchUseNewStyleFilepaths: 0 + switchUseLegacyFmodPriorities: 0 switchUseMicroSleepForYield: 1 switchEnableRamDiskSupport: 0 switchMicroSleepForYieldTime: 25 @@ -581,6 +597,7 @@ PlayerSettings: ps4videoRecordingFeaturesUsed: 0 ps4contentSearchFeaturesUsed: 0 ps4CompatibilityPS5: 0 + ps4AllowPS5Detection: 0 ps4GPU800MHz: 1 ps4attribEyeToEyeDistanceSettingVR: 0 ps4IncludedModules: [] @@ -593,6 +610,7 @@ PlayerSettings: webGLMemorySize: 16 webGLExceptionSupport: 1 webGLNameFilesAsHashes: 0 + webGLShowDiagnostics: 0 webGLDataCaching: 1 webGLDebugSymbols: 0 webGLEmscriptenArgs: @@ -605,22 +623,42 @@ PlayerSettings: webGLLinkerTarget: 1 webGLThreadsSupport: 0 webGLDecompressionFallback: 0 + webGLInitialMemorySize: 32 + webGLMaximumMemorySize: 2048 + webGLMemoryGrowthMode: 2 + webGLMemoryLinearGrowthStep: 16 + webGLMemoryGeometricGrowthStep: 0.2 + webGLMemoryGeometricGrowthCap: 96 + webGLPowerPreference: 2 scriptingDefineSymbols: Standalone: UNITY_DISABLE_AUTOMATIC_SYSTEM_BOOTSTRAP additionalCompilerArguments: {} platformArchitecture: {} scriptingBackend: {} il2cppCompilerConfiguration: {} - managedStrippingLevel: {} + il2cppCodeGeneration: {} + managedStrippingLevel: + Bratwurst: 1 + EmbeddedLinux: 1 + GameCoreScarlett: 1 + GameCoreXboxOne: 1 + Nintendo Switch: 1 + PS4: 1 + PS5: 1 + QNX: 1 + Stadia: 1 + WebGL: 1 + Windows Store Apps: 1 + XboxOne: 1 + iPhone: 1 + tvOS: 1 incrementalIl2cppBuild: {} suppressCommonWarnings: 1 allowUnsafeCode: 0 useDeterministicCompilation: 1 - enableRoslynAnalyzers: 1 additionalIl2CppArgs: scriptingRuntimeVersion: 1 gcIncremental: 1 - assemblyVersionValidation: 1 gcWBarrierValidation: 0 apiCompatibilityLevelPerPlatform: {} m_RenderingPath: 1 @@ -693,8 +731,14 @@ PlayerSettings: luminVersion: m_VersionCode: 1 m_VersionName: + hmiPlayerDataPath: + hmiForceSRGBBlit: 1 + embeddedLinuxEnableGamepadInput: 1 + hmiLogStartupTiming: 0 + hmiCpuConfiguration: apiCompatibilityLevel: 6 activeInputHandler: 1 + windowsGamepadBackendHint: 0 cloudProjectId: framebufferDepthMemorylessMode: 0 qualitySettingsNames: [] @@ -702,6 +746,7 @@ PlayerSettings: organizationId: cloudEnabled: 0 legacyClampBlendShapeWeights: 0 - playerDataPath: - forceSRGBBlit: 1 + hmiLoadingImage: {fileID: 0} + platformRequiresReadableAssets: 0 virtualTexturingSupportEnabled: 0 + insecureHttpOption: 0 diff --git a/Folder.DotSettings.user b/Folder.DotSettings.user new file mode 100644 index 0000000..0692e19 --- /dev/null +++ b/Folder.DotSettings.user @@ -0,0 +1,2 @@ + + ForceIncluded \ No newline at end of file diff --git a/Folder.DotSettings.user.meta b/Folder.DotSettings.user.meta new file mode 100644 index 0000000..73cd65e --- /dev/null +++ b/Folder.DotSettings.user.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 7478a1fce856ffc4183b9e32165817fe +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Scripts/10101Software.DOTS.HybridSimulation.asmdef b/Runtime/Scripts/10101Software.DOTS.HybridSimulation.asmdef index 3abf354..75d4158 100644 --- a/Runtime/Scripts/10101Software.DOTS.HybridSimulation.asmdef +++ b/Runtime/Scripts/10101Software.DOTS.HybridSimulation.asmdef @@ -4,7 +4,8 @@ "references": [ "GUID:734d92eba21c94caba915361bd5ac177", "GUID:e0cd26848372d4e5c891c569017e11f1", - "GUID:2665a8d13d1b3f18800f46e256720795" + "GUID:2665a8d13d1b3f18800f46e256720795", + "GUID:d8b63aba1907145bea998dd612889d6b" ], "includePlatforms": [], "excludePlatforms": [], diff --git a/Runtime/Scripts/MonoBehaviours/Bootstrapper.cs b/Runtime/Scripts/MonoBehaviours/Bootstrapper.cs deleted file mode 100644 index f4e76b7..0000000 --- a/Runtime/Scripts/MonoBehaviours/Bootstrapper.cs +++ /dev/null @@ -1,232 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Reflection; -using Software10101.DOTS.Archetypes; -using Software10101.DOTS.Data; -using Software10101.DOTS.Systems; -using Software10101.DOTS.Systems.EntityCommandBufferSystems; -using Software10101.DOTS.Systems.Groups; -using Unity.Entities; -using UnityEngine; -using UnityEngine.PlayerLoop; -using UnityEngine.Serialization; - -namespace Software10101.DOTS.MonoBehaviours { - /// - /// The purpose of this class is to enable DOTS configuration from the inspector. - /// - /// Each instance of this class contains it's own world. - /// - /// This system handles simulation and presentation a little differently than the default Unity world: - /// * Simulation systems are run during Unity's FixedUpdate. Presentation still runs during Update so there are utilities - /// and examples that demonstrate how to render an interpolated simulation state. - /// * The top level system groups are not sorted using UpdateAfter/UpdateBefore annotations. Instead they execute in the - /// order configured in the inspector. Other groups can be sorted using those annotations if you want. - /// - /// Systems are set up to do presentation using GameObjects. Your custom Components should inherit from EntityMonoBehaviour - /// instead of MonoBehaviour. - /// - /// Prefabs and EntityArchetypes are managed in this class as well. Utility methods for creation and destruction are provided - /// to ease the management of the simulation and presentation sides of an object. - /// - /// This class can be extended. Place your custom world bootstrapping code into a Start() override AFTER base.Start() is - /// called. (see example) - /// - public class Bootstrapper : WorldBehaviour { - [FormerlySerializedAs("_prefabs")] - [SerializeField] - private List _archetypeProducers = null; - private readonly List _archetypes = new List(); - private readonly Dictionary _archetypeProducerIndices = new Dictionary(); - - [Tooltip("Systems that execute before each simulation tick. (executed 0-n times per frame)")] - [SerializeField] - private SystemTypeReference[] _simulationResetSystems = Array.Empty(); - - [Tooltip("Systems that execute during each simulation tick. (executed 0-n times per frame)")] - [FormerlySerializedAs("_simulationSystems")] - [SerializeField] - private SystemTypeReference[] _mainSimulationSystems = Array.Empty(); - - [Tooltip("Systems that execute before the ManagedMonoBehaviours. (executed once per frame)")] - [FormerlySerializedAs("_presentationSystems")] - [SerializeField] - private SystemTypeReference[] _presentationPreUpdateSystems = Array.Empty(); - - [Tooltip("Systems that execute after the ManagedMonoBehaviours. (executed once per frame)")] - [SerializeField] - private SystemTypeReference[] _presentationPostUpdateSystems = Array.Empty(); - - [Tooltip("Systems that execute at the end of each frame. Useful for systems that serialize the world. (executed once per frame)")] - [SerializeField] - private SystemTypeReference[] _endOfFrameSystems = Array.Empty(); - - protected virtual void Start() { - // set up initialization group - // ReSharper disable once UnusedVariable // not used by the bootstrapper but is one of Unity's root system groups - InitializationSystemGroup initGroup = AddSystem(typeof(Initialization), new InitializationSystemGroup()); - SetSystemSortingEnabled(initGroup, false); - - // set up simulation systems - SimulationSystemGroup simGroup = AddSystem(typeof(FixedUpdate), new SimulationSystemGroup()); - SetSystemSortingEnabled(simGroup, false); - { - AddSystem(simGroup, new SimulationDestroySystem()); - - SimulationResetSystemGroup simResetGroup = AddSystem(simGroup, new SimulationResetSystemGroup()); - SetSystemSortingEnabled(simResetGroup, false); - { - foreach (SystemTypeReference systemTypeReference in _simulationResetSystems) { - GetOrCreateSystemInternal(simResetGroup, systemTypeReference.SystemType) - .SetCreator(systemTypeReference); - } - } - - AddSystem(simGroup, new PreSimulationEntityCommandBufferSystem()); - - SimulationMainSystemGroup simMainGroup = AddSystem(simGroup, new SimulationMainSystemGroup()); - SetSystemSortingEnabled(simMainGroup, false); - { - foreach (SystemTypeReference systemTypeReference in _mainSimulationSystems) { - GetOrCreateSystemInternal(simMainGroup, systemTypeReference.SystemType) - .SetCreator(systemTypeReference); - } - } - - AddSystem(simGroup, new PostSimulationEntityCommandBufferSystem()); - } - - // UI interactions happen before the presentation group - - // set up presentation systems - PresentationSystemGroup presGroup = AddSystem(typeof(Update), new PresentationSystemGroup()); - SetSystemSortingEnabled(presGroup, false); - { - AddSystem(presGroup, new PrePresentationEntityCommandBufferSystem()); - - PresentationPreUpdateSystemGroup presPreUpdateGroup = AddSystem(presGroup, new PresentationPreUpdateSystemGroup()); - SetSystemSortingEnabled(presPreUpdateGroup, false); - { - foreach (SystemTypeReference systemTypeReference in _presentationPreUpdateSystems) { - GetOrCreateSystemInternal(presPreUpdateGroup, systemTypeReference.SystemType) - .SetCreator(systemTypeReference); - } - } - - AddSystem(presGroup, new PreManagedMonoBehaviourUpdateEntityCommandBufferSystem()); - AddSystem(presGroup, new ManagedMonoBehaviourUpdateSystem()); - AddSystem(presGroup, new PostManagedMonoBehaviourUpdateEntityCommandBufferSystem()); - - PresentationPostUpdateSystemGroup presPostUpdateGroup = AddSystem(presGroup, new PresentationPostUpdateSystemGroup()); - SetSystemSortingEnabled(presPostUpdateGroup, false); - { - foreach (SystemTypeReference systemTypeReference in _presentationPostUpdateSystems) { - GetOrCreateSystemInternal(presPostUpdateGroup, systemTypeReference.SystemType) - .SetCreator(systemTypeReference); - } - } - - AddSystem(presGroup, new PostPresentationEntityCommandBufferSystem()); - - AddSystem(presGroup, new PresentationDestroySystem()); - AddSystem(presGroup, new PrefabSpawnSystem(this)); - - AddSystem(presGroup, new EndOfFrameEntityCommandBufferSystem()); - - EndOfFrameSystemGroup endOfFrameGroup = AddSystem(presGroup, new EndOfFrameSystemGroup()); - SetSystemSortingEnabled(endOfFrameGroup, false); - { - foreach (SystemTypeReference systemTypeReference in _endOfFrameSystems) { - GetOrCreateSystemInternal(endOfFrameGroup, systemTypeReference.SystemType) - .SetCreator(systemTypeReference); - } - } - } - - // set up archetypes - ArchetypeProducer[] initialArchetypeProducers = _archetypeProducers.ToArray(); - _archetypeProducers.Clear(); - - foreach (ArchetypeProducer archetypeProducer in initialArchetypeProducers) { - AddArchetypeProducer(archetypeProducer); - } - } - - public int AddArchetypeProducer(ArchetypeProducer archetypeProducer) { - if (_archetypeProducerIndices.TryGetValue(archetypeProducer, out int index)) { - return index; - } - - index = _archetypes.Count; - _archetypes.Add(archetypeProducer.Produce(EntityManager)); - _archetypeProducers.Add(archetypeProducer); - _archetypeProducerIndices[archetypeProducer] = index; - return index; - } - - internal EntityMonoBehaviour GetPrefab(int prefabIndex) { - return _archetypeProducers[prefabIndex].Prefab; - } - - public (Entity, EntityCommandBuffer) Create( - ArchetypeProducer archetypeProducer, - CreationBufferToken creationBufferToken = null) { - - return Create(_archetypeProducerIndices[archetypeProducer], creationBufferToken); - } - - public (Entity, EntityCommandBuffer) Create(int prefabIndex, CreationBufferToken creationBufferToken = null) { - EntityCommandBuffer ecb = creationBufferToken?.EntityCommandBuffer - ?? GetExistingSystem() - .CreateCommandBuffer(); - - Entity entity = ecb.CreateEntity(_archetypes[prefabIndex]); - ecb.AddComponent(entity, new SpawnPrefabComponentData { - PrefabIndex = prefabIndex - }); - - return (entity, ecb); - } - - public void Destroy(Entity entity) { - EntityCommandBuffer ecb = - GetExistingSystem().CreateCommandBuffer(); - ecb.AddComponent(entity, new DestroyFlagComponentData()); - } - - public CreationBufferToken GetCreationBufferToken() { - return new CreationBufferToken { - EntityCommandBuffer = - GetExistingSystem().CreateCommandBuffer() - }; - } - - public class CreationBufferToken { - internal EntityCommandBuffer EntityCommandBuffer; - - internal CreationBufferToken() { } - } - - /// - /// This reflection helper needed because the setter on is - /// protected. - /// - private static void SetSystemSortingEnabled(ComponentSystemGroup group, bool enabled) { - const string propertyName = "EnableSystemSorting"; - - PropertyInfo enableSystemSortingPropertyInfo = group.GetType() - .GetProperty(propertyName)! - .DeclaringType! - .GetProperty(propertyName); - - enableSystemSortingPropertyInfo!.SetValue( - group, - enabled, - BindingFlags.Instance | BindingFlags.NonPublic, - null, - null, - CultureInfo.CurrentCulture); - } - } -} diff --git a/Runtime/Scripts/MonoBehaviours/EntityMonoBehaviour.cs b/Runtime/Scripts/MonoBehaviours/EntityMonoBehaviour.cs index babc99e..d9ee4fb 100644 --- a/Runtime/Scripts/MonoBehaviours/EntityMonoBehaviour.cs +++ b/Runtime/Scripts/MonoBehaviours/EntityMonoBehaviour.cs @@ -8,7 +8,7 @@ namespace Software10101.DOTS.MonoBehaviours { public abstract class EntityMonoBehaviour : ManagedMonoBehaviour { - private static readonly Dictionary Instances = new Dictionary(); + private static readonly Dictionary Instances = new(); private Entity _entity = Entity.Null; public Entity Entity { @@ -24,19 +24,19 @@ internal set { } } - private Bootstrapper _bootstrapper = null; - public Bootstrapper Bootstrapper { - protected get => _bootstrapper; + private WorldBehaviour _worldBehaviour = null; + public WorldBehaviour WorldBehaviour { + protected get => _worldBehaviour; set { - if (_bootstrapper != null) { + if (_worldBehaviour != null) { throw new Exception("Cannot set bootstrapper multiple times."); } - _bootstrapper = value; + _worldBehaviour = value; } } - protected EntityManager EntityManager => _bootstrapper.EntityManager; + protected EntityManager EntityManager => _worldBehaviour.EntityManager; #if UNITY_EDITOR && ENTITY_NAME_SYNC private string _oldName = null; @@ -68,7 +68,7 @@ public static EntityMonoBehaviour Get(Entity entity) { internal override void Destroy() { Entity = Entity.Null; - _bootstrapper = null; + _worldBehaviour = null; base.Destroy(); } diff --git a/Runtime/Scripts/MonoBehaviours/ResetDotsOnDestroy.cs b/Runtime/Scripts/MonoBehaviours/ResetDotsOnDestroy.cs deleted file mode 100644 index 1fc4200..0000000 --- a/Runtime/Scripts/MonoBehaviours/ResetDotsOnDestroy.cs +++ /dev/null @@ -1,10 +0,0 @@ -using Software10101.DOTS.Utils; -using UnityEngine; - -namespace Software10101.DOTS.MonoBehaviours { - public class ResetDotsOnDestroy : MonoBehaviour{ - private void OnDestroy() { - DotsUtil.Reset(); - } - } -} diff --git a/Runtime/Scripts/MonoBehaviours/WorldBehaviour.cs b/Runtime/Scripts/MonoBehaviours/WorldBehaviour.cs index ad57d5f..74d011f 100644 --- a/Runtime/Scripts/MonoBehaviours/WorldBehaviour.cs +++ b/Runtime/Scripts/MonoBehaviours/WorldBehaviour.cs @@ -1,166 +1,160 @@ -using System; -using System.Collections.Generic; -using Software10101.DOTS.Utils; -using Unity.Entities; -using UnityEngine; - -namespace Software10101.DOTS.MonoBehaviours { - public class WorldBehaviour : MonoBehaviour { - private WorldWrapper _world = null; - - public EntityManager EntityManager => _world.EntityManager; - - protected virtual void Awake() { - _world = new WorldWrapper(name); - } - - protected void Update() { - if (_world.Disposed) { - Destroy(this); - } - } - - protected virtual void OnDestroy() { - _world?.Dispose(); - } - - public T GetExistingSystem() where T : ComponentSystemBase { - return _world.GetExistingSystem(); - } - - internal T GetOrCreateSystem(Type parent) where T : ComponentSystemBase { - return _world.GetOrCreateSystem(parent); - } - - public T GetOrCreateSystem(ComponentSystemGroup group) where T : ComponentSystemBase { - return _world.GetOrCreateSystem(group); - } - - internal ReferenceCreatedSystemBase GetOrCreateSystemInternal(ComponentSystemGroup group, Type systemType) { - return _world.GetOrCreateSystemInternal(group, systemType); - } - - public ComponentSystemBase GetOrCreateSystem(ComponentSystemGroup group, Type systemType) { - return _world.GetOrCreateSystem(group, systemType); - } - - public T AddSystem(ComponentSystemGroup group, T system) where T : ComponentSystemBase { - return _world.AddSystem(group, system); - } - - public ComponentSystemBase AddSystem(ComponentSystemGroup group, ComponentSystemBase system) { - return _world.AddSystem(group, system); - } - - internal T AddSystem(Type parent, T system) where T : ComponentSystemBase { - return _world.AddSystem(parent, system); - } - - internal ComponentSystemBase AddSystem(Type parent, ComponentSystemBase system) { - return _world.AddSystem(parent, system); - } - } - - public class WorldWrapper : IDisposable { - private readonly World _world; - - private readonly Dictionary _topLevelSystems = new Dictionary(); - - public EntityManager EntityManager => _world.EntityManager; - - public bool Disposed => !_world.IsCreated; - - public WorldWrapper(string name) { - _world = new World(name); - } - - public T GetExistingSystem() where T : ComponentSystemBase { - return _world.GetExistingSystem(); - } - - internal T GetOrCreateSystem(Type parent) where T : ComponentSystemBase { - bool hasSystem = _world.GetExistingSystem() != null; - - T system = _world.GetOrCreateSystem(); - - if (!hasSystem) { - _topLevelSystems[system] = parent; - PlayerLoopUtil.AddSubSystem(parent, system); - } - - return system; - } - - public T GetOrCreateSystem(ComponentSystemGroup group) where T : ComponentSystemBase { - T system = _world.GetOrCreateSystem(); - - AddSystemToGroup(group, system); - - return system; - } - - public ComponentSystemBase GetOrCreateSystem(ComponentSystemGroup group, Type systemType) { - ComponentSystemBase system = _world.GetOrCreateSystem(systemType); - - AddSystemToGroup(group, system); - - return system; - } - - internal ReferenceCreatedSystemBase GetOrCreateSystemInternal(ComponentSystemGroup group, Type systemType) { - ReferenceCreatedSystemBase system = _world.GetOrCreateSystem(systemType) as ReferenceCreatedSystemBase; - - AddSystemToGroup(group, system); - - return system; - } - - public T AddSystem(ComponentSystemGroup group, T system) where T : ComponentSystemBase { - return (T)AddSystem(group, (ComponentSystemBase)system); - } - - public ComponentSystemBase AddSystem(ComponentSystemGroup group, ComponentSystemBase system) { - _world.AddSystem(system); - - AddSystemToGroup(group, system); - - return system; - } - - internal T AddSystem(Type parent, T system) where T : ComponentSystemBase { - return (T)AddSystem(parent, (ComponentSystemBase)system); - } - - internal ComponentSystemBase AddSystem(Type parent, ComponentSystemBase system) { - _world.AddSystem(system); - - _topLevelSystems[system] = parent; - PlayerLoopUtil.AddSubSystem(parent, system); - - return system; - } - - public void Dispose() { - foreach (KeyValuePair systemEntry in _topLevelSystems) { - PlayerLoopUtil.RemoveSubSystem(systemEntry.Value, systemEntry.Key); - } - - if (Disposed) { - return; - } - - _world.Dispose(); - } - - private void AddSystemToGroup(ComponentSystemGroup group, ComponentSystemBase system) { - switch (group) { - case IList lcsg: - lcsg.Add(system); - return; - default: - group.AddSystemToUpdateList(system); - return; - } - } - } -} +using System; +using System.Globalization; +using System.Reflection; +using Software10101.DOTS.Systems; +using Software10101.DOTS.Systems.EntityCommandBufferSystems; +using Software10101.DOTS.Systems.Groups; +using Unity.Entities; +using UnityEngine; +using UnityEngine.LowLevel; +using UnityEngine.PlayerLoop; +using InitializationSystemGroup = Unity.Entities.InitializationSystemGroup; +using PresentationSystemGroup = Unity.Entities.PresentationSystemGroup; +using SimulationSystemGroup = Unity.Entities.SimulationSystemGroup; + +namespace Software10101.DOTS.MonoBehaviours { + [DisallowMultipleComponent] + public class WorldBehaviour : MonoBehaviour { + [SerializeField] + private WorldFlags _flags = WorldFlags.Live | WorldFlags.Game; + + [SerializeField] + private GraphSystemGroupData _simResetGroup = GraphSystemGroupData.CreateEmpty(); + + [SerializeField] + private GraphSystemGroupData _mainSimGroup = GraphSystemGroupData.CreateEmpty(); + + [SerializeField] + private GraphSystemGroupData _presentationPreUpdateGroup = GraphSystemGroupData.CreateEmpty(); + + [SerializeField] + private GraphSystemGroupData _presentationPostUpdateGroup = GraphSystemGroupData.CreateEmpty(); + + [SerializeField] + private GraphSystemGroupData _endOfFrameGroup = GraphSystemGroupData.CreateEmpty(); + + private World _world; + public World World => _world; + public EntityManager EntityManager => _world.EntityManager; + + private void Awake() { + _world = new World(name, _flags); + + // set up initialization group + // ReSharper disable once UnusedVariable // not used by the bootstrapper but is one of Unity's root system groups + InitializationSystemGroup initGroup = AddSystemToCurrentPlayerLoop(new InitializationSystemGroup(), typeof(Initialization)); + + // set up simulation systems + SimulationSystemGroup simGroup = AddSystemToCurrentPlayerLoop(new SimulationSystemGroup(), typeof(FixedUpdate)); + AddSystemToGroup(new SimulationDestroySystem(), simGroup); + AddSystemToGroup(new SimulationResetSystemGroup(), simGroup); + // TODO populate + AddSystemToGroup(new PreSimulationEntityCommandBufferSystem(), simGroup); + AddSystemToGroup(new SimulationMainSystemGroup(), simGroup); + // TODO populate + AddSystemToGroup(new PostSimulationEntityCommandBufferSystem(), simGroup); + + // UI interactions happen before the presentation group + + // set up presentation systems + PresentationSystemGroup presentationGroup = AddSystemToCurrentPlayerLoop(new PresentationSystemGroup(), typeof(Update)); + AddSystemToGroup(new PrePresentationEntityCommandBufferSystem(), presentationGroup); + AddSystemToGroup(new PresentationPreUpdateSystemGroup(), presentationGroup); + // TODO populate + AddSystemToGroup(new PreManagedMonoBehaviourUpdateEntityCommandBufferSystem(), presentationGroup); + AddSystemToGroup(new ManagedMonoBehaviourUpdateSystem(), presentationGroup); + AddSystemToGroup(new PostManagedMonoBehaviourUpdateEntityCommandBufferSystem(), presentationGroup); + AddSystemToGroup(new PresentationPostUpdateSystemGroup(), presentationGroup); + // TODO populate + AddSystemToGroup(new PostPresentationEntityCommandBufferSystem(), presentationGroup); + AddSystemToGroup(new PresentationDestroySystem(), presentationGroup); + AddSystemToGroup(new PrefabSpawnSystem(this), presentationGroup); + AddSystemToGroup(new EndOfFrameEntityCommandBufferSystem(), presentationGroup); + AddSystemToGroup(new EndOfFrameSystemGroup(), presentationGroup); + // TODO populate + + // TODO archetype producers + } + + private void Reset() { + _simResetGroup = GraphSystemGroupData.CreateEmpty(); + _mainSimGroup = GraphSystemGroupData.CreateEmpty(); + _presentationPreUpdateGroup = GraphSystemGroupData.CreateEmpty(); + _presentationPostUpdateGroup = GraphSystemGroupData.CreateEmpty(); + _endOfFrameGroup = GraphSystemGroupData.CreateEmpty(); + } + + public T AddSystemToCurrentPlayerLoop(T system, Type playerLoopSystemType) where T : ComponentSystemBase { + PlayerLoopSystem playerLoop = PlayerLoop.GetCurrentPlayerLoop(); + + system = _world.AddSystemManaged(system); + ScriptBehaviourUpdateOrder.AppendSystemToPlayerLoop(system, ref playerLoop, playerLoopSystemType); + + PlayerLoop.SetPlayerLoop(playerLoop); + + return system; + } + + public T AddSystemToGroup(T system, ComponentSystemGroup parent) where T : ComponentSystemBase { + system = _world.AddSystemManaged(system); + parent.AddSystemToUpdateList(system); + + return system; + } + + /// + /// This reflection helper needed because the setter on is + /// protected. + /// + private static void SetSystemSortingEnabled(ComponentSystemGroup group, bool enabled) { + const string propertyName = "EnableSystemSorting"; + + PropertyInfo enableSystemSortingPropertyInfo = group.GetType() + .GetProperty(propertyName)! + .DeclaringType! + .GetProperty(propertyName); + + enableSystemSortingPropertyInfo!.SetValue( + group, + enabled, + BindingFlags.Instance | BindingFlags.NonPublic, + null, + null, + CultureInfo.CurrentCulture); + } + + [Serializable] + public struct GraphSystemGroupData { + public SystemNodeData[] Nodes; + + public static GraphSystemGroupData CreateEmpty() { + GraphSystemGroupData newData = new() { + Nodes = new []{ new SystemNodeData() } + }; + + return newData; + } + + [Serializable] + public struct SystemNodeData { + public SystemTypeReference SystemReference; + public Vector2 NodePosition; + public SystemTypeReference[] Dependencies; + + public SystemNodeData( + SystemTypeReference systemReference, + Vector2 nodePosition, + SystemTypeReference[] dependencies + ) { + SystemReference = systemReference; + NodePosition = nodePosition; + Dependencies = dependencies; + } + } + } + + public EntityMonoBehaviour GetPrefab(int initDataPrefabIndex) { + throw new NotImplementedException(); + } + } +} diff --git a/Runtime/Scripts/MonoBehaviours/WorldBehaviour.cs.meta b/Runtime/Scripts/MonoBehaviours/WorldBehaviour.cs.meta index 22d5375..8209489 100644 --- a/Runtime/Scripts/MonoBehaviours/WorldBehaviour.cs.meta +++ b/Runtime/Scripts/MonoBehaviours/WorldBehaviour.cs.meta @@ -1,3 +1,11 @@ -fileFormatVersion: 2 -guid: b5f4b11a5ba74433a17c73d9bc92c177 -timeCreated: 1586752128 \ No newline at end of file +fileFormatVersion: 2 +guid: b5f4b11a5ba74433a17c73d9bc92c177 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Scripts/Systems/Entity Command Buffer Systems/EndOfFrameEntityCommandBufferSystem.cs b/Runtime/Scripts/Systems/Entity Command Buffer Systems/EndOfFrameEntityCommandBufferSystem.cs index 38a7464..3f77d96 100644 --- a/Runtime/Scripts/Systems/Entity Command Buffer Systems/EndOfFrameEntityCommandBufferSystem.cs +++ b/Runtime/Scripts/Systems/Entity Command Buffer Systems/EndOfFrameEntityCommandBufferSystem.cs @@ -1,5 +1,7 @@ using Unity.Entities; namespace Software10101.DOTS.Systems.EntityCommandBufferSystems { - internal sealed class EndOfFrameEntityCommandBufferSystem : EntityCommandBufferSystem { } + [UpdateInGroup(typeof(PresentationSystemGroup))] + [UpdateAfter(typeof(PrefabSpawnSystem))] + internal sealed partial class EndOfFrameEntityCommandBufferSystem : EntityCommandBufferSystem { } } diff --git a/Runtime/Scripts/Systems/Entity Command Buffer Systems/PostManagedMonoBehaviourUpdateEntityCommandBufferSystem.cs b/Runtime/Scripts/Systems/Entity Command Buffer Systems/PostManagedMonoBehaviourUpdateEntityCommandBufferSystem.cs index 24de68a..5c3bcf8 100644 --- a/Runtime/Scripts/Systems/Entity Command Buffer Systems/PostManagedMonoBehaviourUpdateEntityCommandBufferSystem.cs +++ b/Runtime/Scripts/Systems/Entity Command Buffer Systems/PostManagedMonoBehaviourUpdateEntityCommandBufferSystem.cs @@ -1,5 +1,7 @@ using Unity.Entities; namespace Software10101.DOTS.Systems.EntityCommandBufferSystems { - public sealed class PostManagedMonoBehaviourUpdateEntityCommandBufferSystem : EntityCommandBufferSystem { } + [UpdateInGroup(typeof(PresentationSystemGroup))] + [UpdateAfter(typeof(ManagedMonoBehaviourUpdateSystem))] + public sealed partial class PostManagedMonoBehaviourUpdateEntityCommandBufferSystem : EntityCommandBufferSystem { } } diff --git a/Runtime/Scripts/Systems/Entity Command Buffer Systems/PostPresentationEntityCommandBufferSystem.cs b/Runtime/Scripts/Systems/Entity Command Buffer Systems/PostPresentationEntityCommandBufferSystem.cs index 9519461..32221aa 100644 --- a/Runtime/Scripts/Systems/Entity Command Buffer Systems/PostPresentationEntityCommandBufferSystem.cs +++ b/Runtime/Scripts/Systems/Entity Command Buffer Systems/PostPresentationEntityCommandBufferSystem.cs @@ -1,5 +1,8 @@ +using Software10101.DOTS.Systems.Groups; using Unity.Entities; namespace Software10101.DOTS.Systems.EntityCommandBufferSystems { - public sealed class PostPresentationEntityCommandBufferSystem : EntityCommandBufferSystem { } + [UpdateInGroup(typeof(PresentationSystemGroup))] + [UpdateAfter(typeof(PresentationPostUpdateSystemGroup))] + public sealed partial class PostPresentationEntityCommandBufferSystem : EntityCommandBufferSystem { } } diff --git a/Runtime/Scripts/Systems/Entity Command Buffer Systems/PostSimulationEntityCommandBufferSystem.cs b/Runtime/Scripts/Systems/Entity Command Buffer Systems/PostSimulationEntityCommandBufferSystem.cs index 6b2d601..3162fd2 100644 --- a/Runtime/Scripts/Systems/Entity Command Buffer Systems/PostSimulationEntityCommandBufferSystem.cs +++ b/Runtime/Scripts/Systems/Entity Command Buffer Systems/PostSimulationEntityCommandBufferSystem.cs @@ -1,5 +1,8 @@ +using Software10101.DOTS.Systems.Groups; using Unity.Entities; namespace Software10101.DOTS.Systems.EntityCommandBufferSystems { - public sealed class PostSimulationEntityCommandBufferSystem : EntityCommandBufferSystem { } + [UpdateInGroup(typeof(SimulationSystemGroup))] + [UpdateAfter(typeof(SimulationMainSystemGroup))] + public sealed partial class PostSimulationEntityCommandBufferSystem : EntityCommandBufferSystem { } } diff --git a/Runtime/Scripts/Systems/Entity Command Buffer Systems/PreManagedMonoBehaviourUpdateEntityCommandBufferSystem.cs b/Runtime/Scripts/Systems/Entity Command Buffer Systems/PreManagedMonoBehaviourUpdateEntityCommandBufferSystem.cs index 2ea2086..76da6d2 100644 --- a/Runtime/Scripts/Systems/Entity Command Buffer Systems/PreManagedMonoBehaviourUpdateEntityCommandBufferSystem.cs +++ b/Runtime/Scripts/Systems/Entity Command Buffer Systems/PreManagedMonoBehaviourUpdateEntityCommandBufferSystem.cs @@ -1,5 +1,8 @@ +using Software10101.DOTS.Systems.Groups; using Unity.Entities; namespace Software10101.DOTS.Systems.EntityCommandBufferSystems { - public sealed class PreManagedMonoBehaviourUpdateEntityCommandBufferSystem : EntityCommandBufferSystem { } + [UpdateInGroup(typeof(PresentationSystemGroup))] + [UpdateAfter(typeof(PresentationPreUpdateSystemGroup))] + public sealed partial class PreManagedMonoBehaviourUpdateEntityCommandBufferSystem : EntityCommandBufferSystem { } } diff --git a/Runtime/Scripts/Systems/Entity Command Buffer Systems/PrePresentationEntityCommandBufferSystem.cs b/Runtime/Scripts/Systems/Entity Command Buffer Systems/PrePresentationEntityCommandBufferSystem.cs index 1e16ded..28d0230 100644 --- a/Runtime/Scripts/Systems/Entity Command Buffer Systems/PrePresentationEntityCommandBufferSystem.cs +++ b/Runtime/Scripts/Systems/Entity Command Buffer Systems/PrePresentationEntityCommandBufferSystem.cs @@ -1,5 +1,6 @@ using Unity.Entities; namespace Software10101.DOTS.Systems.EntityCommandBufferSystems { - public sealed class PrePresentationEntityCommandBufferSystem : EntityCommandBufferSystem { } + [UpdateInGroup(typeof(PresentationSystemGroup), OrderFirst = true)] + public sealed partial class PrePresentationEntityCommandBufferSystem : EntityCommandBufferSystem { } } diff --git a/Runtime/Scripts/Systems/Entity Command Buffer Systems/PreSimulationEntityCommandBufferSystem.cs b/Runtime/Scripts/Systems/Entity Command Buffer Systems/PreSimulationEntityCommandBufferSystem.cs index e41d390..fad8d8b 100644 --- a/Runtime/Scripts/Systems/Entity Command Buffer Systems/PreSimulationEntityCommandBufferSystem.cs +++ b/Runtime/Scripts/Systems/Entity Command Buffer Systems/PreSimulationEntityCommandBufferSystem.cs @@ -1,5 +1,8 @@ +using Software10101.DOTS.Systems.Groups; using Unity.Entities; namespace Software10101.DOTS.Systems.EntityCommandBufferSystems { - public sealed class PreSimulationEntityCommandBufferSystem : EntityCommandBufferSystem { } + [UpdateInGroup(typeof(SimulationSystemGroup))] + [UpdateAfter(typeof(SimulationResetSystemGroup))] + public sealed partial class PreSimulationEntityCommandBufferSystem : EntityCommandBufferSystem { } } diff --git a/Runtime/Scripts/Systems/Groups/Abstract.meta b/Runtime/Scripts/Systems/Groups/Abstract.meta new file mode 100644 index 0000000..173659b --- /dev/null +++ b/Runtime/Scripts/Systems/Groups/Abstract.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 558d9743b050d5445a67785be600d876 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Scripts/Systems/Groups/Abstract/GraphSystemGroup.cs b/Runtime/Scripts/Systems/Groups/Abstract/GraphSystemGroup.cs new file mode 100644 index 0000000..df58685 --- /dev/null +++ b/Runtime/Scripts/Systems/Groups/Abstract/GraphSystemGroup.cs @@ -0,0 +1,3 @@ +namespace Software10101.DOTS.Systems.Groups.Abstract { + public abstract partial class GraphSystemGroup : UnsortedSystemGroup { } +} diff --git a/Runtime/Scripts/Systems/Groups/Abstract/GraphSystemGroup.cs.meta b/Runtime/Scripts/Systems/Groups/Abstract/GraphSystemGroup.cs.meta new file mode 100644 index 0000000..01eabdd --- /dev/null +++ b/Runtime/Scripts/Systems/Groups/Abstract/GraphSystemGroup.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 78ab7e2ab7ddccc49abb1098f36dde9d +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Scripts/Systems/Groups/Abstract/UnsortedSystemGroup.cs b/Runtime/Scripts/Systems/Groups/Abstract/UnsortedSystemGroup.cs new file mode 100644 index 0000000..1a7049b --- /dev/null +++ b/Runtime/Scripts/Systems/Groups/Abstract/UnsortedSystemGroup.cs @@ -0,0 +1,10 @@ +using Unity.Entities; + +namespace Software10101.DOTS.Systems.Groups.Abstract { + public abstract partial class UnsortedSystemGroup : ComponentSystemGroup { + protected override void OnCreate() { + base.OnCreate(); + EnableSystemSorting = false; + } + } +} diff --git a/Runtime/Scripts/Systems/Groups/Abstract/UnsortedSystemGroup.cs.meta b/Runtime/Scripts/Systems/Groups/Abstract/UnsortedSystemGroup.cs.meta new file mode 100644 index 0000000..8b1b3c2 --- /dev/null +++ b/Runtime/Scripts/Systems/Groups/Abstract/UnsortedSystemGroup.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 27d6e735876c8b64389ecd690816e456 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Scripts/Systems/Groups/EndOfFrameSystemGroup.cs b/Runtime/Scripts/Systems/Groups/EndOfFrameSystemGroup.cs index 8ccd7c7..ecfbcfa 100644 --- a/Runtime/Scripts/Systems/Groups/EndOfFrameSystemGroup.cs +++ b/Runtime/Scripts/Systems/Groups/EndOfFrameSystemGroup.cs @@ -1,5 +1,9 @@ +using Software10101.DOTS.Systems.EntityCommandBufferSystems; +using Software10101.DOTS.Systems.Groups.Abstract; using Unity.Entities; namespace Software10101.DOTS.Systems.Groups { - internal sealed class EndOfFrameSystemGroup : ComponentSystemGroup { } + [UpdateInGroup(typeof(PresentationSystemGroup))] + [UpdateAfter(typeof(EndOfFrameEntityCommandBufferSystem))] + internal sealed partial class EndOfFrameSystemGroup : GraphSystemGroup { } } diff --git a/Runtime/Scripts/Systems/Groups/ListComponentSystemGroup.cs b/Runtime/Scripts/Systems/Groups/ListComponentSystemGroup.cs deleted file mode 100644 index 688d318..0000000 --- a/Runtime/Scripts/Systems/Groups/ListComponentSystemGroup.cs +++ /dev/null @@ -1,361 +0,0 @@ -using System; -using System.Collections; -using System.Collections.Generic; -using System.Collections.ObjectModel; -using System.Reflection; -using Unity.Collections.LowLevel.Unsafe; -using Unity.Entities; -using UnityEngine; - -namespace Software10101.DOTS.Systems.Groups { - /// - /// Component system group that acts like a List. Not compatible with unmanaged systems. - /// - [Obsolete] - public abstract class ListComponentSystemGroup : - ComponentSystemGroup, - IList, - IReadOnlyList, - IList { - - private List _underlyingSystemsToUpdate; - private static readonly FieldInfo UnderlyingSystemsToUpdateField = typeof(ComponentSystemGroup).GetField( - "m_systemsToUpdate", - BindingFlags.Instance | BindingFlags.NonPublic); - - private List _underlyingSystemsToRemove; - private static readonly FieldInfo UnderlyingSystemsToRemoveField = typeof(ComponentSystemGroup).GetField( - "m_systemsToRemove", - BindingFlags.Instance | BindingFlags.NonPublic); - - private static readonly FieldInfo MasterUpdateListField = typeof(ComponentSystemGroup).GetField( - "m_MasterUpdateList", - BindingFlags.Instance | BindingFlags.NonPublic); - - private static readonly Type UpdateIndexType = typeof(ComponentSystemGroup).Assembly.GetType("Unity.Entities.UpdateIndex"); - private static readonly Type UnsafeListOfUpdateIndexType = typeof(UnsafeList<>).MakeGenericType(UpdateIndexType); - - private static readonly MethodInfo UnsafeListOfUpdateIndexClearMethod = UnsafeListOfUpdateIndexType - .GetMethod("Clear", BindingFlags.Instance | BindingFlags.Public); - private static readonly MethodInfo UnsafeListOfUpdateIndexSetCapacityMethod = UnsafeListOfUpdateIndexType - .GetMethod("SetCapacity", BindingFlags.Instance | BindingFlags.Public); - private static readonly MethodInfo UnsafeListOfUpdateIndexAddMethod = UnsafeListOfUpdateIndexType - .GetMethod("Add", BindingFlags.Instance | BindingFlags.Public); - - private static readonly ConstructorInfo UpdateIndexConstructor = UpdateIndexType.GetConstructor(new[] {typeof(int), typeof(bool)}); - - private readonly List _systems = new List(); - private readonly List _mutableSystemsList = new List(); - private bool _systemsListDirtyFlag = false; - - public int Count => _mutableSystemsList.Count; - public bool IsSynchronized => ((ICollection)_mutableSystemsList).IsSynchronized; - public object SyncRoot => ((ICollection)_mutableSystemsList).SyncRoot; - public bool IsFixedSize => ((IList)_mutableSystemsList).IsFixedSize; - public bool IsReadOnly => ((ICollection)_mutableSystemsList).IsReadOnly; - - public override IReadOnlyList Systems => _systems; - - protected override void OnCreate() { - base.OnCreate(); - - _underlyingSystemsToUpdate = (List)UnderlyingSystemsToUpdateField.GetValue(this); - _underlyingSystemsToRemove = (List)UnderlyingSystemsToRemoveField.GetValue(this); - } - - protected override void OnUpdate() { - if (_underlyingSystemsToUpdate.Count > 0) { - _mutableSystemsList.AddRange(_underlyingSystemsToUpdate); - _underlyingSystemsToUpdate.Clear(); - _systemsListDirtyFlag = true; - } - - if (_underlyingSystemsToRemove.Count > 0) { - _underlyingSystemsToRemove.ForEach(system => _mutableSystemsList.Remove(system)); - _underlyingSystemsToRemove.Clear(); - _systemsListDirtyFlag = true; - } - - if (_systemsListDirtyFlag) { - _systemsListDirtyFlag = false; - _systems.Clear(); - _systems.AddRange(_mutableSystemsList); - - // this icky stuff is because the entity debugger only really wants to work with the default group class - #region EntityDebuggerWorkarounds - object o = MasterUpdateListField.GetValue(this); - UnsafeListOfUpdateIndexClearMethod.Invoke(o, null); - UnsafeListOfUpdateIndexSetCapacityMethod.Invoke(o, new object[] {_systems.Count}); - - for (int i = 0; i < _systems.Count; i++) { - object obj = UpdateIndexConstructor.Invoke(new object[] {i, true}); - UnsafeListOfUpdateIndexAddMethod.Invoke(o, new [] {obj}); - } - - MasterUpdateListField.SetValue(this, o); - #endregion - } - - if (RateManager == null) { - UpdateAllSystems(); - } else { - while (RateManager.ShouldGroupUpdate(this)) { - UpdateAllSystems(); - } - } - } - - private void UpdateAllSystems() { - int count = _systems.Count; - int index; - - for (index = 0; index < count; index++) { - try { - _systems[index].Update(); - } catch (Exception e) { - Debug.LogException(e); - } - - if (World.QuitUpdate) { - break; - } - } - } - - IEnumerator IEnumerable.GetEnumerator() { - return ((IEnumerable)_mutableSystemsList).GetEnumerator(); - } - - IEnumerator IEnumerable.GetEnumerator() { - return ((IEnumerable)_mutableSystemsList).GetEnumerator(); - } - - public List.Enumerator GetEnumerator() { - return _mutableSystemsList.GetEnumerator(); - } - - int IList.Add(object value) { - int result = ((IList)_mutableSystemsList).Add(value); - _systemsListDirtyFlag = true; - return result; - } - - public void Add(ComponentSystemBase item) { - _mutableSystemsList.Add(item); - _systemsListDirtyFlag = true; - } - - public void Clear() { - _mutableSystemsList.Clear(); - _systemsListDirtyFlag = true; - } - - bool IList.Contains(object value) { - return ((IList)_mutableSystemsList).Contains(value); - } - - public bool Contains(ComponentSystemBase item) { - return _mutableSystemsList.Contains(item); - } - - void ICollection.CopyTo(Array array, int index) { - ((ICollection)_mutableSystemsList).CopyTo(array, index); - } - - public void CopyTo(ComponentSystemBase[] array, int arrayIndex) { - _mutableSystemsList.CopyTo(array, arrayIndex); - } - - void IList.Remove(object value) { - ((IList)_mutableSystemsList).Remove(value); - _systemsListDirtyFlag = true; - } - - public bool Remove(ComponentSystemBase item) { - bool result = _mutableSystemsList.Remove(item); - _systemsListDirtyFlag = true; - return result; - } - - int IList.IndexOf(object value) { - return ((IList)_mutableSystemsList).IndexOf(value); - } - - public int IndexOf(ComponentSystemBase item) { - return _mutableSystemsList.IndexOf(item); - } - - public int IndexOf(ComponentSystemBase item, int index) { - return _mutableSystemsList.IndexOf(item, index); - } - - public int IndexOf(ComponentSystemBase item, int index, int count) { - return _mutableSystemsList.IndexOf(item, index, count); - } - - void IList.Insert(int index, object value) { - ((IList)_mutableSystemsList).Insert(index, value); - _systemsListDirtyFlag = true; - } - - public void Insert(int index, ComponentSystemBase item) { - _mutableSystemsList.Insert(index, item); - _systemsListDirtyFlag = true; - } - - public void RemoveAt(int index) { - _mutableSystemsList.RemoveAt(index); - _systemsListDirtyFlag = true; - } - - object IList.this[int index] { - get => _mutableSystemsList[index]; - set { - ((IList)_mutableSystemsList)[index] = value; - _systemsListDirtyFlag = true; - } - } - - public ComponentSystemBase this[int index] { - get => _mutableSystemsList[index]; - set { - _mutableSystemsList[index] = value; - _systemsListDirtyFlag = true; - } - } - - public ReadOnlyCollection AsReadOnly() { - return _mutableSystemsList.AsReadOnly(); - } - - public int BinarySearch(int index, int count, ComponentSystemBase item, IComparer comparer) { - return _mutableSystemsList.BinarySearch(index, count, item, comparer); - } - - public int BinarySearch(ComponentSystemBase item) { - return _mutableSystemsList.BinarySearch(item); - } - - public int BinarySearch(ComponentSystemBase item, IComparer comparer) { - return _mutableSystemsList.BinarySearch(item, comparer); - } - - public bool Exists(Predicate match) { - return _mutableSystemsList.Exists(match); - } - - public ComponentSystemBase Find(Predicate match) { - return _mutableSystemsList.Find(match); - } - - public List FindAll(Predicate match) { - return _mutableSystemsList.FindAll(match); - } - - public int FindIndex(Predicate match) { - return _mutableSystemsList.FindIndex(match); - } - - public int FindIndex(int startIndex, Predicate match) { - return _mutableSystemsList.FindIndex(match); - } - - public int FindIndex(int startIndex, int count, Predicate match) { - return _mutableSystemsList.FindIndex(startIndex, count, match); - } - - public ComponentSystemBase FindLast(Predicate match) { - return _mutableSystemsList.FindLast(match); - } - - public int FindLastIndex(Predicate match) { - return _mutableSystemsList.FindLastIndex(match); - } - - public int FindLastIndex(int startIndex, Predicate match) { - return _mutableSystemsList.FindLastIndex(startIndex, match); - } - - public int FindLastIndex(int startIndex, int count, Predicate match) { - return _mutableSystemsList.FindLastIndex(startIndex, count, match); - } - - public void ForEach(Action action) { - _mutableSystemsList.ForEach(action); - } - - public List GetRange(int index, int count) { - return _mutableSystemsList.GetRange(index, count); - } - - public void InsertRange(int index, IEnumerable collection) { - _mutableSystemsList.InsertRange(index, collection); - _systemsListDirtyFlag = true; - } - - public int LastIndexOf(ComponentSystemBase item) { - return _mutableSystemsList.LastIndexOf(item); - } - - public int LastIndexOf(ComponentSystemBase item, int index) { - return _mutableSystemsList.LastIndexOf(item, index); - } - - public int LastIndexOf(ComponentSystemBase item, int index, int count) { - return _mutableSystemsList.LastIndexOf(item, index, count); - } - - public int RemoveAll(Predicate match) { - int result = _mutableSystemsList.RemoveAll(match); - _systemsListDirtyFlag = true; - return result; - } - - public void RemoveRange(int index, int count) { - _mutableSystemsList.RemoveRange(index, count); - _systemsListDirtyFlag = true; - } - - public void Reverse() { - _mutableSystemsList.Reverse(); - _systemsListDirtyFlag = true; - } - - public void Reverse(int index, int count) { - _mutableSystemsList.Reverse(index, count); - _systemsListDirtyFlag = true; - } - - public void Sort() { - _mutableSystemsList.Sort(); - _systemsListDirtyFlag = true; - } - - public void Sort(IComparer comparer) { - _mutableSystemsList.Sort(comparer); - _systemsListDirtyFlag = true; - } - - public void Sort(int index, int count, IComparer comparer) { - _mutableSystemsList.Sort(index, count, comparer); - _systemsListDirtyFlag = true; - } - - public void Sort(Comparison comparison) { - _mutableSystemsList.Sort(comparison); - _systemsListDirtyFlag = true; - } - - public ComponentSystemBase[] ToArray() { - return _mutableSystemsList.ToArray(); - } - - public void TrimExcess() { - _mutableSystemsList.TrimExcess(); - } - - public bool TrueForAll(Predicate match) { - return _mutableSystemsList.TrueForAll(match); - } - } -} diff --git a/Runtime/Scripts/Systems/Groups/ListComponentSystemGroup.cs.meta b/Runtime/Scripts/Systems/Groups/ListComponentSystemGroup.cs.meta deleted file mode 100644 index 6f9b4d9..0000000 --- a/Runtime/Scripts/Systems/Groups/ListComponentSystemGroup.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: 24801e2927d94ffe85534c6e6dcaae0d -timeCreated: 1587158791 \ No newline at end of file diff --git a/Runtime/Scripts/Systems/Groups/PresentationPostUpdateSystemGroup.cs b/Runtime/Scripts/Systems/Groups/PresentationPostUpdateSystemGroup.cs index 2da4af4..cf430c4 100644 --- a/Runtime/Scripts/Systems/Groups/PresentationPostUpdateSystemGroup.cs +++ b/Runtime/Scripts/Systems/Groups/PresentationPostUpdateSystemGroup.cs @@ -1,5 +1,9 @@ +using Software10101.DOTS.Systems.EntityCommandBufferSystems; +using Software10101.DOTS.Systems.Groups.Abstract; using Unity.Entities; namespace Software10101.DOTS.Systems.Groups { - internal sealed class PresentationPostUpdateSystemGroup : ComponentSystemGroup { } + [UpdateInGroup(typeof(PresentationSystemGroup))] + [UpdateAfter(typeof(PostManagedMonoBehaviourUpdateEntityCommandBufferSystem))] + internal sealed partial class PresentationPostUpdateSystemGroup : GraphSystemGroup { } } diff --git a/Runtime/Scripts/Systems/Groups/PresentationPreUpdateSystemGroup.cs b/Runtime/Scripts/Systems/Groups/PresentationPreUpdateSystemGroup.cs index f451b89..90c36bc 100644 --- a/Runtime/Scripts/Systems/Groups/PresentationPreUpdateSystemGroup.cs +++ b/Runtime/Scripts/Systems/Groups/PresentationPreUpdateSystemGroup.cs @@ -1,5 +1,9 @@ +using Software10101.DOTS.Systems.EntityCommandBufferSystems; +using Software10101.DOTS.Systems.Groups.Abstract; using Unity.Entities; namespace Software10101.DOTS.Systems.Groups { - internal sealed class PresentationPreUpdateSystemGroup : ComponentSystemGroup { } + [UpdateInGroup(typeof(PresentationSystemGroup))] + [UpdateAfter(typeof(PrePresentationEntityCommandBufferSystem))] + internal sealed partial class PresentationPreUpdateSystemGroup : GraphSystemGroup { } } diff --git a/Runtime/Scripts/Systems/Groups/SimulationMainSystemGroup.cs b/Runtime/Scripts/Systems/Groups/SimulationMainSystemGroup.cs index 6b9c870..11bd735 100644 --- a/Runtime/Scripts/Systems/Groups/SimulationMainSystemGroup.cs +++ b/Runtime/Scripts/Systems/Groups/SimulationMainSystemGroup.cs @@ -1,5 +1,9 @@ +using Software10101.DOTS.Systems.EntityCommandBufferSystems; +using Software10101.DOTS.Systems.Groups.Abstract; using Unity.Entities; namespace Software10101.DOTS.Systems.Groups { - internal sealed class SimulationMainSystemGroup : ComponentSystemGroup { } + [UpdateInGroup(typeof(SimulationSystemGroup))] + [UpdateAfter(typeof(PreSimulationEntityCommandBufferSystem))] + internal sealed partial class SimulationMainSystemGroup : GraphSystemGroup { } } diff --git a/Runtime/Scripts/Systems/Groups/SimulationResetSystemGroup.cs b/Runtime/Scripts/Systems/Groups/SimulationResetSystemGroup.cs index a69146f..83c6ec4 100644 --- a/Runtime/Scripts/Systems/Groups/SimulationResetSystemGroup.cs +++ b/Runtime/Scripts/Systems/Groups/SimulationResetSystemGroup.cs @@ -1,5 +1,8 @@ +using Software10101.DOTS.Systems.Groups.Abstract; using Unity.Entities; namespace Software10101.DOTS.Systems.Groups { - internal sealed class SimulationResetSystemGroup : ComponentSystemGroup { } + [UpdateInGroup(typeof(SimulationSystemGroup))] + [UpdateAfter(typeof(SimulationDestroySystem))] + internal sealed partial class SimulationResetSystemGroup : GraphSystemGroup { } } diff --git a/Runtime/Scripts/Systems/ManagedMonoBehaviourUpdateSystem.cs b/Runtime/Scripts/Systems/ManagedMonoBehaviourUpdateSystem.cs index b2460ae..ddee15c 100644 --- a/Runtime/Scripts/Systems/ManagedMonoBehaviourUpdateSystem.cs +++ b/Runtime/Scripts/Systems/ManagedMonoBehaviourUpdateSystem.cs @@ -1,11 +1,13 @@ using System.Collections.Generic; using Software10101.DOTS.MonoBehaviours; +using Software10101.DOTS.Systems.EntityCommandBufferSystems; using Unity.Collections; using Unity.Entities; using Unity.Jobs; namespace Software10101.DOTS.Systems { - // ReSharper disable once PartialTypeWithSinglePart // systems need to be partial after Entities 0.50 + [UpdateInGroup(typeof(PresentationSystemGroup))] + [UpdateAfter(typeof(PreManagedMonoBehaviourUpdateEntityCommandBufferSystem))] internal partial class ManagedMonoBehaviourUpdateSystem : SystemBase { protected override void OnUpdate() { JobHandleExtensions.CompleteJobList(); diff --git a/Runtime/Scripts/Systems/PrefabSpawnSystem.cs b/Runtime/Scripts/Systems/PrefabSpawnSystem.cs index 5d85a42..a5b5396 100644 --- a/Runtime/Scripts/Systems/PrefabSpawnSystem.cs +++ b/Runtime/Scripts/Systems/PrefabSpawnSystem.cs @@ -5,27 +5,28 @@ using UnityEngine; namespace Software10101.DOTS.Systems { - // ReSharper disable once PartialTypeWithSinglePart // systems need to be partial after Entities 0.50 + [UpdateInGroup(typeof(PresentationSystemGroup))] + [UpdateAfter(typeof(PresentationDestroySystem))] [DisableAutoCreation] internal partial class PrefabSpawnSystem : SystemBase { - private readonly Bootstrapper _bootstrapper; + private readonly WorldBehaviour _worldBehaviour; - public PrefabSpawnSystem(Bootstrapper bootstrapper) { - _bootstrapper = bootstrapper; + public PrefabSpawnSystem(WorldBehaviour worldBehaviour) { + _worldBehaviour = worldBehaviour; } protected override void OnUpdate() { - EntityCommandBuffer ecb = World - .GetExistingSystem() - .CreateCommandBuffer(); + EntityCommandBuffer ecb = World + .GetExistingSystemManaged() + .CreateCommandBuffer(); - Entities - .WithoutBurst() - .ForEach((Entity entity, in SpawnPrefabComponentData initData) => { - EntityMonoBehaviour instance = Object.Instantiate(_bootstrapper.GetPrefab(initData.PrefabIndex)); + Entities + .WithoutBurst() + .ForEach((Entity entity, in SpawnPrefabComponentData initData) => { + EntityMonoBehaviour instance = Object.Instantiate(_worldBehaviour.GetPrefab(initData.PrefabIndex)); instance.Entity = entity; - instance.Bootstrapper = _bootstrapper; + instance.WorldBehaviour = _worldBehaviour; #if UNITY_EDITOR && ENTITY_NAME_SYNC EntityManager.SetName(entity, instance.name); @@ -36,8 +37,8 @@ protected override void OnUpdate() { // doing these in an ECB makes it a ton faster ecb.RemoveComponent(entity); ecb.AddComponent(entity, new GameObjectFlagComponentData()); - }) - .Run(); // must be on the main thread + }) + .Run(); // must be on the main thread } } } diff --git a/Runtime/Scripts/Systems/PresentationDestroySystem.cs b/Runtime/Scripts/Systems/PresentationDestroySystem.cs index ee39cf2..b4fbaa7 100644 --- a/Runtime/Scripts/Systems/PresentationDestroySystem.cs +++ b/Runtime/Scripts/Systems/PresentationDestroySystem.cs @@ -1,9 +1,11 @@ using Software10101.DOTS.Data; using Software10101.DOTS.MonoBehaviours; +using Software10101.DOTS.Systems.EntityCommandBufferSystems; using Unity.Entities; namespace Software10101.DOTS.Systems { - // ReSharper disable once PartialTypeWithSinglePart // systems need to be partial after Entities 0.50 + [UpdateInGroup(typeof(PresentationSystemGroup))] + [UpdateAfter(typeof(PostPresentationEntityCommandBufferSystem))] internal partial class PresentationDestroySystem : SystemBase { protected override void OnUpdate() { Entities diff --git a/Runtime/Scripts/Systems/SimulationDestroySystem.cs b/Runtime/Scripts/Systems/SimulationDestroySystem.cs index d0a9ff2..4c97d3b 100644 --- a/Runtime/Scripts/Systems/SimulationDestroySystem.cs +++ b/Runtime/Scripts/Systems/SimulationDestroySystem.cs @@ -2,7 +2,7 @@ using Unity.Entities; namespace Software10101.DOTS.Systems { - // ReSharper disable once PartialTypeWithSinglePart // systems need to be partial after Entities 0.50 + [UpdateInGroup(typeof(SimulationSystemGroup), OrderFirst = true)] internal partial class SimulationDestroySystem : SystemBase { protected override void OnUpdate() { Entities diff --git a/Runtime/Scripts/Utils/DotsUtil.cs b/Runtime/Scripts/Utils/DotsUtil.cs deleted file mode 100644 index 901e73e..0000000 --- a/Runtime/Scripts/Utils/DotsUtil.cs +++ /dev/null @@ -1,20 +0,0 @@ -using Software10101.DOTS.MonoBehaviours; -using Unity.Entities; -using UnityEngine; - -namespace Software10101.DOTS.Utils { - public static class DotsUtil { - [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)] - public static void Reset() { - World.DisposeAllWorlds(); - - PlayerLoopUtil.ResetPlayerLoop(); - - ReferenceTypeUtil.Clear(); - - ManagedMonoBehaviour.DestroyAll(); - - TimeUtil.TimeOffset = 0; - } - } -} diff --git a/Runtime/Scripts/Utils/DotsUtil.cs.meta b/Runtime/Scripts/Utils/DotsUtil.cs.meta deleted file mode 100644 index 101af1d..0000000 --- a/Runtime/Scripts/Utils/DotsUtil.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: 689f7f59fbbb41e19946c1192739ffc0 -timeCreated: 1586747843 \ No newline at end of file diff --git a/Runtime/Scripts/Utils/PlayerLoopUtil.cs b/Runtime/Scripts/Utils/PlayerLoopUtil.cs deleted file mode 100644 index 92419a6..0000000 --- a/Runtime/Scripts/Utils/PlayerLoopUtil.cs +++ /dev/null @@ -1,151 +0,0 @@ -using System; -using System.Reflection; -using Unity.Entities; -using UnityEngine.LowLevel; - -namespace Software10101.DOTS.Utils { - public static class PlayerLoopUtil { - private static readonly Type DummyWrapperType = typeof(ScriptBehaviourUpdateOrder).Assembly - .GetType("Unity.Entities.ScriptBehaviourUpdateOrder+DummyDelegateWrapper"); - - private static readonly ConstructorInfo DummyWrapperConstructor = DummyWrapperType - .GetConstructors(BindingFlags.Instance | BindingFlags.Public)[0]; - - private static readonly FieldInfo DummyWrapperSystem = DummyWrapperType - .GetField("m_System", BindingFlags.Instance | BindingFlags.NonPublic); - - private static readonly MethodInfo TriggerUpdateMethod = DummyWrapperType - .GetMethod("TriggerUpdate", BindingFlags.Public | BindingFlags.Instance); - - /// - /// Adds a system to the player loop in the same way that does. - /// - /// One difference is that this does not check to see if the system is already added. It is up to the users of this - /// method to ensure that they do not add systems multiple times. - /// - /// - /// Must be one of the top level types already in the player loop such as - /// or . - /// - /// - /// The system to be added to the player loop. - /// - /// - /// An exception is thrown if the reflection components could not be initialized or the parent type was not in the player - /// loop. - /// - public static void AddSubSystem(Type parent, ComponentSystemBase system) { - ValidateReflectionComponents(); - - PlayerLoopSystem currentPlayerLoop = PlayerLoop.GetCurrentPlayerLoop(); - - for (int i = 0; i < currentPlayerLoop.subSystemList.Length; i++) { - if (currentPlayerLoop.subSystemList[i].type == parent) { - PlayerLoopSystem[] oldSubSystems = currentPlayerLoop.subSystemList[i].subSystemList; - - PlayerLoopSystem[] newSubSystems = new PlayerLoopSystem[oldSubSystems.Length + 1]; - Array.Copy(oldSubSystems, newSubSystems, oldSubSystems.Length); - - newSubSystems[oldSubSystems.Length].type = system.GetType(); - newSubSystems[oldSubSystems.Length].updateDelegate = CreateDummyWrapper(system); - - currentPlayerLoop.subSystemList[i].subSystemList = newSubSystems; - - PlayerLoop.SetPlayerLoop(currentPlayerLoop); - - return; - } - } - - throw new Exception($"Could not add {system.GetType().Name} to player loop. Are you sure {parent.Name} is in the player loop?"); - } - - /// - /// Removes the first instance of the system from the specified parent. - /// - /// - /// Must be one of the top level types already in the player loop such as - /// or . - /// - /// - /// The system to be removed from the player loop. - /// - public static void RemoveSubSystem(Type parent, ComponentSystemBase system) { - ValidateReflectionComponents(); - - PlayerLoopSystem currentPlayerLoop = PlayerLoop.GetCurrentPlayerLoop(); - - for (int i = 0; i < currentPlayerLoop.subSystemList.Length; i++) { - if (currentPlayerLoop.subSystemList[i].type == parent) { - PlayerLoopSystem[] oldSubSystems = currentPlayerLoop.subSystemList[i].subSystemList; - PlayerLoopSystem[] newSubSystems = new PlayerLoopSystem[oldSubSystems.Length - 1]; - - int index; - for (index = 0; index < oldSubSystems.Length; index++) { - if (oldSubSystems[index].updateDelegate == null) { - continue; - } - - object target = oldSubSystems[index].updateDelegate.Target; - if (target.GetType() == DummyWrapperType && DummyWrapperSystem.GetValue(target) == system) { - break; - } - } - - if (index < oldSubSystems.Length) { - Array.Copy( - oldSubSystems, - newSubSystems, - index); - - Array.Copy( - oldSubSystems, - index + 1, - newSubSystems, - index, - oldSubSystems.Length - index - 1); - } - - currentPlayerLoop.subSystemList[i].subSystemList = newSubSystems; - - PlayerLoop.SetPlayerLoop(currentPlayerLoop); - - return; - } - } - } - - /// - /// Resets the player loop to the default. - /// - public static void ResetPlayerLoop() { - PlayerLoop.SetPlayerLoop(PlayerLoop.GetDefaultPlayerLoop()); - } - - private static PlayerLoopSystem.UpdateFunction CreateDummyWrapper(ComponentSystemBase system) { - object dummyWrapper = DummyWrapperConstructor.Invoke(new object[] { system }); - - Delegate del = TriggerUpdateMethod.CreateDelegate(typeof(PlayerLoopSystem.UpdateFunction), dummyWrapper); - - return (PlayerLoopSystem.UpdateFunction)del; - } - - private static void ValidateReflectionComponents() { - if (DummyWrapperType == null) { - throw new Exception("Could not find DummyDelegateWrapper!"); - } - - if (DummyWrapperConstructor == null) { - throw new Exception("Could not find DummyDelegateWrapper constructor!"); - } - - if (TriggerUpdateMethod == null) { - throw new Exception("Could not find TriggerUpdate!"); - } - - if (DummyWrapperSystem == null) { - throw new Exception("Could not find m_System!"); - } - } - } -} diff --git a/Runtime/Scripts/Utils/PlayerLoopUtil.cs.meta b/Runtime/Scripts/Utils/PlayerLoopUtil.cs.meta deleted file mode 100644 index c6091f7..0000000 --- a/Runtime/Scripts/Utils/PlayerLoopUtil.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: 08a127f2ccdc43bda90bf935de880bda -timeCreated: 1586733313 \ No newline at end of file