示例#1
0
        private void InitializePositions(NetworkMovementTrackerTypeFlags context, Vector3[] positions)
        {
            EntityGameObjectDirectory directory = GameObjectDirectoryMappable.RetrieveEntity(LocalPlayerDetails.LocalPlayerGuid);

            int index = 0;

            index = InitializePositionIndex(context, NetworkMovementTrackerTypeFlags.Head, EntityGameObjectDirectory.Type.CameraRoot, positions, index, directory);
            index = InitializePositionIndex(context, NetworkMovementTrackerTypeFlags.RightHand, EntityGameObjectDirectory.Type.RightHand, positions, index, directory);
            index = InitializePositionIndex(context, NetworkMovementTrackerTypeFlags.LeftHand, EntityGameObjectDirectory.Type.LeftHand, positions, index, directory);
        }
示例#2
0
        private void InitializeRotations(NetworkMovementTrackerTypeFlags context, Quaternion[] rotations)
        {
            EntityGameObjectDirectory directory = GameObjectDirectoryMappable.RetrieveEntity(LocalPlayerDetails.LocalPlayerGuid);

            int index = 0;

            //TODO: Right now we're only doing heads, so this works but will break later.
            index = InitializeRotationIndex(context, NetworkMovementTrackerTypeFlags.Head, EntityGameObjectDirectory.Type.CameraRoot, rotations, index, directory);
            index = InitializeRotationIndex(context, NetworkMovementTrackerTypeFlags.RightHand, EntityGameObjectDirectory.Type.RightHand, rotations, index, directory);
            index = InitializeRotationIndex(context, NetworkMovementTrackerTypeFlags.LeftHand, EntityGameObjectDirectory.Type.LeftHand, rotations, index, directory);
        }
示例#3
0
        protected override void HandleEvent(PlayerTrackerTransformChangedEventArgs args)
        {
            //TODO: Log this
            if (!KnownEntities.isEntityKnown(args.ChangeInformation.EntityGuid))
                return;

            EntityGameObjectDirectory directory = GameObjectDirectoryMappable.RetrieveEntity(args.ChangeInformation.EntityGuid);

            //TODO: We need to support more than just the head.
            Transform rootTransform = directory.GetGameObject(EntityGameObjectDirectory.Type.Root).transform;

            int index = 0;
            index = InitializeRotationIndex(args.ChangeInformation.Data.UpdateFields, NetworkMovementTrackerTypeFlags.Head, EntityGameObjectDirectory.Type.CameraRoot, args.ChangeInformation.Data.TrackerRotationUpdates, index, directory);
            index = InitializeRotationIndex(args.ChangeInformation.Data.UpdateFields, NetworkMovementTrackerTypeFlags.RightHand, EntityGameObjectDirectory.Type.RightHand, args.ChangeInformation.Data.TrackerRotationUpdates, index, directory);
            index = InitializeRotationIndex(args.ChangeInformation.Data.UpdateFields, NetworkMovementTrackerTypeFlags.LeftHand, EntityGameObjectDirectory.Type.LeftHand, args.ChangeInformation.Data.TrackerRotationUpdates, index, directory);

            index = 0;
            index = InitializePositionIndex(args.ChangeInformation.Data.UpdateFields, NetworkMovementTrackerTypeFlags.Head, EntityGameObjectDirectory.Type.CameraRoot, args.ChangeInformation.Data.TrackerPositionUpdates, index, directory);
            index = InitializePositionIndex(args.ChangeInformation.Data.UpdateFields, NetworkMovementTrackerTypeFlags.RightHand, EntityGameObjectDirectory.Type.RightHand, args.ChangeInformation.Data.TrackerPositionUpdates, index, directory);
            index = InitializePositionIndex(args.ChangeInformation.Data.UpdateFields, NetworkMovementTrackerTypeFlags.LeftHand, EntityGameObjectDirectory.Type.LeftHand, args.ChangeInformation.Data.TrackerPositionUpdates, index, directory);
        }
示例#4
0
        protected override void OnEventFired(object source, ContentPrefabCompletedDownloadEventArgs args)
        {
            //Only interested in players.
            if (args.EntityGuid.EntityType != EntityType.Player)
            {
                return;
            }

            if (Logger.IsInfoEnabled)
            {
                Logger.Info($"About to create new Avatar for Entity: {args.EntityGuid}");
            }

            try
            {
                //Now we've assigned the handle, we need to actually handle the spawning/loading of the avatar.
                GameObject ikRootGameObject            = GameObjectDirectoryMappable.RetrieveEntity(args.EntityGuid).GetGameObject(EntityGameObjectDirectory.Type.IKRoot);
                GameObject currentAvatarRootGameObject = ikRootGameObject.transform.GetChild(0).gameObject;
                GameObject newlySpawnedAvatar          = InstantiateNewFromPrefab(args.DownloadedPrefabObject, currentAvatarRootGameObject);

                //Try to get AvatarBoneSDKData from root spawned model
                AvatarBoneSDKData boneSdkData = newlySpawnedAvatar.GetComponent <AvatarBoneSDKData>();

                //TODO: Head height.
                //We can set relative camera height for VR users or first person users.
                //Don't do it for desktop.
                if (boneSdkData != null)
                {
                    GameObject nameRoot = GameObjectDirectoryMappable.RetrieveEntity(args.EntityGuid).GetGameObject(EntityGameObjectDirectory.Type.NameRoot);
                    nameRoot.transform.localPosition = new Vector3(nameRoot.transform.localPosition.x, boneSdkData.FloatingNameHeight, nameRoot.transform.localPosition.z);

                    //Don't use 0 or super small head heights. They're probably wrong, especially negative ones.
                    if (boneSdkData.HeadHeight > 0.1f)
                    {
                        GameObject headRoot = GameObjectDirectoryMappable.RetrieveEntity(args.EntityGuid).GetGameObject(EntityGameObjectDirectory.Type.HeadRoot);
                        headRoot.transform.localPosition = new Vector3(headRoot.transform.localPosition.x, boneSdkData.HeadHeight, headRoot.transform.localPosition.z);
                    }
                }

                GameObject.DestroyImmediate(currentAvatarRootGameObject, false);

                IMovementDirectionChangedListener movementChangeListener = newlySpawnedAvatar.GetComponentInChildren <IMovementDirectionChangedListener>();

                if (movementChangeListener != null)
                {
                    if (MovementDirectionListenerMappable.ContainsKey(args.EntityGuid))
                    {
                        MovementDirectionListenerMappable.ReplaceObject(args.EntityGuid, movementChangeListener);
                    }
                    else
                    {
                        MovementDirectionListenerMappable.AddObject(args.EntityGuid, movementChangeListener);
                    }
                }
                else
                {
                    MovementDirectionListenerMappable.RemoveEntityEntry(args.EntityGuid);                     //if it's null jsut remove one if it exists.
                }
                //This is for custom complex avatars that may need initialization after downloading.
                IAvatarInitializable avatarInitializable = newlySpawnedAvatar.GetComponentInChildren <IAvatarInitializable>();

                if (avatarInitializable != null)
                {
                    avatarInitializable.InitializeAvatar(args.EntityGuid, NameQueryable.RetrieveAsync(args.EntityGuid));
                }

                //This will actually re-initialize the IK for the new avatar, since the old one is now gone.
                ikRootGameObject.GetComponent <IIKReinitializable>().ReInitialize();
            }
            catch (Exception e)
            {
                if (Logger.IsErrorEnabled)
                {
                    Logger.Error($"Failed to create Avatar for Entity: {args.EntityGuid}. Error: {e.Message}\n\nStack: {e.StackTrace}");
                }

                throw;
            }
        }
示例#5
0
 public void InitializeTrackerGameObject(NetworkEntityGuid entityGuid)
 {
     //We now use head instead of camera because it doesn't make sense if they're 3rd person camera.
     //Cache the gameobject that trackers voice.
     TrackerObject = GameObjectDirectoryMappable.RetrieveEntity(entityGuid).GetGameObject(EntityGameObjectDirectory.Type.HeadRoot).transform;
 }