using Unity.Collections; using Unity.Entities; using UnityEditor.Rendering; using UnityEngine; namespace Streaming.AssetManagement { public partial struct UIInteropSystem : ISystem { public void OnCreate(ref SystemState state) { state.RequireForUpdate(); state.EntityManager.AddComponent(state.SystemHandle); state.EntityManager.SetComponentData(state.SystemHandle, new UIInterop()); } public void OnUpdate(ref SystemState state) { var ui = state.EntityManager.GetComponentData(state.SystemHandle); if (ui.LoadButton == null) { ui.LoadButton = GameObject.FindObjectOfType(); if (ui.LoadButton == null) { return; } } if (!ui.LoadButton.Toggle) { return; } ui.LoadButton.Toggle = false; var unloadQuery = SystemAPI.QueryBuilder().WithAll().WithNone().Build(); var loadQuery = SystemAPI.QueryBuilder().WithAll().WithNone().Build(); if (ui.LoadButton.Loaded) { state.EntityManager.AddComponent(unloadQuery); ui.LoadButton.Loaded = false; } else { state.EntityManager.RemoveComponent(loadQuery); ui.LoadButton.Loaded = true; } } } public class UIInterop : IComponentData { public LoadButton LoadButton; } }