/// <summary> /// Create a proxy <see cref="EvergineEntity"/> for a remote <see cref="ARREntity"/>. /// <para> /// /// When created, the path from the remote <see cref="ARREntity"/> to the remote scene root will have /// proxy entities created for it. /// These proxy entities must be created in order to appropriately set the /// <see cref="EvergineEntity.Parent"/> for the proxy entity. /// /// As a side effect, this means that, given a Remote hierarchy: /// /// ARR.Parent /// ARR.Child /// /// Calling <see cref="CreateProxyEntity"/> on ARR.Child will also create a proxy entity for ARR.Parent. /// </para> /// </summary> /// <param name="entityManager">The entity manager where the proxy entity is included.</param> /// <param name="remoteEntity">The remote entity.</param> /// <param name="mode">Whether the proxy components will be created.</param> /// <param name="recursive">Whether to create proxy entities for children of the remote entity.</param> /// <returns>A proxy <see cref="EvergineEntity"/> for a remote <see cref="ARREntity"/>.</returns> public static EvergineEntity CreateProxyEntity(this EntityManager entityManager, ARREntity remoteEntity, ARRCreationMode mode, bool recursive = false) { if (!remoteEntity.Valid) { return(null); } if (ARREntitySync.TryGetSyncComponent(remoteEntity, out _)) { throw new Exception("A proxy entity for this remote entity already exists!"); } var proxyEntity = new EvergineEntity(); proxyEntity.AddComponent(new Transform3D()); var remoteParentEntity = remoteEntity.Parent; if (remoteParentEntity != null) { var proxyParentEntity = GetExistingProxyEntity(remoteParentEntity); if (proxyParentEntity == null) { proxyParentEntity = entityManager.CreateProxyEntity(remoteParentEntity, ARRCreationMode.DoNotCreateProxyComponents, false); } proxyParentEntity.AddChild(proxyEntity); } else { entityManager.Add(proxyEntity); } var sync = proxyEntity.FindComponent <ARREntitySync>(); if (sync == null) { sync = new ARREntitySync(); proxyEntity.AddComponent(sync); } sync.Bind(remoteEntity, true); if (mode == ARRCreationMode.CreateProxyComponents) { proxyEntity.CreateARRComponentsFromRemoteEntity(remoteEntity); } if (recursive) { foreach (var remoteChild in remoteEntity.Children) { entityManager.CreateProxyEntity(remoteChild, mode, true); } } return(proxyEntity); }
/// <summary> /// Finds a proxy <see cref="EvergineEntity"/> for a remote <see cref="ARREntity"/>. /// If no proxy entity already exists, a new one will be created. /// </summary> /// <param name="entityManager">The entity manager where the proxy entity is included.</param> /// <param name="remoteEntity">The remote entity.</param> /// <param name="mode">Whether the proxy components will be created.</param> /// <param name="recursive">Whether to create proxy entities for children of the remote entity.</param> /// <returns>A proxy <see cref="EvergineEntity"/> for a remote <see cref="ARREntity"/>.</returns> public static EvergineEntity FindOrCreateProxyEntity(this EntityManager entityManager, ARREntity remoteEntity, ARRCreationMode mode, bool recursive = false) { var proxyEntity = remoteEntity.GetExistingProxyEntity(); if (proxyEntity == null) { proxyEntity = entityManager.CreateProxyEntity(remoteEntity, mode, false); } else if (mode == ARRCreationMode.CreateProxyComponents) { proxyEntity.CreateARRComponentsFromRemoteEntity(remoteEntity); } if (recursive) { foreach (var remoteChild in remoteEntity.Children) { entityManager.FindOrCreateProxyEntity(remoteChild, mode, true); } } return(proxyEntity); }