コード例 #1
0
ファイル: NSTMaster.cs プロジェクト: vert0r/NetDemo2
        public override void OnEnable()
        {
            nstMaster = (NSTMaster)target;
            mna       = nstMaster.EnsureHasCorrectAdapter();

            headerName  = HeaderMasterName;
            headerColor = HeaderSettingsColor;
            base.OnEnable();
        }
コード例 #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);
        }
コード例 #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);
        }
コード例 #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);
     }
 }
コード例 #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);
            }
        }
コード例 #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;
        }
コード例 #7
0
ファイル: NSTMaster.cs プロジェクト: vert0r/NetDemo2
        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);
        }
コード例 #8
0
ファイル: MasterNetAdapter.cs プロジェクト: vert0r/NetDemo2
        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);
        }
コード例 #9
0
ファイル: NSTMaster.cs プロジェクト: vert0r/NetDemo2
        //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);
        }
コード例 #10
0
        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");
        }
コード例 #11
0
ファイル: NSTMaster.cs プロジェクト: lenix2/VRProject
        // 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);
            }
        }
コード例 #12
0
 public void OnConnect(ServerClient svrclnt)
 {
     MasterNetAdapter.PUN_JoinRandomRoom();
 }
コード例 #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);
 }
コード例 #14
0
 void OnEnable()
 {
     spawns.Add(this);
     MasterNetAdapter.UNET_RegisterStartPosition(transform);
 }
コード例 #15
0
 void OnDisable()
 {
     spawns.Remove(this);
     MasterNetAdapter.UNET_UnRegisterStartPosition(transform);
 }
コード例 #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();
 }
コード例 #17
0
ファイル: NSTMaster.cs プロジェクト: vert0r/NetDemo2
 protected override void Awake()
 {
     base.Awake();
     mna = EnsureHasCorrectAdapter();
     //EnforceSingleton();
 }
コード例 #18
0
ファイル: NSTMaster.cs プロジェクト: vert0r/NetDemo2
 public void Reset()
 {
     //EnforceSingleton();
     mna = EnsureHasCorrectAdapter();
 }
コード例 #19
0
 protected virtual void OnDisable()
 {
     MasterNetAdapter.UnregisterCallbackInterfaces(this);
 }
コード例 #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);
 }