예제 #1
0
        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();
            NetAdapterTools.GetNetworkManager(true);
            NetAdapterTools.CopyPlayerPrefabFromPUNtoOthers();
            NetAdapterTools.EnsureNMPlayerPrefabIsLocalAuthority();
            NetAdapterTools.EnsureSceneNetLibDependencies(false);

            needsEditorModePostAwakeCheck = false;
        }
예제 #2
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

            if (!MasterNetAdapter.NetworkIsActive)
            {
                return;
            }

            for (int i = 0; i < NSTTools.allNsts.Count; i++)
            {
                NSTTools.allNsts[i].MasterUpdate();
            }
        }
예제 #3
0
        public override void OnEnable()
        {
            headerName  = HeaderSettingsName;
            headerColor = HeaderSettingsColor;
            base.OnEnable();


            NetAdapterTools.TryToAddDependenciesEverywhere();
            NetAdapterTools.EnsureSceneNetLibDependencies(true);
        }
예제 #4
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);
        }
예제 #5
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]);
        }
예제 #6
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
        }
예제 #7
0
 public static void AddNstEntityComponentsEverywhere()
 {
     NetAdapterTools.AddComponentsWhereverOtherComponentIsFound <NetworkSyncTransform, NSTNetAdapter, NetworkIdentity>();
 }
예제 #8
0
 public static void PurgeLibSpecificComponents()
 {
     NetAdapterTools.PurgeTypeFromEverywhere <NetworkIdentity>();
     NetAdapterTools.PurgeTypeFromEverywhere <NetworkManager>(true);
 }
예제 #9
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 || nm.playerPrefab)
            {
                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>();

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

            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);
            }

            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);
        }
예제 #10
0
 private void Reset()
 {
     // On creation, see if there is a UNET network manager and copy the playerprefab from that.
     playerPrefab = null;
     NetAdapterTools.CopyPlayerPrefab();
 }