示例#1
0
    // OnEnable
    void OnEnable()
    {
        currentState = InGameMenuState.None;
        nextState    = InGameMenuState.None;

        Screen.showCursor = true;

        if (Player.main != null)
        {
            Player.main.crossHair.enabled = false;
        }

        // Try to free up some RAM
        PerformanceMonitor.FreeRAM();
    }
示例#2
0
    // DO NOT CALL THIS IN THE EDITOR
    public void DestroyServerAssets()
    {
        LogManager.General.Log("Going to destroy unneeded server assets");

        /*// Remove all textures
         * var allTextures = Resources.FindObjectsOfTypeAll(typeof(Texture));
         * LogManager.General.Log(allTextures.Length.ToString() + " textures loaded, going to destroy.");
         * foreach(var obj in allTextures) {
         *      Destroy(obj);
         * }
         * LogManager.General.Log("Textures destroyed.");
         *
         * // Remove all audio clips
         * var allAudioClips = Resources.FindObjectsOfTypeAll(typeof(AudioClip));
         * LogManager.General.Log(allAudioClips.Length.ToString() + " audio clips loaded, going to destroy.");
         * foreach(var obj in allAudioClips) {
         *      Destroy(obj);
         * }
         * LogManager.General.Log("Audio clips destroyed.");
         *
         * // Remove all materials
         * var allMaterials = Resources.FindObjectsOfTypeAll(typeof(Material));
         * LogManager.General.Log(allMaterials.Length.ToString() + " materials loaded, going to destroy.");
         * foreach(var obj in allMaterials) {
         *      Destroy(obj);
         * }
         * LogManager.General.Log("Materials destroyed.");*/

        // Remove occlusion area data
        if (MapManager.occlusionArea)
        {
            Destroy(MapManager.occlusionArea);
            MapManager.occlusionArea = null;
        }

        // Try to free up some RAM
        PerformanceMonitor.FreeRAM();

        // DO NOT DELETE THE MESHES, YOU WILL GET PROBLEMS
    }
示例#3
0
    // Loads a new map
    public static IEnumerator LoadMapAsync(string mapName, CallBack func = null)
    {
        DeleteOldMap();

        LogManager.General.Log("[" + mapName + "] Checking scene");

        if (Application.CanStreamedLevelBeLoaded(mapName))
        {
            LogManager.General.Log("[" + mapName + "] Map can be loaded");
        }
        else
        {
            // Wait for version info download to finish
            while (!AssetBundlesManager.instance.isReady)
            {
                yield return(new WaitForSeconds(0.02f));
            }

            // Download level
            var mapURL     = AssetBundlesManager.instance.GetMapURL(mapName);
            var mapVersion = AssetBundlesManager.instance.GetMapVersion(mapName);
            LogManager.General.Log("Downloading map '" + mapName + "' version " + mapVersion + " from " + mapURL);
            var download = WWW.LoadFromCacheOrDownload(mapURL, mapVersion);

            if (LoadingScreen.instance != null)
            {
                LoadingScreen.instance.downloadingText = "Downloading map: <color=yellow>" + mapName + "</color>...";
                LoadingScreen.instance.asyncDownload   = download;
            }

            yield return(download);

            if (download.error == null)
            {
                var bundle = download.assetBundle;
                LogManager.General.Log("Successfully downloaded " + mapName + bundle);
            }
            else
            {
                LogManager.General.LogError("Failed downloading map: " + mapName + " (" + download.error + ")");
            }

            if (!Application.CanStreamedLevelBeLoaded(mapName))
            {
                LogManager.General.LogError("Map can not be loaded: " + mapName);
            }
        }

        // Load map
        LogManager.General.Log("Loading map '" + mapName + "'...");
        currentMapName = mapName;

        var asyncLoadLevel = Application.LoadLevelAdditiveAsync(mapName);

        if (LoadingScreen.instance != null)
        {
            LoadingScreen.instance.loadingText    = "Loading map: <color=yellow>" + mapName + "</color>...";
            LoadingScreen.instance.asyncLoadLevel = asyncLoadLevel;
        }

        yield return(asyncLoadLevel);

        LogManager.General.Log("Finished loading map: " + mapName);

        // Try getting mapInstance 5 times (maximum)
        for (int i = 1; i <= 5; i++)
        {
            mapInstance = GameObject.FindGameObjectWithTag("Map");

            if (mapInstance == null)
            {
                LogManager.General.LogWarning("Couldn't find the map, mapInstance is null: Retrying.");
                yield return(new WaitForSeconds(0.01f));
            }
            else
            {
                break;
            }
        }

        if (mapInstance == null)
        {
            LogManager.General.LogError("Couldn't find the map, mapInstance is null");
        }

        mapIntro = mapInstance.GetComponent <Intro>();
        LogManager.General.Log("Map intro: " + mapIntro);

        mapBounds = mapInstance.GetComponent <MapBoundary>().bounds;
        LogManager.General.Log("Map bounds: " + mapBounds);

        // Occlusion area
        occlusionArea = mapInstance.transform.FindChild("Occlusion Area");
        if (occlusionArea != null)
        {
            LogManager.General.Log("Occlusion culling information available");
            occlusionCullingActive = true;
        }
        else
        {
            LogManager.General.Log("Occlusion culling information not available");
            occlusionCullingActive = false;
        }

        // Play music
        if (MusicManager.instance != null)
        {
            MusicManager.instance.PlayCategory(mapInstance.GetComponent <MusicCategory>());
        }

        // Update spawn locations
        GameServerParty.UpdateSpawns();

        // Delete NPCs on PvP areas
        if (GameManager.isPvP)
        {
            DeleteNPCs();
        }

        // Update sun shafts caster

        /*if(isServer) {
         *      var sun = GameObject.FindGameObjectWithTag("Sun");
         *      var sunShafts = Camera.main.GetComponent<SunShafts>();
         *      if(sun != null && sunShafts != null) {
         *              // TODO: Why doesn't this work?
         *              sunShafts.sunTransform = sun.transform;
         *              LogManager.General.Log("Updated sun shafts caster to " + sun.ToString() + ", " + sun.transform.ToString());
         *      } else {
         *              LogManager.General.LogWarning("Couldn't find sun (did you use the 'Sun' tag?)");
         *      }
         * }*/

        // Try to free up some RAM
        PerformanceMonitor.FreeRAM();

        // Custom callback function
        if (func != null)
        {
            func();
        }
    }