コード例 #1
0
    /// <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();
    }
コード例 #2
0
    /// <summary>
    /// Called when a user's avatar has changed.
    /// </summary>
    /// <param name="msg"></param>
    void UpdateUserAvatar(NetworkInMessage msg)
    {
        // Parse the message
        long userID = msg.ReadInt64();

        RemoteHeadInfo headInfo = GetRemoteHeadInfo(userID);

        headInfo.PlayerAvatarIndex = msg.ReadInt32();

        // Configure the remote user's head object
        if (headInfo.HeadObject != null)
        {
            Destroy(headInfo.HeadObject);
        }

        headInfo.HeadObject = Instantiate(PlayerAvatarStore.Instance.PlayerAvatars[headInfo.PlayerAvatarIndex]);
        headInfo.headObjectPositionOffset    = headInfo.HeadObject.transform.localPosition;
        headInfo.HeadObject.transform.parent = this.transform;
        headInfo.HeadObject.GetComponent <PlayerAvatarParameters>();
        FriendlyDrone droneScript = headInfo.HeadObject.GetComponentInChildren <FriendlyDrone>();

        droneScript.OwningUserId = userID;

        // And since we've been sent an avatar, the user is now ready to play.
        headInfo.HeadObject.GetComponentInChildren <MeshRenderer>().enabled = true;
        headInfo.Active = true;
    }
コード例 #3
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;
    }
コード例 #4
0
    /// <summary>
    /// Checks to see if the projectile should continue with destruction or
    /// safely bounce.
    /// </summary>
    /// <param name="collision"></param>
    /// <returns>true = use the collision for exploding, false = bounce.</returns>
    protected virtual bool HitPlayer(Collision collision)
    {
        if (collision.contacts[0].otherCollider.GetComponent <ExplodingBlob>() != null)
        {
            return(true);
        }

        // Spin on hit is attached to user's heads.
        FriendlyDrone soh = collision.contacts[0].otherCollider.GetComponent <FriendlyDrone>();

        if (soh != null)
        {
            soh.PlayHit();

            firstContact = true;

            if (OwningUserId == 0 && soh.OwningUserId != 0)
            {
                // And send the message that we hit someone.
                CustomMessages.Instance.SendUserHit(soh.OwningUserId);
            }

            return(true);
        }

        // Play the 'we hit something that's not the players head clip'.
        audioSource.clip = bounceSoundEffect;
        audioSource.Play();

        // Tell spatial mapping deformation that we hit this point.
        // This causes the shader to do a little animation around the hit position.
        if (SpatialMappingManager.Instance.gameObject.activeSelf)
        {
            SpatialMappingDeformation.Instance.SetHitPosition(collision.contacts[0].point);
        }

        return(false);
    }
コード例 #5
0
    /// <summary>
    /// Spawns a drone at the first position in the NavigationPath.
    /// </summary>
    /// <param name="navIndex">Index of NavigationPath, Color, and Speed to use for the underdrone.</param>
    public void SpawnDrone(int index)
    {
        // Create drone and set initial position, rotation, scale.
        DroneNavigationPath path  = NavigationPaths[index].gameObject.GetComponent <DroneNavigationPath>();
        GameObject          drone = (GameObject)Instantiate(DronePrefab);

        drone.transform.parent   = this.transform;
        drone.transform.position = path.NavigationPoints[0].position;
        drone.transform.LookAt(path.NavigationPoints[1].transform);
        drone.transform.localScale = new Vector3(0.72f, 0.72f, 0.72f);

        // Set drone's speed and navigation path.
        DroneBehavior behavior = drone.AddComponent <DroneBehavior>();

        behavior.NavPath      = NavigationPaths[index].gameObject;
        behavior.Speed        = DroneSpeeds[index];
        behavior.NavPathIndex = index;

        // Set drone's color.
        FriendlyDrone friendly = drone.GetComponentInChildren <Animator>().gameObject.AddComponent <FriendlyDrone>();

        friendly.EmissiveColor = DroneColors[index];
    }