Exemplo n.º 1
0
    private void TransferPlayerAsNeeded()
    {
        // What actors want to be controlled by the player?
        List <VoosActor> actorsToControl = temp;

        engine.GetActorsControlledByVirtualPlayerId(virtualPlayerId, actorsToControl);
        // What actor is the player is currently controlling?
        // (use null to mean a placeholder actor)
        VoosActor currentActor = userMain.GetPlayerActor();
        // What actor should the player be controlling?
        // It's the one match. If there is not exactly one match, then none (conflict).
        VoosActor actorToControl = actorsToControl.Count == 1 ? actorsToControl[0] : null;

        // Transfer control if needed.
        if (actorToControl != currentActor)
        {
            TransferUserTo(actorToControl);
        }
        // Request ownership periodically, if we don't own ourselves.
        requestOwnershipCooldown -= Time.unscaledDeltaTime;
        if (actorToControl != null && !actorToControl.IsLocallyOwned() && requestOwnershipCooldown <= 0)
        {
            requestOwnershipCooldown = 2;
            actorToControl.RequestOwnership();
        }
        // Show error message if applicable.
        UpdateWarningState(actorsToControl);
    }