Example #1
0
        private void RemoveScripts <T>() where T : Component
        {
            PunLauncher punLauncher = (PunLauncher)target;

            foreach (GameObject sourceOfSyncTarget in punLauncher.rootsOfSyncTarget)
            {
                T[] photonScripts = sourceOfSyncTarget.GetComponentsInChildren <T>();

                foreach (T photonScript in photonScripts)
                {
                    Undo.DestroyObjectImmediate(photonScript);
                }
            }
        }
Example #2
0
        //void OnEnable()
        //{
        //}

        public override void OnInspectorGUI()
        {
            PunLauncher punLauncher = (PunLauncher)target;

            //if (punLauncher.humanMaxNumber != punLauncher.humanPositions.Length || punLauncher.humanMaxNumber != punLauncher.humanEulerAngles.Length)
            //{
            //	Undo.RecordObject(target, "Update Human Spawn Info");
            //	Array.Resize(ref punLauncher.humanPositions, punLauncher.humanMaxNumber);
            //	Array.Resize(ref punLauncher.humanEulerAngles, punLauncher.humanMaxNumber);
            //}

            //if (punLauncher.robotMaxNumber != punLauncher.robotPositions.Length || punLauncher.robotMaxNumber != punLauncher.robotEulerAngles.Length)
            //{
            //	Undo.RecordObject(target, "Update Robot Spawn Info");
            //	Array.Resize(ref punLauncher.robotPositions, punLauncher.robotMaxNumber);
            //	Array.Resize(ref punLauncher.robotEulerAngles, punLauncher.robotMaxNumber);
            //}

            base.OnInspectorGUI();

            GUILayout.Space(10);

            EditorGUILayout.BeginHorizontal();
            {
                GUILayout.FlexibleSpace();

                if (GUILayout.Button("Update Photon View", GUILayout.Width(200), GUILayout.Height(40)))
                {
                    Undo.RecordObject(target, "Update Photon View");

                    // Remove photon scripts
                    RemoveScripts <PhotonTransformView>();
                    RemoveScripts <LocalTransformView>();
                    RemoveScripts <PhotonRigidbodyView>();
                    RemoveScripts <PhotonView>();
//					RemoveScripts<PunOwnerChangerForObject>();

                    // Add photon scripts
                    List <GameObject> roomObjects = new List <GameObject>();

                    foreach (GameObject sourceOfSyncTarget in punLauncher.rootsOfSyncTarget)
                    {
                        Rigidbody[] syncTargetRigidbodies = sourceOfSyncTarget.GetComponentsInChildren <Rigidbody>();

                        foreach (Rigidbody syncTargetRigidbody in syncTargetRigidbodies)
                        {
                            roomObjects.Add(syncTargetRigidbody.gameObject);
                        }
                    }

                    punLauncher.SetRoomObjects(roomObjects);

                    foreach (GameObject roomObject in roomObjects)
                    {
                        PhotonView photonView = Undo.AddComponent <PhotonView>(roomObject);
                        photonView.OwnershipTransfer  = OwnershipOption.Takeover;
                        photonView.Synchronization    = ViewSynchronization.ReliableDeltaCompressed;
                        photonView.ObservedComponents = new List <Component>();

//						PhotonTransformView photonTransformView = Undo.AddComponent<PhotonTransformView>(roomObject);
                        LocalTransformView localTransformView = Undo.AddComponent <LocalTransformView>(roomObject);
//						PhotonRigidbodyView photonRigidbodyView = Undo.AddComponent<PhotonRigidbodyView>(roomObject);

//						photonView.ObservedComponents.Add(photonTransformView);
                        photonView.ObservedComponents.Add(localTransformView);
//						photonView.ObservedComponents.Add(photonRigidbodyView);

//						Undo.AddComponent<PunOwnerChangerForObject>(roomObject);
                    }
                }

                GUILayout.FlexibleSpace();
            }
            EditorGUILayout.EndHorizontal();

            GUILayout.Space(10);
        }