protected virtual void Reset() { if (!NetworkManager.IsServer) { return; } if (m_GeneratedLobbyBlocksCount == 0 && !m_RegenerateOnReset) { return; } m_RegenerateOnReset = false; m_Reset = true; RemoveAll(); m_CurrentX = 0f; m_LastBlock = null; m_LastBackgroundBlock = null; for (int i = 0; i < m_BackgroundLayers.Length; i++) { m_BackgroundLayers [i].Reset(); } m_FathestBackgroundX = 0f; m_Blocks.Clear(); m_BackgroundBlocks.Clear(); m_GeneratedStartBlocksCount = 0; m_GeneratedMiddleBlocksCount = 0; m_GeneratedEndBlocksCount = 0; if (m_GeneratedLobbyBlocksCount > 0) { m_GeneratedLobbyBlocksCount = 0; Generate(); // need new spawn immediately } m_Reset = false; }
public void GenerateBackground() { for (int i = 0; i < m_BackgroundLayers.Length; i++) { int random = Random.Range(0, 2); bool generate = random == 1 ? true : false; if (!generate) { continue; } Vector3 current = new Vector3(m_BackgroundLayers[i].CurrentX, 0f, 0f); BackgroundBlock block = (BackgroundBlock)ChooseFrom(m_BackgroundLayers[i].Blocks); float newX = 0f; if (m_BackgroundLayers[i].LastBlock != null) { newX = m_BackgroundLayers[i].CurrentX + m_BackgroundLayers[i].LastBlock.Width; } else { newX = 0f; } if (block != null && (m_BackgroundLayers[i].LastBlock == null || newX < DEFAULT_TERRAIN_LENGTH + m_BackgroundGenerateRange)) { CreateBackgroundBlock(block, current, m_BackgroundLayers[i], i); } } }
public void GenerateBackground() { if (m_CurrentX < m_Settings.LevelLength || m_Settings.LevelLength <= 0) { for (int i = 0; i < m_BackgroundLayers.Length; i++) { int random = Random.Range(0, 2); bool generate = random == 1 ? true : false; if (!generate) { continue; } Vector3 current = new Vector3(m_BackgroundLayers[i].CurrentX, 0f, 0f); BackgroundBlock block = (BackgroundBlock)ChooseFrom(m_BackgroundLayers[i].Blocks); float newX = 0f; if (m_BackgroundLayers[i].LastBlock != null) { newX = m_BackgroundLayers[i].CurrentX + m_BackgroundLayers[i].LastBlock.Width; } else { newX = 0f; } if (block != null && (m_BackgroundLayers[i].LastBlock == null || newX < m_Character.transform.position.x + m_BackgroundGenerateRange)) { CreateBackgroundBlock(block, current, m_BackgroundLayers[i], i); } } } }
public void GenerateMiddle(int block_number) { Debug.Log(block_number); Block block = null; Vector3 current = new Vector3(m_CurrentX, 0f, 0f); if (m_GeneratedMiddleBlocksCount < m_Settings.MiddleBlocksCount || m_Settings.MiddleBlocksCount <= 0) { if (GameManager.Singleton.AdaptivityOn) { block = m_Settings.MiddleBlocks[block_number]; } else { block = ChooseMiddle(m_Settings.MiddleBlocks); } } if (block != null) { if (m_Settings.MiddleBlocksCount > 0) { m_GeneratedMiddleBlocksCount++; } CreateBlock(block, current); current = new Vector3(m_CurrentX, 0f, 0f); CreateBlock(m_Settings.SpecialThinkingBlock, current); } for (int i = 0; i < m_BackgroundLayers.Length; i++) { int random = Random.Range(0, 2); bool generate = random == 1 ? true : false; if (!generate) { continue; } current = new Vector3(m_BackgroundLayers[i].CurrentX, 0f, 0f); BackgroundBlock BGblock = (BackgroundBlock)ChooseFrom(m_BackgroundLayers[i].Blocks); float newX = 0f; if (m_BackgroundLayers[i].LastBlock != null) { newX = m_BackgroundLayers[i].CurrentX + m_BackgroundLayers[i].LastBlock.Width; } else { newX = 0f; } if (BGblock != null && (m_BackgroundLayers[i].LastBlock == null || newX < m_Character.transform.position.x + m_BackgroundGenerateRange)) { CreateBackgroundBlock(BGblock, current, m_BackgroundLayers[i], i); } } }
protected virtual void Reset() { m_Reset = true; RemoveAll(); m_CurrentX = 0f; m_LastBlock = null; m_LastBackgroundBlock = null; for (int i = 0; i < m_BackgroundLayers.Length; i++) { m_BackgroundLayers [i].Reset(); } m_FathestBackgroundX = 0f; m_Blocks.Clear(); m_BackgroundBlocks.Clear(); m_GeneratedStartBlocksCount = 0; m_GeneratedMiddleBlocksCount = 0; m_GeneratedEndBlocksCount = 0; m_Reset = false; }
public virtual bool CreateBackgroundBlock(BackgroundBlock blockPrefab, Vector3 position, BackgroundLayer layer, int layerIndex) { if (blockPrefab == null) { return(false); } blockPrefab.PreGenerate(this); position.z = blockPrefab.transform.position.z; position.y = blockPrefab.transform.position.y; BackgroundBlock block = Instantiate <BackgroundBlock> (blockPrefab, position, Quaternion.identity); float width = Random.Range(block.MinWidth, block.MaxWidth); m_BackgroundLayers [layerIndex].PreviousX = m_BackgroundLayers [layerIndex].CurrentX; m_BackgroundLayers [layerIndex].CurrentX += width; block.Width = width; m_BackgroundLayers [layerIndex].LastBlock = block; m_BackgroundBlocks.Add(position, block); blockPrefab.PostGenerate(this); if (m_BackgroundLayers [layerIndex].CurrentX > m_FathestBackgroundX) { m_FathestBackgroundX = m_BackgroundLayers [layerIndex].CurrentX; } return(true); }
public virtual void RemoveBackgroundBlock(BackgroundBlock block) { block.OnRemove(this); Destroy(m_BackgroundBlocks [block.transform.position].gameObject); m_BackgroundBlocks.Remove(block.transform.position); }
public virtual void Generate() { if (m_CurrentX < m_Settings.LevelLength || m_Settings.LevelLength <= 0) { bool isEnd = false, isStart = false, isMiddle = false; Block block = null; Vector3 current = new Vector3(m_CurrentX, 0f, 0f); float newX = 0f; if (m_GeneratedStartBlocksCount < m_Settings.StartBlocksCount || m_Settings.StartBlocksCount <= 0) { isStart = true; block = ChooseFrom(m_Settings.StartBlocks); } else if (m_GeneratedMiddleBlocksCount < m_Settings.MiddleBlocksCount || m_Settings.MiddleBlocksCount <= 0) { isMiddle = true; block = ChooseFrom(m_Settings.MiddleBlocks); } else if (m_GeneratedEndBlocksCount < m_Settings.EndBlocksCount || m_Settings.EndBlocksCount <= 0) { isEnd = true; block = ChooseFrom(m_Settings.EndBlocks); } if (m_LastBlock != null) { newX = m_CurrentX + m_LastBlock.Width; } else { newX = 0f; } if (block != null && (m_LastBlock == null || newX < m_Character.transform.position.x + m_GenerateRange)) { if (isStart) { if (m_Settings.StartBlocksCount > 0) { m_GeneratedStartBlocksCount++; } } else if (isMiddle) { if (m_Settings.MiddleBlocksCount > 0) { m_GeneratedMiddleBlocksCount++; } } else if (isEnd) { if (m_Settings.EndBlocksCount > 0) { m_GeneratedEndBlocksCount++; } } CreateBlock(block, current); } } for (int i = 0; i < m_BackgroundLayers.Length; i++) { int random = Random.Range(0, 2); bool generate = random == 1 ? true : false; if (!generate) { continue; } Vector3 current = new Vector3(m_BackgroundLayers [i].CurrentX, 0f, 0f); BackgroundBlock block = ( BackgroundBlock )ChooseFrom(m_BackgroundLayers [i].Blocks); float newX = 0f; if (m_BackgroundLayers [i].LastBlock != null) { newX = m_BackgroundLayers [i].CurrentX + m_BackgroundLayers [i].LastBlock.Width; } else { newX = 0f; } if (block != null && (m_BackgroundLayers [i].LastBlock == null || newX < m_Character.transform.position.x + m_BackgroundGenerateRange)) { CreateBackgroundBlock(block, current, m_BackgroundLayers [i], i); } } }
public void Reset() { CurrentX = 0f; PreviousX = 0f; LastBlock = null; }