Ability to Restart Level, Player Spawning and a Test Level added + Bug Fix
This commit is contained in:
		
							
								
								
									
										1240
									
								
								Assets/Resources/Levels/99.prefab
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										1240
									
								
								Assets/Resources/Levels/99.prefab
									
									
									
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
							
								
								
									
										7
									
								
								Assets/Resources/Levels/99.prefab.meta
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										7
									
								
								Assets/Resources/Levels/99.prefab.meta
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,7 @@
 | 
				
			|||||||
 | 
					fileFormatVersion: 2
 | 
				
			||||||
 | 
					guid: 195a574a43515b84da3e006bc1890628
 | 
				
			||||||
 | 
					PrefabImporter:
 | 
				
			||||||
 | 
					  externalObjects: {}
 | 
				
			||||||
 | 
					  userData: 
 | 
				
			||||||
 | 
					  assetBundleName: 
 | 
				
			||||||
 | 
					  assetBundleVariant: 
 | 
				
			||||||
@@ -109,7 +109,7 @@ GameObject:
 | 
				
			|||||||
  - component: {fileID: 7008207192594766308}
 | 
					  - component: {fileID: 7008207192594766308}
 | 
				
			||||||
  m_Layer: 6
 | 
					  m_Layer: 6
 | 
				
			||||||
  m_Name: Player
 | 
					  m_Name: Player
 | 
				
			||||||
  m_TagString: Untagged
 | 
					  m_TagString: Player
 | 
				
			||||||
  m_Icon: {fileID: 0}
 | 
					  m_Icon: {fileID: 0}
 | 
				
			||||||
  m_NavMeshLayer: 0
 | 
					  m_NavMeshLayer: 0
 | 
				
			||||||
  m_StaticEditorFlags: 0
 | 
					  m_StaticEditorFlags: 0
 | 
				
			||||||
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							@@ -21,7 +21,7 @@ namespace AI
 | 
				
			|||||||
        protected bool isShooting = false;
 | 
					        protected bool isShooting = false;
 | 
				
			||||||
        protected IMovement movement = null;
 | 
					        protected IMovement movement = null;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        protected bool canShoot => (target.transform.position - transform.position).sqrMagnitude < attackRangeSquared && target != null;
 | 
					        protected bool canShoot => target != null && (target.transform.position - transform.position).sqrMagnitude < attackRangeSquared;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        public UnityEvent OnShoot { get; protected set; } = null;
 | 
					        public UnityEvent OnShoot { get; protected set; } = null;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -36,11 +36,13 @@ namespace AI
 | 
				
			|||||||
            cooldownPerShoot = 1f / attacksPerSecond;
 | 
					            cooldownPerShoot = 1f / attacksPerSecond;
 | 
				
			||||||
            attackRangeSquared = attackRange * attackRange;
 | 
					            attackRangeSquared = attackRange * attackRange;
 | 
				
			||||||
            OnShoot = new UnityEvent();
 | 
					            OnShoot = new UnityEvent();
 | 
				
			||||||
            UpdateTarget(FindObjectOfType<Player.PlayerController>()?.transform);
 | 
					 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        protected virtual void Start()
 | 
					        protected virtual void Start()
 | 
				
			||||||
            => movement = transform.GetComponentInParent<IMovement>();
 | 
					        {
 | 
				
			||||||
 | 
					            movement = transform.GetComponentInParent<IMovement>();
 | 
				
			||||||
 | 
					            UpdateTarget(FindObjectOfType<Player.PlayerController>()?.transform);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        protected virtual void Update()
 | 
					        protected virtual void Update()
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -40,5 +40,8 @@ namespace Level
 | 
				
			|||||||
            gameObject.SetActive(false);
 | 
					            gameObject.SetActive(false);
 | 
				
			||||||
            needsRestart = false;
 | 
					            needsRestart = false;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        [ContextMenu("Restart")]
 | 
				
			||||||
 | 
					        public void Restart() => LevelManager.Instance.SwitchToLevel(LevelName);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -46,6 +46,8 @@ namespace Level
 | 
				
			|||||||
                Destroy(this);
 | 
					                Destroy(this);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        public GameObject Player { get; private set; } = null;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        private void Initialize()
 | 
					        private void Initialize()
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            GameObject[] levelPrefabs = Resources.LoadAll<GameObject>("Levels/");
 | 
					            GameObject[] levelPrefabs = Resources.LoadAll<GameObject>("Levels/");
 | 
				
			||||||
@@ -64,6 +66,11 @@ namespace Level
 | 
				
			|||||||
                level.SetLevel(levelPrefab.name);
 | 
					                level.SetLevel(levelPrefab.name);
 | 
				
			||||||
                _levels.Add(levelPrefab.gameObject.name, level);
 | 
					                _levels.Add(levelPrefab.gameObject.name, level);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            Player = GameObject.FindWithTag("Player");
 | 
				
			||||||
 | 
					            if (Player == null)
 | 
				
			||||||
 | 
					                Player = (GameObject)Instantiate(Resources.Load("Playable/Player"), transform.position, Quaternion.identity);
 | 
				
			||||||
 | 
					            Player.SetActive(false);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        public void SwitchToLevel(string levelName)
 | 
					        public void SwitchToLevel(string levelName)
 | 
				
			||||||
@@ -73,13 +80,16 @@ namespace Level
 | 
				
			|||||||
            currentLevel = Levels[levelName];
 | 
					            currentLevel = Levels[levelName];
 | 
				
			||||||
            currentLevel.Enable();
 | 
					            currentLevel.Enable();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            // TODO Move Player To currentLevel.StartingPoint
 | 
					            Player.SetActive(true);
 | 
				
			||||||
 | 
					            Player.transform.position = currentLevel.StartingPoint.position;
 | 
				
			||||||
 | 
					            Player.GetComponent<Rigidbody2D>().velocity = Vector2.zero;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            UIManager.Instance.CloseAllCanvases();
 | 
					            UIManager.Instance.CloseAllCanvases();
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        private void DisableAllLevels()
 | 
					        private void DisableAllLevels()
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
 | 
					            Player.SetActive(false);
 | 
				
			||||||
            foreach (Level level in Levels.Values)
 | 
					            foreach (Level level in Levels.Values)
 | 
				
			||||||
                level.Disable();
 | 
					                level.Disable();
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user