コード例 #1
0
    public void ResetAuthorityForClientCubes(int clientIndex)
    {
        int authorityIndex = clientIndex + 1;

        for (int i = 0; i < Constants.NumCubes; ++i)
        {
            NetworkInfo networkInfo = cubes[i].GetComponent <NetworkInfo>();

            if (networkInfo.GetAuthorityIndex() == authorityIndex)
            {
                Debug.Log("Returning cube " + i + " to default authority");

                networkInfo.DetachCubeFromPlayer();

                networkInfo.SetAuthorityIndex(0);
                networkInfo.SetAuthoritySequence(0);
                networkInfo.IncreaseOwnershipSequence();

                var rigidBody = cubes[i].GetComponent <Rigidbody>();

                if (rigidBody.IsSleeping())
                {
                    rigidBody.WakeUp();
                }

                ResetCubeRingBuffer(i);
            }
        }
    }
コード例 #2
0
    void DetachFromHand(ref HandData hand)
    {
        // IMPORTANT: This happens when passing a cube from hand-to-hand
        if (hand.gripObject == null)
        {
            return;
        }

        NetworkInfo networkInfo = hand.gripObject.GetComponent <NetworkInfo>();

        networkInfo.DetachCubeFromPlayer();

#if DEBUG_AUTHORITY
        Debug.Log("client " + context.GetClientIndex() + " released cube " + networkInfo.GetCubeId() + ". ownership sequence is " + networkInfo.GetOwnershipSequence() + ", authority sequence is " + networkInfo.GetAuthoritySequence());
#endif // #if DEBUG_AUTHORITY
    }
コード例 #3
0
    public static void ApplyCubeState(Rigidbody rigidBody, NetworkInfo networkInfo, ref CubeState cubeState, ref Vector3 origin, bool smoothing = false)
    {
        if (networkInfo.IsHeldByPlayer())
        {
            networkInfo.DetachCubeFromPlayer();
        }

        if (cubeState.active)
        {
            if (rigidBody.IsSleeping())
            {
                rigidBody.WakeUp();
            }
        }

        if (!cubeState.active)
        {
            if (!rigidBody.IsSleeping())
            {
                rigidBody.Sleep();
            }
        }

        networkInfo.SetAuthorityIndex(cubeState.authorityIndex);
        networkInfo.SetAuthoritySequence(cubeState.authoritySequence);
        networkInfo.SetOwnershipSequence(cubeState.ownershipSequence);

        Vector3 position = new Vector3(cubeState.position_x, cubeState.position_y, cubeState.position_z) * 1.0f / Constants.UnitsPerMeter + origin;

        Quaternion rotation = SmallestThreeToQuaternion(cubeState.rotation_largest, cubeState.rotation_a, cubeState.rotation_b, cubeState.rotation_c);

        if (smoothing)
        {
            networkInfo.MoveWithSmoothing(position, rotation);
        }
        else
        {
            rigidBody.position = position;
            rigidBody.rotation = rotation;
        }

        rigidBody.velocity = new Vector3(cubeState.linear_velocity_x, cubeState.linear_velocity_y, cubeState.linear_velocity_z) * 1.0f / Constants.UnitsPerMeter;

        rigidBody.angularVelocity = new Vector3(cubeState.angular_velocity_x, cubeState.angular_velocity_y, cubeState.angular_velocity_z) * 1.0f / Constants.UnitsPerMeter;
    }
コード例 #4
0
    void CreateCubes()
    {
        Profiler.BeginSample("CreateCubes");

        Vector3 origin = GetOrigin();

        for (int i = 0; i < Constants.NumCubes; i++)
        {
            if (!cubes[i])
            {
                // cube initial create

                cubes[i] = (GameObject)Instantiate(cubePrefab, cubePositions[i] + origin, Quaternion.identity);

                cubes[i].layer = this.gameObject.layer;

                var rigidBody = cubes[i].GetComponent <Rigidbody>();

                rigidBody.maxDepenetrationVelocity = Constants.PushOutVelocity;           // this is *extremely* important to reduce jitter in the remote view of large stacks of rigid bodies

                NetworkInfo networkInfo = cubes[i].GetComponent <NetworkInfo>();

                networkInfo.touching.layer = GetTouchingLayer();

                networkInfo.Initialize(this, i);
            }
            else
            {
                // cube already exists: force it back to initial state

                var rigidBody = cubes[i].GetComponent <Rigidbody>();

                if (rigidBody.IsSleeping())
                {
                    rigidBody.WakeUp();
                }

                rigidBody.position        = cubePositions[i] + origin;
                rigidBody.rotation        = Quaternion.identity;
                rigidBody.velocity        = Vector3.zero;
                rigidBody.angularVelocity = Vector3.zero;

                ResetCubeRingBuffer(i);

                NetworkInfo networkInfo = cubes[i].GetComponent <NetworkInfo>();

                networkInfo.DetachCubeFromPlayer();

                networkInfo.SetAuthorityIndex(0);
                networkInfo.SetAuthoritySequence(0);
                networkInfo.SetOwnershipSequence(0);

                Renderer renderer = networkInfo.smoothed.GetComponent <Renderer>();

                renderer.material = authorityMaterials[0];

                networkInfo.m_positionError = Vector3.zero;
                networkInfo.m_rotationError = Quaternion.identity;

                cubes[i].transform.parent = null;
            }
        }

        Profiler.EndSample();
    }