public void Instantiate_GameObjects() { // first: instantiate the sdk-manager and the correlated setup-switcher // if the flag is not set you have to set a SDK-Manager and Setup-Switcher manually in the scene for it to work! if (instantiateSDKManager) { InstantiateSdkManager(); } else { vrmInstance = GameObject.FindWithTag("SDK_Manager"); } //Player Model Instantiation if (playerAvatar != null) { if (PhotonNetwork.IsConnected) { playerModelInstance = PhotonNetwork.Instantiate(playerAvatar.name, transform.position, transform.rotation); } else { playerModelInstance = Instantiate(playerAvatar, transform.position, transform.rotation); } } if (evaluateAvatar) { MUVRTK_Evaluation avatarEvaluator = gameObject.AddComponent <MUVRTK_Evaluation>(); avatarEvaluator.trackPositionData = true; avatarEvaluator.photonViewOfTrackedObject = playerModelInstance.GetPhotonView(); } //Networked Controller Model Instantiation if (controllerModels.Length > 0 && showControllersOverNetwork && PhotonNetwork.IsConnected) { //If you want the same Model applied to both Controllers if (controllerModels.Length == 1) { controllerModelInstances[0] = PhotonNetwork.Instantiate(controllerModels[0].name, transform.position, transform.rotation); controllerModelInstances[1] = PhotonNetwork.Instantiate(controllerModels[0].name, transform.position, transform.rotation); } if (controllerModels.Length == 2) { //If you want different Models applied to both Controllers controllerModelInstances[0] = PhotonNetwork.Instantiate(controllerModels[0].name, transform.position, transform.rotation); controllerModelInstances[1] = PhotonNetwork.Instantiate(controllerModels[1].name, transform.position, transform.rotation); } } //All other Networked Objects Instantiation, including Controller Script Aliases if (PhotonNetwork.IsConnected) { //Controler Script Aliases if (controllerScriptAliases.Length > 1) { controllerScriptAliasInstances[0] = PhotonNetwork.Instantiate(controllerScriptAliases[0].name, transform.position, transform.rotation); vrmInstance.GetComponent <VRTK_SDKManager>().scriptAliasLeftController = controllerScriptAliasInstances[0]; controllerScriptAliasInstances[1] = PhotonNetwork.Instantiate(controllerScriptAliases[1].name, transform.position, transform.rotation); vrmInstance.GetComponent <VRTK_SDKManager>().scriptAliasRightController = controllerScriptAliasInstances[1]; controllerScriptAliasesLoaded = true; } if (controllerScriptAliases.Length == 1) { controllerScriptAliasInstances[0] = PhotonNetwork.Instantiate(controllerScriptAliases[0].name, transform.position, transform.rotation); vrmInstance.GetComponent <VRTK_SDKManager>().scriptAliasLeftController = controllerScriptAliasInstances[0]; controllerScriptAliasInstances[1] = PhotonNetwork.Instantiate(controllerScriptAliases[0].name, transform.position, transform.rotation); vrmInstance.GetComponent <VRTK_SDKManager>().scriptAliasRightController = controllerScriptAliasInstances[1]; controllerScriptAliasesLoaded = true; } else { Debug.LogWarning(name + ": No ControllerScriptAliases found!"); } foreach (GameObject go in controllerScriptAliasInstances) { if (go.GetComponent <MUVRTK_PersonalSpace>()) { personalSpace = go.GetComponent <MUVRTK_PersonalSpace>(); personalSpace.avatarInstance = playerModelInstance; } } //All else (interactive objects and the like) foreach (GameObject go in objectsToInstantiateOverTheNetwork) { PhotonNetwork.InstantiateSceneObject(go.name, new Vector3(Random.value * networkedOffset, Random.value, Random.value * networkedOffset), Quaternion.Euler(0, 0, 0)); } } else { //Controller Script Aliases foreach (GameObject go in controllerScriptAliases) { Instantiate(go, transform.position, transform.rotation); } //All networked objects foreach (GameObject go in objectsToInstantiateOverTheNetwork) { Instantiate(go, new Vector3(Random.value * networkedOffset, 1, Random.value * networkedOffset), Quaternion.Euler(0, 0, 0)); } } //All local objects foreach (GameObject go in objectsToInstantiateLocally) { Instantiate(go, new Vector3(Random.value * localOffset, 1, Random.value * localOffset), Quaternion.Euler(0, 0, 0)); } }
void Update() { if (rightControllerInstance == null) { rightControllerInstance = GameObject.FindWithTag("RightController"); } if (leftControllerInstance == null) { leftControllerInstance = GameObject.FindWithTag("LeftController"); } // This waits for the vrm and model-instantiation and then binds the two together in holy matrimony. if (!cameraLoaded) { if (vrmInstance != null) { if (vrmInstance.GetComponentInChildren <Camera>() != null) { if (playerModelInstance != null) { BindModelToVRM(playerModelInstance, vrmInstance, "Camera"); cameraLoaded = true; } } } } if (!leftControllerModelLoaded) { //only replace the current controller meshes if any new models have been added to the array if (controllerModels.Length > 0 && showControllersOverNetwork) { if (leftControllerInstance != null) { if (leftControllerInstance.transform.GetChild(0).transform.childCount > 0) { if (vrmInstance != null) { BindModelToVRM(controllerModelInstances[0], vrmInstance, "LeftController"); DeactivateCurrentControllerModel(leftControllerInstance); if (evaluateControllers) { MUVRTK_Evaluation leftControllerEvaluator = gameObject.AddComponent <MUVRTK_Evaluation>(); leftControllerEvaluator.trackPositionData = true; leftControllerEvaluator.nonNetworkedGameObjectToTrack = leftControllerInstance; } leftControllerModelLoaded = true; } } } } } if (!rightControllerModelLoaded) { //only replace the current controller meshes if any new models have been added to the array if (controllerModels.Length > 0 && showControllersOverNetwork) { if (rightControllerInstance != null) { if (rightControllerInstance.transform.GetChild(0).transform.childCount > 0) { if (vrmInstance != null) { BindModelToVRM(controllerModelInstances[1], vrmInstance, "RightController"); DeactivateCurrentControllerModel(rightControllerInstance); if (evaluateControllers) { MUVRTK_Evaluation rightControllerEvaluator = gameObject.AddComponent <MUVRTK_Evaluation>(); rightControllerEvaluator.trackPositionData = true; rightControllerEvaluator.nonNetworkedGameObjectToTrack = rightControllerInstance; } rightControllerModelLoaded = true; } } } } } if (enableTeleport) { bool startedTeleportEnable = false; if (!startedTeleportEnable) { if (controllerScriptAliasesLoaded) { TeleportEnable(); startedTeleportEnable = true; } } } if (!instantiateSDKManager) { if (controllerScriptAliasesLoaded) { controllerScriptAliasInstances[0].transform.parent = leftControllerInstance.transform; controllerScriptAliasInstances[1].transform.parent = rightControllerInstance.transform; } } ///when everything else is loaded, then re-enable the BasicTeleport-Script to make it work. if (playareascriptloaded) { if (cameraLoaded) { if (controllerScriptAliasesLoaded) { // Making sure the OnEnable-Method is called in the Basic-Teleport-Script. playArea.SetActive(false); playArea.SetActive(true); } } } }