public void Setup() { _photonView = GetComponent <PhotonView>(); _photonRigidbodyView = GetComponent <PhotonRigidbodyView>(); _photonTransformView = GetComponent <PhotonTransformView>(); _photonLiveRemote = GetComponent <PhotonLiveRemote>(); _photonPuntuation = GetComponent <PhotonPuntuation>(); _photonView.ObservedComponents.Clear(); _photonView.ObservedComponents.Add(_photonRigidbodyView); _photonView.ObservedComponents.Add(_photonTransformView); _photonView.ObservedComponents.Add(_photonLiveRemote); _photonView.ObservedComponents.Add(_photonPuntuation); _photonView.ObservedComponents.Add(this); }
private void OnGUI() { // Find views that have a rigidbody component. if (GUILayout.Button("Find")) { targetedViews = FindObjectsOfType <PhotonView>().Where((view) => view.GetComponent <Rigidbody>() != null).ToList(); targetedViews.Sort((a, b) => String.Compare(a.gameObject.name, b.gameObject.name)); } // Add rigidbody views to the photon views. if (GUILayout.Button("Add")) { for (int i = 0; i < targetedViews.Count; i++) { PhotonRigidbodyView rigidbodyView = targetedViews[i].GetOrAddComponent <PhotonRigidbodyView>(); if (!targetedViews[i].ObservedComponents.Contains(rigidbodyView)) { Undo.RegisterCompleteObjectUndo(targetedViews[i], "Setup rigidbody view"); targetedViews[i].ObservedComponents.Add(rigidbodyView); } } } // Draw the targeted views. scrollPosition = EditorGUILayout.BeginScrollView(scrollPosition); for (int i = 0; i < targetedViews.Count; i++) { GUILayout.BeginHorizontal(); if (targetedViews[i] == null || GUILayout.Button("✖", GUILayout.Width(20))) { targetedViews.RemoveAt(i); GUILayout.EndHorizontal(); continue; } UnityEngine.Object viewProperty = targetedViews[i]; viewProperty = EditorGUILayout.ObjectField(viewProperty, typeof(PhotonView), true); GUILayout.Label(targetedViews[i].ViewID.ToString(), GUILayout.Width(50)); if (GUILayout.Button("↗", GUILayout.Width(18))) { Selection.activeGameObject = targetedViews[i].gameObject; } GUILayout.EndHorizontal(); } EditorGUILayout.EndScrollView(); }
public void FirePrefabeExploding() { //Merging all GameObject on PlanetPrefab in same array allArray GameObject[] likeArray; GameObject[] dissArray; GameObject[] allArray; likeArray = GameObject.FindGameObjectsWithTag("Like"); dissArray = GameObject.FindGameObjectsWithTag("Diss"); allArray = likeArray.Concat(dissArray).ToArray(); //Adding Rigidbody / Photon components to allArray foreach (GameObject allPrefabs in allArray) { //Rigidbody Rigidbody allPrefabsRB = allPrefabs.gameObject.AddComponent <Rigidbody>(); //Networking PhotonView allPrefabsPhoton = allPrefabs.AddComponent <PhotonView>(); PhotonTransformView allPrefabsTranPhoton = allPrefabs.AddComponent <PhotonTransformView>(); PhotonRigidbodyView allPrefabsRBPhoton = allPrefabs.gameObject.AddComponent <PhotonRigidbodyView>(); //Setting Components before add AddComponent /*allPrefabsPhoton.ObservedComponents.Add(allPrefabsTranPhoton); * allPrefabsPhoton.ObservedComponents.Add(allPrefabsRBPhoton);*/ allPrefabsRB.AddForce(transform.up * explodingForceStrength, ForceMode.Impulse); allPrefabsRB.useGravity = true; allPrefabsRBPhoton.m_SynchronizeVelocity = true; allPrefabsRBPhoton.m_SynchronizeAngularVelocity = true; //Destroy allPrefabs in any server with delay Destroy(allPrefabs, explodingDestoryTime); //PhotonNetwork.Destroy(allPrefabs); } }