private void ParsePlatformTransition(Runner.PlatformObject[] list) { var checkList = new List <int>(); Dictionary <int, Runner.PlatformObject> outDic; Runner.PlatformObject current = null; foreach (var p in list) { if (transitionByType.TryGetValue(p.Type, out outDic) == false) { outDic = new Dictionary <int, PlatformObject>(); transitionByType.Add(p.Type, outDic); } if (outDic.TryGetValue(p.TypeTo, out current)) { ErrorManager.Show("Error", string.Format("LocationManager ParsePlatformTransition, type:{0}, typeTo:{1} - exist already", p.Type, p.TypeTo)); return; } if (checkList.Contains(p.Type) == false) { checkList.Add(p.Type); } outDic.Add(p.TypeTo, p); } var checkResult = CheckTransitionCount(checkList.Count); if (checkList.Count != list.Length) { ErrorManager.Show("Error", string.Format("LocationManager ParsePlatformTransition list is not correct")); return; } }
public void Add(Runner.PlatformObject item) { if (item.AllowDispose) { if (list.Contains(item) == false) { list.Add(item); } } }
public void Remove(Runner.PlatformObject platform) { if (list.Remove(platform)) { platform.InPlatformList = false; } platformsManager.PushPlatform(platform); platform.gameObject.SetActive(false); disposedPlatformContainer.AddChild(platform.gameObject); PowerUpManager.RemovePowerUpObjects(platform); }
public void PushPlatform(Runner.PlatformObject p) { List <Runner.PlatformObject> array; if (PoolById.TryGetValue(p.Id, out array) == false) { array = new List <PlatformObject>(); PoolById.Add(p.Id, array); } p.gameObject.SetActive(false); array.Add(p); }
public void Update(Runner.PlayerController player) { List <Runner.PlatformObject> collection = children.List; var len = collection.Count; Runner.PlatformObject platform = null; var distance = player.gameObject.transform.position; for (var i = 0; i < len; i++) { platform = collection[i]; if (platform.AllowDispose == false) { if (platform.transform.position.z < distance.z) { platform.AllowDispose = true; Add(platform); } else { break; } } } len = list.Count; var index = 0; float currentDistance; float halfPlatformSize; while (index < len) { platform = list[index]; currentDistance = Mathf.Abs(platform.transform.position.Distance(ref distance)); halfPlatformSize = platform.Size.z / 2; if (currentDistance >= LocationManager.DisposeDistance && currentDistance > halfPlatformSize * LocationManager.MinDisposeMultiply) { index++; platform.AllowDispose = false; children.Remove(platform); } else { break; } } if (index > 0) { list.RemoveRange(0, index); } }
private void ParsePlatforms(Runner.PlatformObject[] platforms, Runner.PlatformObject[] startPlatforms, Runner.PlatformObject[] transitionPlatforms) { this.list = platforms; this.startList = startPlatforms; ListById = new Runner.PlatformObject[platforms.Length + startPlatforms.Length + transitionPlatforms.Length]; listSize = new Vector3[ListById.Length]; ListByType = new Dictionary <int, List <PlatformObject> >(); Runner.PlatformObject current = null; int index = 0; for (var i = 0; i < startPlatforms.Length; i++, index++) { current = startPlatforms[i]; current.Id = index; current.IsStartPlatform = true; ListById[index] = current; } for (var i = 0; i < platforms.Length; i++, index++) { current = platforms[i]; current.Id = index; ListById[index] = current; AddToListByType(current); } for (var i = 0; i < transitionPlatforms.Length; i++, index++) { current = transitionPlatforms[i]; if (current.Mode != PlatformMode.Transition) { throw new Exception("platform.Mode != Platform.Transition in transition list"); } current.Id = index; ListById[index] = current; } ParseSize(startPlatforms); ParseSize(platforms); ParseSize(transitionPlatforms); ParsePlatformTransition(transitionPlatforms); }
public void Add(Runner.PlatformObject platform) { if (list.Contains(platform) == false) { list.Add(platform); platform.InPlatformList = true; if (Last == null) { Last = platform; } else if (platform.transform.position.z > Last.transform.position.z) { Last = platform; } if (!platform.gameObject.activeSelf) { platform.gameObject.SetActive(true); } platformContainer.AddChild(platform.gameObject); PowerUpManager.AddPowerUpObjects(platform); } }
public Runner.PlatformObject PopPlatform(int id) { List <Runner.PlatformObject> array; Runner.PlatformObject result = null; int count; if (PoolById.TryGetValue(id, out array)) { count = array.Count; if (count > 0) { result = (Runner.PlatformObject)array[count - 1]; array.RemoveAt(count - 1); } } if (result == null) { result = ListById[id].Clone(); } //result.gameObject.SetActive(false); result.SetStartTransform(); return(result); }
public void Generate(float speed, Runner.PlayerController player) { Runner.PlatformObject platform = _platforms.Last; bool isStartPlatform = false; if (platform == null) { platform = _platformsManager.GetRandomStartPlatform(Runner.PlayerData.PlatformType); isStartPlatform = true; if (platform == null) { ErrorManager.Show("empty start platform", "add start platforms"); return; } PlayerData.PlatformTypeRemainingDistance = _platformsManager.GetDistanceByType(platform.Type); _next = platform.GetNextRandom(); _platforms.Add(platform); } float distance = platform.Distance(player); Vector3 size; int count = 0; while (distance <= LocationManager.GenerateDistance && count < Runner.LocationManager.MaxGeneratePlatforms) { int nextType = -1; if (PlayerData.PlatformTypeRemainingDistance <= 0.0f && isStartPlatform == false) { nextType = _platformsManager.GetTypeByDistance(player.Distance, PlayerData.PlatformType, Random.Range(0, 2) > 0); if (nextType == -1) { nextType = platform.Type; } if (nextType != PlayerData.PlatformType) { _next = _platformsManager.GetTransitionPlatform(PlayerData.PlatformType, nextType); } if (_next == null) { _next = _platformsManager.GetRandomPlatformByTypeAndDistance(PlayerData.PlatformType, player.Distance); } PlayerData.PlatformType = nextType; PlayerData.PlatformTypeRemainingDistance += _platformsManager.GetDistanceByType(nextType); } else { _next = _next != null ? _next : _platformsManager.GetRandomPlatformByTypeAndDistance(PlayerData.PlatformType, _player.Distance); } _platformsManager.GetSize(out size, platform); vectorHelper.x = 0; vectorHelper.y = 0; vectorHelper.z = size.z - size.z / 2; _next.transform.position = platform.transform.position + vectorHelper; platform = _next; _platformsManager.GetSize(out size, platform); vectorHelper.x = 0; vectorHelper.y = 0; vectorHelper.z = size.z - size.z / 2; platform.transform.position += vectorHelper; distance = platform.Distance(player); _platforms.Add(platform); _next = platform.GetNextRandom(); count++; } }
public Runner.PlatformObject PopPlatform(Runner.PlatformObject p) { return(PopPlatform(p.Id)); }
public void GetSize(out Vector3 result, Runner.PlatformObject p) { result = (Vector3)listSize[p.Id]; }
public Vector3 GetSize(Runner.PlatformObject p) { return((Vector3)listSize[p.Id]); }