// TODO this is redudant with NSTNetAdapter code for UNET
        public static void CopyPlayerPrefabFromPUNtoOthers()
        {
            PUNSampleLauncher punl = PUNSampleLauncher.Single;

            if (!punl || punl.playerPrefab == null)
            {
                return;
            }

            NSTNetAdapter.AddAsRegisteredPrefab(punl.playerPrefab, true);

            //// Copy player prefab from PUN launcher to NM
            //if (MasterNetAdapter.NetLib == NetworkLibrary.UNET)
            //	NSTNetAdapter.AddAsRegisteredPrefab(punl.playerPrefab, true);

            //// Copy PUN playerPrefab to UNET
            //NetworkManager nm = GetNetworkManager(MasterNetAdapter.NetLib == NetworkLibrary.UNET);
            //if (nm && !nm.playerPrefab)
            //{
            //	Debug.Log("Copying Player Prefab : <b>'" + punl.playerPrefab.name + "'</b> from " + punl.GetType().Name + " to NetworkManager for you.");

            //	NetworkIdentity ni = punl.playerPrefab.GetComponent<NetworkIdentity>();
            //	if (!ni)
            //		ni = punl.playerPrefab.AddComponent<NetworkIdentity>();

            //	// This seemingly pointless code forces the NI to initialize the assetid. For some dumb reason UNET.
            //	ni.assetId.IsValid();

            //	if (nm.playerPrefab != punl.playerPrefab)
            //	{
            //		nm.playerPrefab = punl.playerPrefab;
            //		EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene());
            //	}
            //}
        }
Example #2
0
        // TODO this is redudant with NSTNetAdapter code for UNET
        public static void CopyPlayerPrefabFromPUNtoOthers()
        {
            PUNSampleLauncher punl = PUNSampleLauncher.Single;

            if (!punl || punl.playerPrefab == null)
            {
                return;
            }

            NSTNetAdapter.AddAsRegisteredPrefab(punl.playerPrefab, true);
        }
        public static void CopyPlayerPrefabFromUNETtoOthers()
        {
            NetworkManager nm = GetNetworkManager();

            if (!nm || nm.playerPrefab == null)
            {
                return;
            }

            PUNSampleLauncher punl = PUNSampleLauncher.Single;

            if (punl && !punl.playerPrefab)
            {
                Debug.Log("Copying Player Prefab : <b>'" + nm.playerPrefab.name + "'</b> from NetworkManager to " + punl.GetType().Name + " for you.");
                punl.playerPrefab = nm.playerPrefab;
            }
        }
        /// <summary>
        /// Tries to register this NST as the player prefab (if there is none currently set), after doing some checks to make sure it makes sense to.
        /// </summary>
        public static void AddAsRegisteredPrefab(GameObject go, bool playerPrefabCandidate, bool silence = false)
        {
            // Doesn't apply to PUN
            PUNSampleLauncher punl = UnityEngine.Object.FindObjectOfType <PUNSampleLauncher>();

            if (punl && !punl.playerPrefab && playerPrefabCandidate)
            {
                XDebug.LogWarning("Adding " + go.name + " as the player prefab to " + typeof(PUNSampleLauncher).Name);
#if UNITY_2018_3_OR_NEWER
                GameObject parprefab = PrefabUtility.GetCorrespondingObjectFromSource(go);
#else
#pragma warning disable CS0618 // Type or member is obsolete
                GameObject parprefab = (GameObject)PrefabUtility.GetPrefabParent(go);
#pragma warning restore CS0618 // Type or member is obsolete
#endif
                punl.playerPrefab = parprefab ? parprefab : go;
            }
        }