Example #1
0
        /// <summary>
        /// Removes the proxy entity bound to this remote entity without destroying the remote entity.
        /// </summary>
        /// <param name="entityManager">The entity manager where the proxy entity is included.</param>
        /// <param name="remoteEntity">The remote entity.</param>
        /// <param name="removeFlags">Flags to indicate how to proceed with parent entities of the proxy entity.</param>
        public static void RemoveProxyEntity(this EntityManager entityManager, ARREntity remoteEntity, ARRRemoveProxyEntityFlags removeFlags)
        {
            var proxyEntity = remoteEntity.GetExistingProxyEntity();

            if (proxyEntity == null)
            {
                return;
            }

            ARREntitySync  sync;
            EvergineEntity previous = null;

            if (removeFlags.HasFlag(ARRRemoveProxyEntityFlags.DestroyEmptyParents))
            {
                sync = proxyEntity.FindComponent <ARREntitySync>();
                while (proxyEntity.Parent?.NumChildren == 1)
                {
                    previous    = proxyEntity;
                    proxyEntity = proxyEntity.Parent;

                    // Unbind on our way up the hierarchy for performance, keep the last sync bound in case keepRemoteRoot is true.
                    var syncNext = proxyEntity.FindComponent <ARREntitySync>();
                    if (syncNext == null)
                    {
                        break;
                    }

                    // Unbind first entity recursively since it doesn't need to be leaf
                    sync.Unbind(sync.RemoteEntity == remoteEntity);
                    sync = syncNext;
                }
            }

            if (removeFlags.HasFlag(ARRRemoveProxyEntityFlags.KeepRemoteRoot))
            {
                proxyEntity = previous;
            }
            else
            {
                proxyEntity?.FindComponent <ARREntitySync>().Unbind(true);
            }

            if (proxyEntity != null)
            {
                entityManager.Remove(proxyEntity);
            }
        }
Example #2
0
        /// <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);
        }