public IEnumerator LoadGroupsOverTime() { Debug.Log("Superloading path " + GroupPath); if (string.IsNullOrEmpty(GroupPath)) { Debug.Log("Path was empty!"); OnFinish(); yield break; } GroupsToLoad = WIGroup.SplitPath(GroupPath); //pop the first - it will be the root GroupsToLoad.Pop(); LastGroupLoaded = WIGroups.Get.Root; LastGroupLoaded.Load(); if (GroupsToLoad.Count > 0) { NextGroupToLoad = GroupsToLoad.Peek(); //start at the root and then load the groups all the way down //we'll keep loading groups until we've loaded everything in the stack while (GroupsToLoad.Count > 0) { State = "Loading group"; WIGroup nextGroup = null; while (!LastGroupLoaded.Is(WIGroupLoadState.Loaded) || !LastGroupLoaded.GetChildGroup(out nextGroup, NextGroupToLoad)) { Debug.Log("Last group " + LastGroupLoaded.name + " loaded? " + LastGroupLoaded.Is(WIGroupLoadState.Loaded).ToString() + "\n" + "Child group available? " + LastGroupLoaded.GetChildGroup(out nextGroup, NextGroupToLoad).ToString()); State = "Waiting for child group " + NextGroupToLoad; Ticks++; yield return(null); } //now that it has its child items, tell it to load its child groups LastGroupLoaded = nextGroup; GroupsToLoad.Pop(); if (GroupsToLoad.Count > 0) { NextGroupToLoad = GroupsToLoad.Peek(); Ticks++; yield return(null); } } yield return(null); //now we search the group to see if it holds the child item we're looking for while (!LastGroupLoaded.FindChildItem(ChildItemFileName, out LoadedWorldItem)) { //LastGroupLoaded.State = WIGroupState.ForceLoad; Ticks++; State = "Waiting for child item " + ChildItemFileName; yield return(null); } } //finished! OnFinish(); yield break; }
public IEnumerator LoadChunkGroups() { ChunkGroup.Load(); while (!ChunkGroup.Is(WIGroupLoadState.Loaded)) { //be patient yield return(null); } if (WorldItemsGroup == null) { WorldItemsGroup = WIGroups.GetOrAdd(Transforms.WorldItems.gameObject, Transforms.WorldItems.name, ChunkGroup, null); } WorldItemsGroup.Load(); while (!WorldItemsGroup.Is(WIGroupLoadState.Loaded)) { //be patient yield return(null); } if (AboveGroundGroup == null) { AboveGroundGroup = WIGroups.GetOrAdd(Transforms.AboveGroundWorldItems.gameObject, Transforms.AboveGroundWorldItems.name, WorldItemsGroup, null); AboveGroundGroup.Props.IgnoreOnSave = true; AboveGroundGroup.Props.TerrainType = LocationTerrainType.AboveGround; } if (BelowGroundGroup == null) { BelowGroundGroup = WIGroups.GetOrAdd(Transforms.BelowGroundWorldItems.gameObject, Transforms.BelowGroundWorldItems.name, WorldItemsGroup, null); BelowGroundGroup.Props.IgnoreOnSave = true; BelowGroundGroup.Props.TerrainType = LocationTerrainType.BelowGround; } AboveGroundGroup.Load(); BelowGroundGroup.Load(); yield break; }
public IEnumerator SpawnItemsOverTime() { System.Random random = new System.Random(Profile.Get.CurrentGame.Seed + worlditem.GetHashCode()); Location location = null; if (!worlditem.Is <Location> (out location)) { mIsSpawning = false; yield break; } while (!Player.Local.HasSpawned || location.LocationGroup == null || !location.LocationGroup.Is(WIGroupLoadState.Loaded)) { yield return(null); if (worlditem.Is(WIActiveState.Invisible) || !worlditem.Is(WILoadState.Initialized)) { //Debug.Log ("We went invisible before we could spawn in " + name); mIsSpawning = false; yield break; } } WIGroup spawnGroup = location.LocationGroup; for (int i = 0; i < State.SpawnerSettings.Count; i++) { SpawnerStateSetting setting = State.SpawnerSettings [i]; if (setting.TimeToSpawn) { setting.LastManualSpawnPointIndex = 0; //reset this just in case var enumerator = GetSpawnPoints(setting, location, spawnGroup, Player.Local, random).GetEnumerator(); while (enumerator.MoveNext()) { if (!spawnGroup.Is(WIGroupLoadState.Initialized | WIGroupLoadState.Loading | WIGroupLoadState.Loaded)) { //whoops, it unloaded yield break; } SpawnPoint spawnPoint = enumerator.Current; //wait a tick after fetching the spawn point yield return(null); if (spawnPoint != SpawnPoint.Empty) { var spawn = Spawn(spawnPoint, setting, location, spawnGroup, random); while (spawn.MoveNext()) { yield return(spawn.Current); } } double waitUntil = WorldClock.RealTime + Globals.SpawnerRTYieldInterval + UnityEngine.Random.value * 0.25f; while (WorldClock.RealTime < waitUntil) { yield return(null); } } int gameHoursToNextSpawnTime = random.Next(setting.MinHoursBetweenSpawns, setting.MaxHoursBetweenSpawns); setting.NextSpawnTime = WorldClock.AdjustedRealTime + WorldClock.HoursToSeconds(gameHoursToNextSpawnTime); } yield return(null); } mIsSpawning = false; yield break; }