/// <summary>
    /// Process user hit.
    /// </summary>
    /// <param name="msg"></param>
    void ProcessUserHit(NetworkInMessage msg)
    {
        // Parse the message
        long userID    = msg.ReadInt64();
        long hitUserId = msg.ReadInt64();

        RemoteHeadInfo headInfo = GetRemoteHeadInfo(userID);
        FriendlyDrone  soh      = headInfo.HeadObject.GetComponentInChildren <FriendlyDrone>();

        if (soh != null)
        {
            soh.Happy();
        }
        headInfo.HitCount++;

        AudioSource            remoteHeadAudio = headInfo.HeadObject.GetComponentInChildren <AudioSource>();
        PlayerAvatarParameters playerParams    = PlayerAvatarStore.Instance.PlayerAvatars[headInfo.PlayerAvatarIndex].GetComponent <PlayerAvatarParameters>();

        if (hitUserId == customMessages.localUserID)
        {
            // ack they hit ME!!!
            // Play the 'they hit me' sound.
            AudioSource            localAudioSource  = Camera.main.GetComponent <AudioSource>();
            PlayerAvatarParameters localPlayerParams = PlayerAvatarStore.Instance.PlayerAvatars[LocalPlayerManager.Instance.AvatarIndex].GetComponent <PlayerAvatarParameters>();
            localAudioSource.clip = localPlayerParams.SomeoneHitPlayerClip;
            localAudioSource.Play();
        }

        // Play the 'I hit someone' sound for the user who hit someone.
        remoteHeadAudio.clip = playerParams.PlayerHitSomeoneClip;
        remoteHeadAudio.Play();
    }
Esempio n. 2
0
    /// <summary>
    /// Adds a new projectile to the world.
    /// </summary>
    /// <param name="start">Position to shoot from</param>
    /// <param name="direction">Position to shoot toward</param>
    /// <param name="radius">Size of destruction when colliding.</param>
    void ShootProjectile(Vector3 start, Vector3 direction, long OwningUser)
    {
        // Need to know the index in the PlayerAvatarStore to grab for this projectile's behavior.
        int AvatarIndex = 0;

        // Special case ID 0 to mean the local user.
        if (OwningUser == 0)
        {
            AvatarIndex = LocalPlayerManager.Instance.AvatarIndex;
        }
        else
        {
            RemotePlayerManager.RemoteHeadInfo headInfo = RemotePlayerManager.Instance.GetRemoteHeadInfo(OwningUser);
            AvatarIndex = headInfo.PlayerAvatarIndex;
        }

        PlayerAvatarParameters ownerAvatarParameters = PlayerAvatarStore.Instance.PlayerAvatars[AvatarIndex].GetComponent <PlayerAvatarParameters>();

        GameObject spawnedProjectile = (GameObject)Instantiate(ownerAvatarParameters.PlayerShotObject);

        spawnedProjectile.transform.position = start;

        // Set projectile color to be the same as the avatar color.
        FriendlyDrone drone = PlayerAvatarStore.Instance.PlayerAvatars[AvatarIndex].GetComponentInChildren <FriendlyDrone>();

        if (drone != null)
        {
            spawnedProjectile.GetComponentInChildren <Renderer>().materials[1].SetColor("_EmissionColor", drone.EmissiveColor);
            foreach (ParticleSystem particleSystem in spawnedProjectile.transform.GetComponentsInChildren <ParticleSystem>())
            {
                ParticleSystem.MainModule main = particleSystem.main;
                main.startColor = drone.EmissiveColor;
            }
        }

        ProjectileBehavior pc = spawnedProjectile.GetComponentInChildren <ProjectileBehavior>();

        pc.startDir     = direction;
        pc.OwningUserId = OwningUser;
    }
    /// <summary>
    /// Changes the model used to represent a user.
    /// </summary>
    public void SetAvatar(GameObject avatar)
    {
        PlayerAvatarParameters playerParams = avatar.GetComponent <PlayerAvatarParameters>();

        GetComponent <MeshFilter>().mesh       = avatar.GetComponent <MeshFilter>().sharedMesh;
        GetComponent <MeshRenderer>().material = avatar.GetComponent <MeshRenderer>().sharedMaterial;

        Transform avatarTransform = avatar.GetComponent <Transform>();

        transform.localPosition = avatarTransform.localPosition;
        transform.localRotation = avatarTransform.localRotation;
        transform.localScale    = avatarTransform.localScale;

        MeshCollider mc = GetComponent <MeshCollider>();

        mc.sharedMesh = null;
        mc.sharedMesh = GetComponent <MeshFilter>().mesh;

        AudioSource audioSource = GetComponent <AudioSource>();

        audioSource.clip = playerParams.PlayerJoinedClip;
        audioSource.Play();
    }