private void Update()
        {
            if (Application.isPlaying)
            {
                return;
            }

            if (EditorApplication.isCompiling)
            {
                return;
            }

            if (!needsEditorModePostAwakeCheck)
            {
                return;
            }

            //Destroy the existing Master so it can be readded, to ensure it hasn't been messed up by a library change.
            //NetAdapterTools.RemoveComponentTypeFromScene<NSTMaster>(true);

            //FindMissingScripts.DestroyMissingComponentOnRoot(FindObjectOfType<MasterNetAdapter>().gameObject);
            NetAdapterTools.RemoveUnusedNetworkManager();
            NetAdapterTools.TryToAddDependenciesEverywhere();
#if MIRROR || !UNITY_2019_1_OR_NEWER
            NetAdapterTools.GetNetworkManager(true);
#endif
            NetAdapterTools.CopyPlayerPrefabFromPUNtoOthers();
            NetAdapterTools.EnsureNMPlayerPrefabIsLocalAuthority();
            NetAdapterTools.EnsureSceneNetLibDependencies(false);

            needsEditorModePostAwakeCheck = false;
        }
Exemple #2
0
        ///// <summary>
        ///// Add the NetworkIdenity/PhotonView to an NST gameobject. Must be added before runtime (thus this is editor only script).
        ///// If added at runtime, it may get added AFTER network events fire. Also will attempt to add this NST as a registered prefab
        ///// and player prefab. Will also attempt to register the supplied go with the NetworkManager and as the PlayerPrefab if there is none
        ///// but one is expected.
        ///// </summary>
        //public static void EnsureHasEntityComponentForNetLib(GameObject go, bool playerPrefabCandidate = true)
        //{
        //	if (!Application.isPlaying)
        //		AddAsRegisteredPrefab(go, true, !playerPrefabCandidate, true);
        //}
        /// <summary>
        /// Attempts to add a prefab with NST on it to the NetworkManager spawnable prefabs list, after doing some checks to make
        /// sure it makes sense to. Will then add as the network manager player prefab if it is set to auto spawwn and is still null.
        /// </summary>
        public static bool AddAsRegisteredPrefab(GameObject go, bool playerPrefabCandidate, bool silence = false)
        {
            if (Application.isPlaying)
            {
                return(false);
            }

            // Don't replace an existing playerPrefab
            NetworkManager nm = NetAdapterTools.GetNetworkManager();

            if (!nm)
            {
                return(false);
            }

            PrefabType type     = PrefabUtility.GetPrefabType(go);
            GameObject prefabGO = (type == PrefabType.Prefab) ? go : PrefabUtility.GetPrefabParent(go) as GameObject;

            if (!prefabGO)
            {
                if (!silence)
                {
                    Debug.Log("You have a NST component on a gameobject '" + go.name + "', which is not a prefab. Be sure to make '" + go.name + "' a prefab, otherwise it cannot be registered with the NetworkManager for network spawning.");
                }
                return(false);
            }

            NetworkIdentity ni = prefabGO.GetComponent <NetworkIdentity>();

            if (!ni)
            {
                if (!silence)
                {
                    Debug.Log("There is no NetworkIdentity on '" + go.name + "', so it cannot be registered with the NetworkManager for network spawning.");
                }
                return(false);
            }

            // Force the NetworkIdentity to be valid. Bad things happen if we don't do this. UNET suck.
            ni.assetId.IsValid();

            if (!nm.spawnPrefabs.Contains(prefabGO))
            {
                Debug.Log("Automatically adding '<b>" + prefabGO.name + "</b>' to the NetworkManager spawn list for you.");

                nm.spawnPrefabs.Add(prefabGO);
                EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene());
            }

            // Set this as the player prefab if there is none yet
            if (nm.playerPrefab == null && nm.autoCreatePlayer && playerPrefabCandidate)
            {
                Debug.Log("Automatically adding '<b>" + prefabGO.name + "</b>' to the NetworkManager as the <b>playerPrefab</b>. If this isn't desired, assign your the correct prefab to the Network Manager, or turn off Auto Create Player in the NetworkManager.");
                nm.playerPrefab = prefabGO;
                EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene());
            }

            NetAdapterTools.EnsureNMPlayerPrefabIsLocalAuthority(nm);
            return(true);
        }
		public virtual void OnEnable()
		{
			//if (lTexture == null)
			//	lTexture = (Texture2D)AssetDatabase.LoadAssetAtPath("Assets/emotitron/_Graphics/HeaderName/NST " + headerName + ".png", typeof(Texture2D));

			
			//if (rTexture == null)
			//	rTexture = (Texture2D)AssetDatabase.LoadAssetAtPath("Assets/emotitron/_Graphics/NST Teapot.png", typeof(Texture2D));

			//if (bTexture == null)
			//	bTexture = (Texture2D)AssetDatabase.LoadAssetAtPath("Assets/emotitron/_Graphics/Background/NST " + headerColor + ".png", typeof(Texture2D));

			if (lTexture == null)
				lTexture = (Texture2D)Resources.Load<Texture2D>("_Graphics/HeaderName/NST " + headerName);


			if (rTexture == null)
				rTexture = (Texture2D)Resources.Load<Texture2D>("_Graphics/NST Teapot");

			if (bTexture == null)
				bTexture = (Texture2D)Resources.Load<Texture2D>("_Graphics/Background/NST " + headerColor);


			// Touching or adding any Component that is part of the NST Library will fire this.
			NetAdapterTools.EnsureSceneNetLibDependencies(false);

			Undo.undoRedoPerformed -= OnUndoRedo;
			Undo.undoRedoPerformed += OnUndoRedo;
		}
Exemple #4
0
        public virtual void OnEnable()
        {
            if (lTexture == null)
            {
                lTexture = (Texture2D)AssetDatabase.LoadAssetAtPath("Assets/emotitron/_Graphics/HeaderName/NST " + headerName + ".png", typeof(Texture2D));
            }

            if (rTexture == null)
            {
                rTexture = (Texture2D)AssetDatabase.LoadAssetAtPath("Assets/emotitron/_Graphics/NST Teapot.png", typeof(Texture2D));
            }

            if (bTexture == null)
            {
                bTexture = (Texture2D)AssetDatabase.LoadAssetAtPath("Assets/emotitron/_Graphics/Background/NST " + headerColor + ".png", typeof(Texture2D));
            }

#if UNITY_EDITOR
            // Touching or adding any Component that is part of the NST Library will fire this.
            NetAdapterTools.EnsureSceneNetLibDependencies(false);
#endif

            Undo.undoRedoPerformed -= OnUndoRedo;
            Undo.undoRedoPerformed += OnUndoRedo;
        }
        public override void OnEnable()
        {
            headerName  = HeaderSettingsName;
            headerColor = HeaderSettingsColor;
            base.OnEnable();

            NetAdapterTools.TryToAddDependenciesEverywhere();
            NetAdapterTools.EnsureSceneNetLibDependencies(true);
        }
Exemple #6
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);
        }
Exemple #7
0
        private void Update()
        {
            // Don't actually try to execute in editmode. We only want the Awake() to fire in edit, not the rest.
#if UNITY_EDITOR
            if (!Application.isPlaying)
            {
                if (needsEditorModePostAwakeCheck)
                {
                    NetAdapterTools.RemovedUnusedNetworkIdentity(gameObject);
                    needsEditorModePostAwakeCheck = false;
                }
                return;
            }
#endif

            /// Send in Update version
            //// Test for Network Tick being due
            //// TODO: send multiple if more than one is due?
            //if (MasterNetAdapter.ClientIsActive || MasterNetAdapter.ServerIsActive)
            //{

            //	if (ontickSendsDue > 0)
            //	{
            //		PollForUpdates(_updateCounter, false);
            //		FixedUpdateCounter++;
            //		ontickSendsDue--;

            //		////TEST
            //		//ontickSendsDue = 0;
            //		offtickSendDue = false;
            //	}
            //	else if (offtickSendDue)
            //	{
            //		// Check for Offticks on nsts marked as allowing offtick
            //		PollForUpdates(60, true);
            //		offtickSendDue = false;
            //	}
            //}



            if (!MasterNetAdapter.NetworkIsActive)
            {
                return;
            }

            for (int i = 0; i < NSTTools.allNsts.Count; i++)
            {
                NSTTools.allNsts[i].MasterUpdate();
            }
        }
Exemple #8
0
        public override bool DrawGui(object target, bool isAsset, bool includeScriptField = true)
        {
            expandeds[target] = base.DrawGui(target, isAsset, includeScriptField);

            bool success = NetAdapterTools.ChangeLibraries();

            // if the change failed, set the enum back to the current lib
            if (!success)
            {
                Single.networkLibrary = MasterNetAdapter.NetworkLibrary;
            }

            return(expandeds[target]);
        }
Exemple #9
0
 private void Reset()
 {
     // On creation, see if there is a UNET network manager and copy the playerprefab from that.
     playerPrefab = null;
     NetAdapterTools.CopyPlayerPrefab();
 }
Exemple #10
0
 public static void AddNstEntityComponentsEverywhere()
 {
     NetAdapterTools.AddComponentsWhereverOtherComponentIsFound <NetworkSyncTransform, NSTNetAdapter, NetworkIdentity>();
 }
Exemple #11
0
 public static void PurgeLibSpecificComponents()
 {
     NetAdapterTools.PurgeTypeFromEverywhere <NetworkIdentity>();
     NetAdapterTools.PurgeTypeFromEverywhere <NetworkManager>(true);
 }