Assignment for RMIT Mixed Reality in 2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

64 lines
1.5 KiB

  1. namespace Oculus.Platform.Samples.VrHoops
  2. {
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. using Oculus.Platform.Models;
  6. public class PlayerArea : MonoBehaviour
  7. {
  8. // the prefab for the ball that players will shoot
  9. [SerializeField] private GameObject m_ballPrefab = null;
  10. // cached gameobject that where the player camera will move to
  11. private GameObject m_playerHead;
  12. // cached Text component where we'll render the player's name
  13. private Text m_nameText;
  14. // cached component used to align the backboard movement between devices
  15. private P2PNetworkGoal m_p2pGoal;
  16. public Player Player
  17. {
  18. get { return m_playerHead.GetComponent<Player>(); }
  19. }
  20. public Text NameText
  21. {
  22. get { return m_nameText; }
  23. }
  24. void Awake()
  25. {
  26. m_playerHead = gameObject.transform.Find("Player Head").gameObject;
  27. m_nameText = gameObject.GetComponentsInChildren<Text>()[1];
  28. m_p2pGoal = gameObject.GetComponentInChildren<P2PNetworkGoal> ();
  29. }
  30. public T SetupForPlayer<T>(string name) where T : Player
  31. {
  32. var oldplayer = m_playerHead.GetComponent<Player>();
  33. if (oldplayer) Destroy(oldplayer);
  34. var player = m_playerHead.AddComponent<T>();
  35. player.BallPrefab = m_ballPrefab;
  36. m_nameText.text = name;
  37. if (player is RemotePlayer)
  38. {
  39. (player as RemotePlayer).Goal = m_p2pGoal;
  40. m_p2pGoal.SendUpdates = false;
  41. }
  42. else if (player is LocalPlayer)
  43. {
  44. m_p2pGoal.SendUpdates = true;
  45. }
  46. else
  47. {
  48. m_p2pGoal.SendUpdates = false;
  49. }
  50. return player;
  51. }
  52. }
  53. }