} // ValidatePreFlightCheckOnGameObject /// <summary> /// Sanitizes the game object and check photonView observing fsm, else complain. /// If photonView there, will insert PlayMakerPhotonView inbetween. /// </summary> /// <param name='go'> /// Go. /// </param> public void SanitizeGameObject(GameObject go) { if (go == null) { return; } PhotonView[] allPhotonViews = go.GetComponentsInChildren <PhotonView>(); // now make sure all fsm with network synchronized variable have a photonView attached List <PlayMakerFSM> fsmsToObserve = GetFsmsWithNetworkSynchedVariables(go); Debug.Log("found fsm to observe : " + fsmsToObserve.Count); foreach (PlayMakerFSM fsm in fsmsToObserve) { bool ok = false; foreach (PhotonView photonView in allPhotonViews) { if (photonView.observed == fsm) { ok = true; break; } } if (!ok) { Debug.LogError( string.Format( "Fsm component '{0}' on gameObject '{1}' has variable checked for network synching, but no PhotonView component is observing this fsm", fsm.name, fsm.gameObject.name) ); } } // now inject PlayMakerPhotonView where required. foreach (PhotonView photonView in allPhotonViews) { Debug.Log(" photon view observing : " + photonView.observed + " " + photonView.viewID); if (photonView.observed is PlayMakerFSM) { PlayMakerFSM fsm = (PlayMakerFSM)photonView.observed; PlayMakerPhotonView synchProxy = photonView.gameObject.AddComponent <PlayMakerPhotonView>(); Debug.Log("switching observed"); synchProxy.observed = fsm; photonView.observed = synchProxy; } } } // SanitizeGameObject
}// ValidatePreFlightCheckOnGameObject /// <summary> /// Sanitizes the game object and check photonView observing fsm, else complain. /// If photonView there, will insert PlayMakerPhotonView inbetween. /// </summary> /// <param name='go'> /// Go. /// </param> public void SanitizeGameObject(GameObject go) { if (go == null) { return; } PhotonView[] allPhotonViews = go.GetComponentsInChildren <PhotonView>(); // now make sure all fsm with network synchronized variable have a photonView attached List <PlayMakerFSM> fsmsToObserve = GetFsmsWithNetworkSynchedVariables(go); Debug.Log("found fsm to observe : " + fsmsToObserve.Count); foreach (PlayMakerFSM fsm in fsmsToObserve) { bool ok = false; foreach (PhotonView _photonView in allPhotonViews) { foreach (Component _comp in _photonView.ObservedComponents) { if (_comp == fsm) { ok = true; break; } } } if (!ok) { Debug.LogError( string.Format( "Fsm component '{0}' on gameObject '{1}' has variable checked for network synching, but no PhotonView component is observing this fsm", fsm.name, fsm.gameObject.name) ); } } // now inject PlayMakerPhotonView where required. foreach (PhotonView _photonView in allPhotonViews) { Debug.Log(" photon view observing : " + _photonView.ObservedComponents.ToStringFull() + " " + _photonView.ViewID); Component _comp_i; for (int i = 0; i < _photonView.ObservedComponents.Count; i++) { _comp_i = _photonView.ObservedComponents[i]; if (_comp_i is PlayMakerFSM) { PlayMakerFSM fsm = (PlayMakerFSM)_comp_i; PlayMakerPhotonView synchProxy = _photonView.gameObject.AddComponent <PlayMakerPhotonView>(); Debug.Log("switching observed <" + i + ">"); synchProxy.observed = fsm; _photonView.ObservedComponents[i] = synchProxy; } i++; } Debug.Log(" photon view observing job done : " + _photonView.ObservedComponents.ToStringFull() + " " + _photonView.ViewID); } }// SanitizeGameObject