コード例 #1
0
    private void Start()
    {
        LoadingProgress.ResetVisuals();
        PerfTimerLogger perfTimerLogger = new PerfTimerLogger("[<color=#FFF>TIMER</color>] LoadAsync Start", PerfTimerLogger.LogResultType.Milliseconds, null);

        TheForest.Utils.Input.LockMouse();
        base.transform.parent = null;
        if (this.Menu)
        {
            UnityEngine.Object.Destroy(this.Menu);
        }
        if (LoadAsync.Scenery)
        {
            UnityEngine.Object.Destroy(LoadAsync.Scenery);
            LoadAsync.Scenery = null;
        }
        if (!Application.CanStreamedLevelBeLoaded(this._levelName))
        {
            Debug.LogError("Scene invalid \"" + this._levelName + "\"");
            perfTimerLogger.Stop();
            this.AttemptLoadRecovery();
            return;
        }
        base.StartCoroutine(this.LoadLevelWithProgress(this._levelName));
        perfTimerLogger.Stop();
    }
コード例 #2
0
    private void Awake()
    {
        PerfTimerLogger perfTimerLogger = new PerfTimerLogger("[<color=#FFF>TIMER</color>] LoadSave Awake", PerfTimerLogger.LogResultType.Milliseconds, null);

        GeoHash.ClearAll();
        Scene.FinishGameLoad      = false;
        UnityEngine.Random.seed   = Convert.ToInt32(DateTime.UtcNow.ToUnixTimestamp());
        LevelSerializer.Progress += this.LevelSerializer_Progress;
        if (Scene.PlaneCrash && Scene.PlaneCrash.gameObject && Scene.PlaneCrash.gameObject.activeSelf && Scene.PlaneCrash.ShowCrash)
        {
            Scene.HudGui.Loading._cam.SetActive(!CoopPeerStarter.DedicatedHost);
        }
        if (LevelLoader.Current)
        {
            Scene.HudGui.Loading._cam.SetActive(!CoopPeerStarter.DedicatedHost);
            Scene.HudGui.Loading._message.SetActive(!CoopPeerStarter.DedicatedHost);
            perfTimerLogger.Stop();
            return;
        }
        if (LoadSave.ShouldLoad)
        {
            LoadSave.ShouldLoad = false;
            if (LevelSerializer.CanResume)
            {
                Scene.HudGui.Loading._cam.SetActive(!CoopPeerStarter.DedicatedHost);
                LevelSerializer.Collect();
                LevelSerializer.Resume();
                perfTimerLogger.Stop();
                return;
            }
        }
        if (Scene.HudGui.Loading._message)
        {
            Scene.HudGui.Loading._message.SetActive(false);
        }
        Time.timeScale = 1f;
        MainMenuAudio.FadeOut();
        Debug.Log("****** Game Activation Sequence ******");
        base.StartCoroutine(this.Activation(true));
        perfTimerLogger.Stop();
    }
コード例 #3
0
    private void Start()
    {
        PerfTimerLogger perfTimerLogger = new PerfTimerLogger("[<color=#FFF>TIMER</color>] LoadAsync Start", PerfTimerLogger.LogResultType.Milliseconds, null);

        TheForest.Utils.Input.LockMouse();
        base.transform.parent = null;
        if (this.Menu)
        {
            UnityEngine.Object.Destroy(this.Menu);
        }
        if (LoadAsync.Scenery)
        {
            UnityEngine.Object.Destroy(LoadAsync.Scenery);
            LoadAsync.Scenery = null;
        }
        base.StartCoroutine(this.LoadLevelWithProgress(this._levelName));
        perfTimerLogger.Stop();
    }
コード例 #4
0
    private IEnumerator LoadLevelWithProgress(string levelToLoad)
    {
        using (new PerfTimerLogger("[<color=#FFF>TIMER</color>] Cleanup", PerfTimerLogger.LogResultType.Milliseconds, null))
        {
            if (this.delayForCleanup)
            {
                Resources.UnloadUnusedAssets();
                GC.Collect();
                yield return(null);
            }
        }
        using (new PerfTimerLogger("[<color=#FFF>TIMER</color>] failsafe", PerfTimerLogger.LogResultType.Milliseconds, null))
        {
            float failsafe = 5f;
            while (BoltNetwork.isRunning && failsafe > 0f)
            {
                failsafe -= Time.deltaTime;
                yield return(null);
            }
        }
        yield return(null);

        PerfTimerLogger queryStateTimer = new PerfTimerLogger("[<color=#FFF>TIMER</color>] Query state", PerfTimerLogger.LogResultType.Milliseconds, null);
        bool            canResume       = LevelSerializer.CanResume;
        bool            boltIsRunning   = BoltNetwork.isRunning;
        bool            boltIsServer    = BoltNetwork.isServer;
        bool            boltIsClient    = BoltNetwork.isClient;
        bool            isSavedGame     = GameSetup.IsSavedGame;

        queryStateTimer.Stop();
        if (canResume && (!boltIsRunning || boltIsServer) && isSavedGame)
        {
            PerfTimerLogger resumeTimer = new PerfTimerLogger("[<color=#FFF>TIMER</color>] Resume", PerfTimerLogger.LogResultType.Milliseconds, null);
            ResourceRequest req         = Resources.LoadAsync("PreloadingPrefabs");
            while (!req.isDone)
            {
                yield return(null);
            }
            UnityEngine.Object.Instantiate(req.asset);
            yield return(null);

            LevelSerializer.InitPrefabList();
            yield return(null);

            LevelSerializer.Resume();
            resumeTimer.Stop();
            yield break;
        }
        PerfTimerLogger loadLevelTimer = new PerfTimerLogger(string.Format("[<color=#FFF>TIMER</color>] Load {0}", levelToLoad), PerfTimerLogger.LogResultType.Milliseconds, null);

        UnityEngine.Object.DontDestroyOnLoad(base.gameObject);
        if (!boltIsClient && !canResume)
        {
            GameSetup.SetInitType(InitTypes.New);
        }
        this.async = SceneManager.LoadSceneAsync(levelToLoad);
        while (!this.async.isDone)
        {
            LoadingProgress.Progress = this.async.progress * 0.5f;
            yield return(null);
        }
        LoadingProgress.Progress = 0.5f;
        loadLevelTimer.Stop();
        UnityEngine.Object.Destroy(base.gameObject);
        yield break;
    }
コード例 #5
0
    public IEnumerator Activation(bool activate)
    {
        if (ForestVR.Prototype)
        {
            base.enabled = false;
            yield break;
        }
        if (this.startedSequence)
        {
            yield break;
        }
        PerfTimerLogger timer = new PerfTimerLogger("[<color=#FFF>TIMER</color>] Activation", PerfTimerLogger.LogResultType.Milliseconds, null);

        this.startedSequence = true;
        if (!CoopPeerStarter.DedicatedHost)
        {
            while (!LocalPlayer.Rigidbody)
            {
                yield return(null);
            }
            LocalPlayer.Rigidbody.useGravity  = false;
            LocalPlayer.Rigidbody.isKinematic = true;
        }
        this.SetStartSequenceStep(0, 1f);
        Debug.Log("Game Activation Sequence step 0 (GameStartType=" + GameSetup.Init + ")");
        bool isLoadingSave = GameSetup.IsSavedGame;

        if (isLoadingSave && BoltNetwork.isRunning && BoltNetwork.isServer && Scene.PlaneCrash)
        {
            yield return(null);

            if (Scene.PlaneCrash.savePos)
            {
                CoopServerInfo.Instance.state.PlanePosition = Scene.PlaneCrash.savePos.position;
                CoopServerInfo.Instance.state.PlaneRotation = Scene.PlaneCrash.savePos.rotation;
                foreach (BoltConnection connection in BoltNetwork.clients)
                {
                    SetJoiningTimeOfDay setJoiningTimeOfDay = SetJoiningTimeOfDay.Create(connection);
                    setJoiningTimeOfDay.TimeOfDay = ((!Scene.Atmosphere) ? 302f : Scene.Atmosphere.TimeOfDay);
                    setJoiningTimeOfDay.Send();
                }
            }
            else
            {
                Debug.LogError("No plane crash position");
            }
        }
        else if (BoltNetwork.isServer && ((!isLoadingSave && !Scene.PlaneCrash.gameObject.activeSelf) || (isLoadingSave && !Scene.PlaneCrash.savePos)))
        {
            Debug.LogError("Setting fake plane coordinates for testing purposes. Please turn on plane crash when testing MP.");
            CoopServerInfo.Instance.state.PlanePosition = ((!LocalPlayer.Transform) ? new Vector3(400f, 50f, 300f) : LocalPlayer.Transform.position) + new Vector3(0f, 4f, 0f);
            CoopServerInfo.Instance.state.PlaneRotation = Quaternion.Euler(0f, 20f, 0f);
        }
        yield return(null);

        if (TheForest.Utils.Input.player != null)
        {
            TheForest.Utils.Input.SetMenuMapping(false);
        }
        this.SetStartSequenceStep(1, 1f);
        if (AstarPath.active)
        {
            Debug.Log("Game Activation Sequence step 1 : enable Astar");
            if (BoltNetwork.isClient)
            {
                GameObject gameObject  = GameObject.Find("Astar");
                GameObject gameObject2 = GameObject.Find("AstarGUOGo");
                if (gameObject2)
                {
                    UnityEngine.Object.Destroy(gameObject2);
                }
                if (gameObject)
                {
                    UnityEngine.Object.Destroy(gameObject);
                }
            }
            else
            {
                AstarPath.active.enabled = true;
            }
        }
        else
        {
            Debug.Log("Game Activation Sequence step 1 : AStar is missing, SKIPPING !!!");
        }
        yield return(null);

        int list = 1;

        foreach (LoadSave.GameObjectList frameActivationList in this._activateAfterLoading)
        {
            object arg = "Game Activation Sequence step 2 : Activating GameObject List #";
            int    num;
            list = (num = list) + 1;
            Debug.Log(arg + num);
            this.SetStartSequenceStep(2, (float)list / (float)this._activateAfterLoading.Count);
            foreach (GameObject gameObject3 in frameActivationList._frameJobs)
            {
                if (gameObject3)
                {
                    gameObject3.SetActive(activate);
                }
                else
                {
                    Debug.Log("Null GameObject in LoadSave's lists to activate. Please check something isn't missing or remove the entry.-");
                }
            }
            yield return(null);
        }
        if (!CoopPeerStarter.DedicatedHost)
        {
            while (!LocalPlayer.GameObject)
            {
                yield return(null);
            }
            GameObject endgameLoader = GameObject.FindWithTag("EndgameLoader");
            if (endgameLoader)
            {
                SceneLoadTrigger component = endgameLoader.GetComponent <SceneLoadTrigger>();
                if (LocalPlayer.ActiveAreaInfo.HasActiveEndgameArea)
                {
                    component.SetCanLoad(true);
                    component.ForceLoad();
                }
                else
                {
                    Vector3 rhs = LocalPlayer.Transform.position - component.transform.position;
                    if (Vector3.Dot(component.transform.forward, rhs) > 0f && rhs.magnitude < 150f)
                    {
                        component._onCrossingForwards.Invoke();
                    }
                }
            }
            this.SetStartSequenceStep(3, 1f);
            Debug.Log("Game Activation Sequence step 3 : Enabling GreebleLayers, workscheduler, rainfollow");
            LocalPlayer.GreebleRoot.SetActive(true);
            Scene.RainFollowGO.GetComponent <SmoothTransformConstraint>().target = LocalPlayer.Transform.Find("RainTargetGo");
        }
        else
        {
            this.SetStartSequenceStep(3, 1f);
            Debug.Log("Game Activation Sequence step 3* : Enabling workscheduler");
        }
        WorkScheduler.ShouldDoFullCycle = true;
        if (Scene.PlaneCrash.Crashed || !Scene.PlaneCrash.ShowCrash || !Scene.PlaneCrashAnimGO || !Scene.PlaneCrashAnimGO.activeSelf)
        {
            Scene.WorkScheduler.gameObject.SetActive(true);
        }
        yield return(null);

        yield return(null);

        this.SetStartSequenceStep(4, 1f);
        Debug.Log("Game Activation Sequence step 4 : Initalize Game Mode");
        if (!BoltNetwork.isClient && (Prefabs.Instance.GameModePrefabs[(int)GameSetup.Game] || GameModeStarter.Prefab))
        {
            if (GameModeStarter.Prefab)
            {
                UnityEngine.Object.Instantiate <GameObject>(GameModeStarter.Prefab);
            }
            else
            {
                UnityEngine.Object.Instantiate <GameObject>(Prefabs.Instance.GameModePrefabs[(int)GameSetup.Game]);
            }
        }
        else
        {
            yield return(YieldPresets.WaitPointFiveSeconds);
        }
        this.SetStartSequenceStep(5, 0.5f);
        Debug.Log("Game Activation Sequence step 5 : OnGameStart event");
        Time.timeScale = 1f;
        if (LoadSave.OnGameStart != null)
        {
            LoadSave.OnGameStart();
        }
        LoadSave.OnGameStart = null;
        if (BoltNetwork.isClient && isLoadingSave)
        {
            yield return(YieldPresets.WaitPointFiveSeconds);

            Vector3   playerPos = LocalPlayer.Transform.position;
            LayerMask layers    = LayerMask.GetMask(new string[]
            {
                "ReflectBig",
                "Terrain",
                "Prop",
                "Cave"
            });
            float      mpClientDelayStart = Time.realtimeSinceStartup;
            RaycastHit hit;
            while (Time.realtimeSinceStartup - mpClientDelayStart < 15f && !Physics.Raycast(playerPos, Vector3.down, out hit, 3f, layers))
            {
                this.SetStartSequenceStep(5, 0.5f + (Time.realtimeSinceStartup - mpClientDelayStart) / 15f * 0.5f);
                LocalPlayer.Transform.position = playerPos;
                yield return(null);
            }
        }
        this.SetStartSequenceStep(5, 1f);
        CaveTriggers.CheckPlayersInCave();
        MassDestructionSaveManager md = UnityEngine.Object.FindObjectOfType <MassDestructionSaveManager>();

        if (!md.GetComponent <GlobalDataSaver>())
        {
            md.gameObject.AddComponent <GlobalDataSaver>();
            StoreInformation component2 = md.GetComponent <StoreInformation>();
            if (!component2.Components.Contains("TheForest.Utils.GlobalDataSaver"))
            {
                component2.Components.Add("TheForest.Utils.GlobalDataSaver");
            }
        }
        if (!md.GetComponent <GreebleZonesManager>())
        {
            md.gameObject.AddComponent <GreebleZonesManager>();
            StoreInformation component3 = md.GetComponent <StoreInformation>();
            if (!component3.Components.Contains("GreebleZonesManager"))
            {
                component3.Components.Add("GreebleZonesManager");
            }
            UnityEngine.Object.FindObjectOfType <GreebleZonesManager>().RefreshGreebleZones();
        }
        if (!md.GetComponent <SpawnMutantsSerializerMessageProxy>())
        {
            md.gameObject.AddComponent <SpawnMutantsSerializerMessageProxy>();
        }
        foreach (Camera camera in UnityEngine.Object.FindObjectsOfType <Camera>())
        {
            camera.eventMask = 0;
        }
        Scene.LoadSave = null;
        Scene.Atmosphere.ForceSunRotationUpdate = true;
        Scene.SceneTracker.waitForLoadSequence  = true;
        this.SetStartSequenceStep(6, 0.25f);
        yield return(YieldPresets.WaitPointSixSeconds);

        if (!BoltNetwork.isClient)
        {
            while (Scene.SceneTracker.doingGlobalNavUpdate)
            {
                yield return(null);
            }
        }
        if (!CoopPeerStarter.DedicatedHost)
        {
            VirtualCursor.Instance.SetCursorType(VirtualCursor.CursorTypes.Reset);
            VirtualCursor.Instance.SetCursorType(VirtualCursor.CursorTypes.None);
        }
        this.SetStartSequenceStep(6, 0.5f);
        if (!CoopPeerStarter.DedicatedHost)
        {
            if (LocalPlayer.ActiveAreaInfo.HasActiveEndgameArea)
            {
                while (!LocalPlayer.IsInEndgame)
                {
                    yield return(null);
                }
                yield return(null);
            }
            LocalPlayer.Rigidbody.isKinematic = false;
            LocalPlayer.Rigidbody.useGravity  = true;
            this.SetStartSequenceStep(6, 1f);
            Debug.Log("Game Activation Sequence step 6 : BlackScreen off");
            if (LocalPlayer.Inventory.CurrentView == PlayerInventory.PlayerViews.Loading)
            {
                LocalPlayer.Inventory.CurrentView = PlayerInventory.PlayerViews.World;
            }
            Scene.HudGui.CheckHudState();
        }
        else
        {
            Scene.HudGui.gameObject.SetActive(false);
            this.SetStartSequenceStep(6, 1f);
            Debug.Log("Game Activation Sequence step 6* : BlackScreen off");
        }
        Scene.HudGui.Loading._cam.SetActive(false);
        Debug.Log("Game Activation Sequence step 7 : End of Sequence");
        if (LocalPlayer.Inventory)
        {
            if (LocalPlayer.Inventory.CurrentView != PlayerInventory.PlayerViews.PlaneCrash)
            {
                LocalPlayer.Inventory.enabled = true;
            }
            LocalPlayer.Transform.SendMessage("enableMpRenderers", SendMessageOptions.DontRequireReceiver);
            LocalPlayer.Transform.SendMessage("forceMecanimSync", SendMessageOptions.DontRequireReceiver);
        }
        if (BoltNetwork.isClient)
        {
            foreach (GameObject gameObject4 in Scene.MutantControler.activeNetCannibals)
            {
                if (gameObject4.activeSelf)
                {
                    gameObject4.SendMessage("forceSkinColor", SendMessageOptions.DontRequireReceiver);
                }
            }
        }
        if (LocalPlayer.MainRotator)
        {
            LocalPlayer.Transform.localEulerAngles        = new Vector3(0f, LocalPlayer.Transform.localEulerAngles.y, 0f);
            LocalPlayer.MainRotator.resetOriginalRotation = true;
        }
        if (LocalPlayer.IsInCaves && BoltNetwork.isClient)
        {
            playerInCave playerInCave = playerInCave.Create(GlobalTargets.OnlyServer);
            playerInCave.target = LocalPlayer.Transform.GetComponent <BoltEntity>();
            playerInCave.inCave = true;
            playerInCave.Send();
        }
        if (LocalPlayer.IsInCaves || LocalPlayer.IsInEndgame)
        {
            for (int j = 0; j < Scene.SceneTracker.caveEntrances.Count; j++)
            {
                Scene.SceneTracker.caveEntrances[j].disableCaveBlack();
            }
        }
        UnityEngine.Object.Destroy(this);
        BridgeAnchorHelper.Clear();
        if (BoltNetwork.isRunning && CoopHellDoors.Instance && CoopHellDoors.Instance.entity.isAttached)
        {
            CoopHellDoors.Instance.entity.Freeze(false);
        }
        if (SteamClientDSConfig.isDedicatedClient && LocalPlayer.Inventory.CurrentView == PlayerInventory.PlayerViews.World)
        {
            SteamClientDSConfig.IsClientAtWorld = true;
        }
        Scene.FinishGameLoad     = true;
        LoadingProgress.Progress = 0f;
        timer.Stop();
        yield break;
    }