Exemple #1
0
    // Update is called once per frame
    void Update()
    {
        //We create a new Translation and Rotation from the transform of the GameObject
        //The GameObject Translation and Rotation is updated by the pose driver
        var arTranslation = new Translation {
            Value = transform.position
        };
        var arRotation = new Rotation {
            Value = transform.rotation
        };
        //Now we update our ARPoseComponent with the updated Pose Driver data
        var arPose = new ARPoseComponent {
            translation = arTranslation,
            rotation    = arRotation
        };

        m_ClientSimGroup.SetSingleton <ARPoseComponent>(arPose);

        //If the player was spawned, we will move the AR camera to behind the spawn location
        if (!m_SpawnPositionQuery.IsEmptyIgnoreFilter)
        {
            //We grab the component from the Singleton
            var spawnPosition = m_ClientSimGroup.GetSingleton <SpawnPositionForARComponent>();
            // Debug.Log("spawn position is: " + spawnPosition.spawnTranslation.ToString());

            //We set the new pose to behind the player (0, 2, -10) (this is the same value the player is put in front of the pose in InputResponseMovementSystem)
            var newPoseTranslation = (spawnPosition.spawnTranslation) + (math.mul(spawnPosition.spawnRotation, new float3(0, 2, 0)).xyz) - (math.mul(spawnPosition.spawnRotation, new float3(0, 0, 10)).xyz);
            //The rotation will be the same
            var newPoseRotation = (spawnPosition.spawnRotation);

            // Debug.Log("calculated camera position is: " + newPoseTranslation.ToString());

            //MakeContentAppearAt requires a transform even though it is never used so we create a dummy transform
            Transform dummyTransform = new GameObject().transform;
            //First we will undo our last MakeContentAppearAt to go back to "normal"
            m_ARSessionOrigin.MakeContentAppearAt(dummyTransform, -1f * m_LastTranslation, Quaternion.Inverse(m_LastRotation));

            //Now we will update our LastTranslation and LastRotations to the values we are about to use
            //Because of how MakeContentAppearAt works we must do the inverse to move our camera where we want it
            m_LastTranslation = -1f * newPoseTranslation;
            m_LastRotation    = Quaternion.Inverse(newPoseRotation);
            //Now that we have set the variables we will use them to adjust the AR pose
            m_ARSessionOrigin.MakeContentAppearAt(dummyTransform, m_LastTranslation, m_LastRotation);

            // Debug.Log("transform after MakeContentAppearAt: " + transform.position.ToString());
            //Now we delete the entity so this only runs during an initial spawn
            m_ClientWorld.EntityManager.DestroyEntity(m_ClientSimGroup.GetSingletonEntity <SpawnPositionForARComponent>());
        }
    }
Exemple #2
0
    // Update is called once per frame
    void Update()
    {
        //We do not need to continue if we do not have a GameNameComponent yet
        if (m_GameNameComponentQuery.IsEmptyIgnoreFilter)
        {
            return;
        }

        //If we have a GameNameComponent we need to update ClientServerInfo and then our UI
        //We only need to do this once so we have a boolean flag to prevent this from being ran more than once
        if (!gameNameIsSet)
        {
            ClientServerInfo.GameName = m_ClientWorldSimulationSystemGroup.GetSingleton <GameNameComponent>().GameName.ToString();
            m_GameName.text           = ClientServerInfo.GameName;
            gameNameIsSet             = true;
        }

        //Now we will handle updating scoring
        //We check if the scoring entities exist, otherwise why bother
        if (m_NetworkConnectionEntityQuery.IsEmptyIgnoreFilter || m_PlayerScoresQuery.IsEmptyIgnoreFilter || m_HighestScoreQuery.IsEmptyIgnoreFilter)
        {
            return;
        }

        //We set our NetworkId once
        if (!networkIdIsSet)
        {
            m_NetworkId    = m_ClientWorldSimulationSystemGroup.GetSingleton <NetworkIdComponent>().Value;
            networkIdIsSet = true;
        }

        //We set our PlayerScore entity once
        //Grab PlayerScore entities
        var playerScoresNative = m_PlayerScoresQuery.ToEntityArray(Allocator.TempJob);

        //For each entity find the entity with a matching NetworkId
        for (int j = 0; j < playerScoresNative.Length; j++)
        {
            //Grab the NetworkId of the PlayerScore entity
            var netId = m_ClientWorldSimulationSystemGroup.GetComponentDataFromEntity <PlayerScoreComponent>(true)[playerScoresNative[j]].networkId;
            //Check if it matches our NetworkId that we set
            if (netId == m_NetworkId)
            {
                //If it matches set our ClientPlayerScoreEntity
                ClientPlayerScoreEntity = playerScoresNative[j];
            }
        }
        //No need for this anymore
        playerScoresNative.Dispose();

        //Every Update() we get grab the PlayerScoreComponent from our set Entity and check it out with current values
        var playerScoreComponent = m_ClientWorldSimulationSystemGroup.GetComponentDataFromEntity <PlayerScoreComponent>(true)[ClientPlayerScoreEntity];

        //Check if current is different and update to ghost value
        if (m_CurrentScore != playerScoreComponent.currentScore)
        {
            //If it is make it match the ghost value
            m_CurrentScore = playerScoreComponent.currentScore;
            UpdateCurrentScore();
        }
        //Check if current is different and update to ghost value
        if (m_HighScore != playerScoreComponent.highScore)
        {
            //If it is make it match the ghost value
            m_HighScore = playerScoreComponent.highScore;
            UpdateHighScore();
        }

        //We grab our HighestScoreComponent
        var highestScoreNative = m_HighestScoreQuery.ToComponentDataArray <HighestScoreComponent>(Allocator.TempJob);

        //We check if its current  value is different than ghost value
        if (highestScoreNative[0].highestScore != m_HighestScore)
        {
            //If it is make it match the ghost value
            m_HighestScore     = highestScoreNative[0].highestScore;
            m_HighestScoreName = highestScoreNative[0].playerName.ToString();
            UpdateHighestScore();
        }
        highestScoreNative.Dispose();
    }