Beispiel #1
0
        public override void OnEnable()
        {
            nstMaster = (NSTMaster)target;
            mna       = nstMaster.EnsureHasCorrectAdapter();

            headerName  = HeaderMasterName;
            headerColor = HeaderSettingsColor;
            base.OnEnable();
        }
Beispiel #2
0
        /// <summary>
        /// Returns true if this is the singleton, false if we had to destroy it.
        /// </summary>
        private bool EnforceSingleton()
        {
            if (single && single != this)
            {
                Destroy(this);
                return(false);
            }

            single = this;
            return(true);
        }
Beispiel #3
0
        public override void OnInspectorGUI()
        {
            serializedObject.Update();

            MasterNetAdapter _target = (MasterNetAdapter)target;

            NetAdapterTools.EnsureSceneNetLibDependencies();

            base.OnInspectorGUI();
            EditorGUILayout.HelpBox("This is the UNET adapter. To work with Photon PUN, switch the Network Library.", MessageType.None);
            NetLibrarySettings.Single.DrawGui(true, false);
        }
Beispiel #4
0
 /// <summary>
 /// Start the connection process.
 /// - If already connected, we attempt joining a random room
 /// - if not yet connected, Connect this application instance to Photon Cloud Network
 /// </summary>
 public void Connect()
 {
     // we check if we are connected or not, we join if we are , else we initiate the connection to the server.
     if (MasterNetAdapter.PUN_Connected)
     {
         MasterNetAdapter.PUN_JoinRandomRoom();
     }
     else
     {
         MasterNetAdapter.PUN_ConnectUsingSettings(_gameVersion);
     }
 }
Beispiel #5
0
        private void SpawnLocalPlayer()
        {
            // we're in a room. spawn a character for the local player. it gets synced by using PhotonNetwork.Instantiate
            if (MasterNetAdapter.NetLib == NetworkLibrary.PUN)
            {
                Transform  tr  = NSTSamplePlayerSpawn.GetRandomSpawnPoint();
                Vector3    pos = (tr) ? tr.position : Vector3.zero;
                Quaternion rot = (tr) ? tr.rotation : Quaternion.identity;

                MasterNetAdapter.Spawn(playerPrefab, pos, rot, null);
            }
        }
Beispiel #6
0
        /// <summary>
        /// Deep find and add of adapters to all NSTs objects in assets. Deferred actions that need to happen after a compile following library change.
        /// </summary>
        public static void TryToAddDependenciesEverywhere()
        {
            if (DependenciesHaveBeenAddedEverywhere)
            {
                return;
            }

            DebugX.Log("Adding NST Entities in all Assets");
            MasterNetAdapter.AddNstEntityComponentsEverywhere();

            // Now that prefabs in assets have been altered, make sure any scene objects revert to those prefabs
            RevertPrefabsInSceneWithComponentType <NetworkSyncTransform>();

            DependenciesHaveBeenAddedEverywhere = true;
        }
Beispiel #7
0
        public override void OnInspectorGUI()
        {
            nstMaster   = (NSTMaster)target;
            mna         = nstMaster.EnsureHasCorrectAdapter();
            nstSettings = NSTSettings.EnsureExistsInScene(NSTSettings.DEFAULT_GO_NAME);

            base.OnInspectorGUI();

            if (mna == null)
            {
                EditorGUILayout.HelpBox(
                    "No network library adapter found for '" +
                    Enum.GetName(typeof(NetworkLibrary), nstSettings.networkingLibrary) + "'", MessageType.Error);
            }

            EditorGUILayout.HelpBox("The NST Master is a required engine singleton. It collects and dispatches all NST Updates, and receives incoming updates from the network.", MessageType.None);
        }
Beispiel #8
0
        public override void OnInspectorGUI()
        {
            serializedObject.Update();

            MasterNetAdapter _target = (MasterNetAdapter)target;

            // make sure the network identiy has the correct settings as often as possible.
            ni = _target.GetComponent <NetworkIdentity>();
            ni.localPlayerAuthority = false;

            // kill the network adapter if it is the wrong one (user changed netlib selection)
            if (_target.KillMe && Event.current.type == EventType.Repaint)
            {
                DestroyImmediate(_target);
                return;
            }

            base.OnInspectorGUI();
            EditorGUILayout.HelpBox("This is the Adapter for UNET. To work with Photon (PUN) replace with the Photon Adapter.", MessageType.None);
        }
Beispiel #9
0
        //private void EnforceSingleton()
        //{
        //	// Base does singleton enforcement
        //	if (single != null && single != this)
        //	{
        //		Debug.LogWarning("Enforcing NSTMaster singleton. Multiples found.");
        //		Destroy(this);
        //	}
        //	single = this; ;
        //}

        //TODO add library selection logic here for selecting correct adapter
        public MasterNetAdapter EnsureHasCorrectAdapter()
        {
            NSTSettings nstSettings = NSTSettings.EnsureExistsInScene(NSTSettings.DEFAULT_GO_NAME);

            mna = GetComponent <MasterNetAdapter>();
            if (!mna)
            {
                mna = gameObject.AddComponent <MasterNetAdapter>();
            }

            if (mna && mna.NetLibrary != nstSettings.networkingLibrary)
            {
                Debug.LogWarning("Photon PUN not yet supported");
                nstSettings.networkingLibrary = NetworkLibrary.UNET;
            }



            ////if (Event.current.type == EventType.Repaint)
            //if (mna != null && mna.NetLibrary != networkingLibrary)
            //	mna.KillMe = true;


            //if (mna == null)
            //{
            //	// Hacky way to try and apply classes that may or may not exist.
            //	Type type = (networkingLibrary == NetworkLibrary.Photon) ?
            //		Type.GetType("emotitron.Network.NST.NSTMasterPhotonAdapter") :
            //		Type.GetType("emotitron.Network.NST.NSTMasterUnetAdapter");

            //	if (type != null)
            //		gameObject.AddComponent(type);

            //	mna = GetComponent<INSTMasterAdapter>();
            //}


            // Should exist now... try again.
            return(mna);
        }
        private void AddAllDependencies(bool silence = false)
        {
            headerName  = HeaderNSTName;
            headerColor = HeaderNSTColor;
            base.OnEnable();

            nst = (NetworkSyncTransform)target;

            // Add this NST to the prefab spawn list (and as player prefab if none exists yet) as an idiot prevention
            if (!Application.isPlaying)
            {
                MasterNetAdapter.AddAsRegisteredPrefab(nst.gameObject, silence);
            }


            // If user tried to put NST where it shouldn't be... remove it and all of the required components it added.
            if (nst.transform.parent != null)
            {
                Debug.LogError("NetworkSyncTransform must be on the root of an prefab object.");
                nst.nstElementsEngine = nst.transform.GetComponent <NSTElementsEngine>();

                NSTNetAdapter.RemoveAdapter(nst);

                DestroyImmediate(nst);

                if (nst.nstElementsEngine != null)
                {
                    DestroyImmediate(nst.nstElementsEngine);
                }

                return;
            }

            nst.na = NSTNetAdapter.EnsureNstAdapterExists(nst.gameObject);

            nst.nstSettings       = NSTSettings.EnsureExistsInScene(NSTSettings.DEFAULT_GO_NAME);
            nst.nstElementsEngine = NSTElementsEngine.EnsureExistsOnRoot(nst.transform, false);
            NSTMaster.EnsureExistsInScene("NST Master");
        }
Beispiel #11
0
        // Create the master bitstream and poll for updates
        private static void PollForUpdates(int updateCounter, bool isOfftick)
        {
            UdpBitStream bitstream = new UdpBitStream(NSTMaster.bitstreamByteArray);
            UdpBitStream outstream = new UdpBitStream();

            bitstream.WriteInt(updateCounter, 6);

            bool updatesFound = PollAllForNSTUpdates(ref bitstream, isOfftick ? NSTTools.allNstsWithOfftick : NSTTools.allNsts, updateCounter, isOfftick);

            if (!isOfftick)
            {
                MasterRTT.Send(ref bitstream, updateCounter);
            }

            /// Additional Data after NST Updates added to stream here

            // Send every tick, or if anything offtick was found
            if (updatesFound || !isOfftick)
            {
                MasterNetAdapter.SendUpdate(ref bitstream, ref outstream);
            }
        }
Beispiel #12
0
 public void OnConnect(ServerClient svrclnt)
 {
     MasterNetAdapter.PUN_JoinRandomRoom();
 }
Beispiel #13
0
 /// <summary>
 /// We use interfaces to get messages from the network adapters, so we need to register this MB to make its interfaces
 /// known to the MasterNetAdapter.
 /// </summary>
 protected void OnEnable()
 {
     MasterNetAdapter.RegisterCallbackInterfaces(this);
 }
Beispiel #14
0
 void OnEnable()
 {
     spawns.Add(this);
     MasterNetAdapter.UNET_RegisterStartPosition(transform);
 }
Beispiel #15
0
 void OnDisable()
 {
     spawns.Remove(this);
     MasterNetAdapter.UNET_UnRegisterStartPosition(transform);
 }
Beispiel #16
0
 /// <summary>
 /// Finds all instances of the network adapters in loaded scenes and the assetdatabse. Used prior to a network library change in order to not
 /// create broken scripts where the old adapters were.
 /// </summary>
 public static void PurgeLibraryReferences()
 {
     PurgeTypeFromEverywhere <NSTNetAdapter>();
     PurgeTypeFromEverywhere <MasterNetAdapter>();
     MasterNetAdapter.PurgeLibSpecificComponents();
 }
Beispiel #17
0
 protected override void Awake()
 {
     base.Awake();
     mna = EnsureHasCorrectAdapter();
     //EnforceSingleton();
 }
Beispiel #18
0
 public void Reset()
 {
     //EnforceSingleton();
     mna = EnsureHasCorrectAdapter();
 }
Beispiel #19
0
 protected virtual void OnDisable()
 {
     MasterNetAdapter.UnregisterCallbackInterfaces(this);
 }
Beispiel #20
0
 public void OnJoinRoomFailed()
 {
     DebugX.Log("Launcher:OnPhotonRandomJoinFailed() was called by PUN. No random room available, so we create one.\nCalling: PhotonNetwork.CreateRoom(null, new RoomOptions() {maxPlayers = 4}, null);");
     MasterNetAdapter.PUN_CreateRoom(null, 8);
 }