123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310 |
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using DG.Tweening;
- using UnityEngine.AI;
- using UnityEngine.SceneManagement;
- [Serializable]
- public class PlayerData
- {
- [SerializeField]
- public int Heart;
- //[SerializeField]
- //public int Level;
- [SerializeField]
- public int Stage;
- }
- public class Core : MonoBehaviour
- {
- public static Core Instance;
- public List<GameObject> PlayerMalePrefabs;
- public List<GameObject> PlayerFemalePrefabs;
- public int CurIndexPlayer;
- public Transform ParentMale;
- public Transform ParentFemale;
- //public Transform SpawnPoint;
- public Transform _player;
- [SerializeField]
- public PlayerData PlayerData;
- public InputController Controller;
- public Transform PartPlayerInGame;
- public bool LevelEnd;
- public enum Gender
- {
- Male,
- Female
- }
- public Gender CurGender;
- public enum StateModeGame
- {
- IsGameMode,
- Kiss,
- Menu,
- StartLevel
- }
- public StateModeGame IsGameMode;
- public RunnersController PlayerGame;
-
- public void Start()
- {
- Instance = this;
- Load();
- }
- public void GetPlayerForSelecting(int index, Gender gender)
- {
- CurIndexPlayer = index;
- GameObject go;
- switch (gender)
- {
- case Gender.Male:
- if (_player != null)
- {
- _player.DOScale(0, 0.5f).OnComplete(() => {
- Destroy(_player.gameObject);
- go = Instantiate(PlayerMalePrefabs[index]);
- _player = go.transform;
- go.transform.SetParent(LevelManager.Instance.CurLevel.SpawnPointPlayer);
- go.transform.localPosition = Vector3.zero;
- go.transform.localScale = Vector3.zero;
- go.transform.localEulerAngles = Vector3.zero;
- _player.DOScale(1, 0.5f);
- });
- }
- else
- {
- go = Instantiate(PlayerMalePrefabs[index]);
- _player = go.transform;
- go.transform.SetParent(LevelManager.Instance.CurLevel.SpawnPointPlayer);
- go.transform.localPosition = Vector3.zero;
- go.transform.localScale = Vector3.zero;
- _player.DOScale(1, 0.5f);
- }
-
- break;
- case Gender.Female:
-
- if (_player != null)
- {
- _player.DOScale(0, 0.5f).OnComplete(() => {
- Destroy(_player.gameObject);
- go = Instantiate(PlayerFemalePrefabs[index]);
- _player = go.transform;
- go.transform.SetParent(LevelManager.Instance.CurLevel.SpawnPointPlayer);
- go.transform.localPosition = Vector3.zero;
- go.transform.localScale = Vector3.zero;
- go.transform.localEulerAngles = Vector3.zero;
- _player.DOScale(1, 0.5f);
- });
- }
- else
- {
- go = Instantiate(PlayerFemalePrefabs[index]);
- _player = go.transform;
- go.transform.SetParent(LevelManager.Instance.CurLevel.SpawnPointPlayer);
- go.transform.localPosition = Vector3.zero;
- go.transform.localScale = Vector3.zero;
- _player.DOScale(1, 0.5f);
- }
-
- break;
- }
- }
- public void SetCristal()
- {
- ///TO DO
- }
- public void SetMale()
- {
- ParentMale.gameObject.SetActive(true);
- }
- public void SetFemale()
- {
- ParentFemale.gameObject.SetActive(true);
- }
- public void SetHeart()
- {
- PlayerData.Heart++;
- }
- public void SetPlayer()
- {
- switch(CurGender)
- {
- case Gender.Female:
- Controller.OurPlayer = PlayerFemalePrefabs[CurIndexPlayer].GetComponent<SwipeMove>();
- UIManager.Instance.CompleteCameraController.Target = PlayerFemalePrefabs[CurIndexPlayer].transform;
- Controller.OurPlayer.enabled = true;
- PlayerFemalePrefabs[CurIndexPlayer].GetComponent<RunnersController>().SetPlayer(UIManager.Instance.InputName.text);
- PlayerFemalePrefabs[CurIndexPlayer].GetComponent<RunnersController>().IsPlayer = true;
- Core.Instance.PlayerGame = PlayerFemalePrefabs[CurIndexPlayer].GetComponent<RunnersController>();
- break;
- case Gender.Male:
- Controller.OurPlayer = PlayerMalePrefabs[CurIndexPlayer].GetComponent<SwipeMove>();
- Controller.OurPlayer.enabled = true;
- UIManager.Instance.CompleteCameraController.Target = PlayerMalePrefabs[CurIndexPlayer].transform;
- PlayerMalePrefabs[CurIndexPlayer].GetComponent<RunnersController>().SetPlayer(UIManager.Instance.InputName.text);
- PlayerMalePrefabs[CurIndexPlayer].GetComponent<RunnersController>().IsPlayer = true;
- Core.Instance.PlayerGame = PlayerMalePrefabs[CurIndexPlayer].GetComponent<RunnersController>();
- break;
- }
-
- }
- public void ResetLevel()
- {
- UIManager.Instance.ResetLevelData();
- }
- public void ResetPlayers()
- {
-
- //StartCoroutine(LoadSceneAndSetActive("Loc_2"));
- switch (CurGender)
- {
- case Gender.Male:
- for (var i = 0; i < PlayerMalePrefabs.Count; i++)
- {
- PlayerMalePrefabs[i].SetActive(true);
- PlayerMalePrefabs[i].transform.SetParent(ParentMale);
- //PlayerMalePrefabs[i].transform.position = PlayerMalePrefabs[i].GetComponent<RunnersController>().StartPos;
- PlayerMalePrefabs[i].transform.localEulerAngles = new Vector3(0,180,0);
- PlayerMalePrefabs[i].GetComponent<SwipeMove>().enabled = false;
- PlayerMalePrefabs[i].GetComponent<NavMeshAgent>().enabled = false;
- PlayerMalePrefabs[i].GetComponent<RunnersController>().enabled = true;
- PlayerMalePrefabs[i].GetComponent<RunnersController>().Agent.speed = 8;
- PlayerMalePrefabs[i].GetComponent<RunnersController>().ResetAnimation();
- }
- break;
- case Gender.Female:
- for (var i = 0; i < PlayerFemalePrefabs.Count; i++)
- {
- PlayerFemalePrefabs[i].SetActive(true);
- PlayerFemalePrefabs[i].transform.SetParent(ParentFemale);
- //PlayerFemalePrefabs[i].transform.position = PlayerFemalePrefabs[i].GetComponent<RunnersController>().StartPos;
- PlayerMalePrefabs[i].transform.localEulerAngles = new Vector3(0, 180, 0);
- PlayerFemalePrefabs[i].GetComponent<SwipeMove>().enabled = false;
- PlayerFemalePrefabs[i].GetComponent<NavMeshAgent>().enabled = false;
- PlayerMalePrefabs[i].GetComponent<RunnersController>().enabled = true;
- PlayerFemalePrefabs[i].GetComponent<RunnersController>().Agent.speed = 8;
- PlayerFemalePrefabs[i].GetComponent<RunnersController>().ResetAnimation();
- }
- break;
- }
- //ResetAnimation();
- Core.Instance.SetPlayerNewLevel();
- }
- public void SetPlayerNewLevel()
- {
- for (var i = 0; i < PlayerMalePrefabs.Count; i++)
- {
- PlayerMalePrefabs[i].transform.position = LevelManager.Instance.CurLevel.ListPlayerSpawnPoints[i].position;
- PlayerMalePrefabs[i].GetComponent<RunnersController>()._target = LevelManager.Instance.CurLevel.LevelTargets.ListLevelTargets[0];
- }
- for (var i = 0; i < PlayerFemalePrefabs.Count; i++)
- {
- PlayerFemalePrefabs[i].transform.position = LevelManager.Instance.CurLevel.ListPlayerSpawnPoints[i].position;
- PlayerFemalePrefabs[i].GetComponent<RunnersController>()._target = LevelManager.Instance.CurLevel.LevelTargets.ListLevelTargets[0];
- }
- }
- public void ResetPlayerPos()
- {
- //LoadSceneAndSetActive("Loc_2");
- ResetPlayers();
- //switch (CurGender)
- //{
- // case Gender.Female:
- // for (var i = 0; i < PlayerFemalePrefabs.Count; i++)
- // {
- // PlayerFemalePrefabs[i].GetComponent<RunnersController>().ResetPos();
- // PlayerFemalePrefabs[i].SetActive(true);
- // }
- // break;
- // case Gender.Male:
- // for (var i = 0; i < PlayerMalePrefabs.Count; i++)
- // {
- // PlayerMalePrefabs[i].GetComponent<RunnersController>().ResetPos();
- // PlayerFemalePrefabs[i].SetActive(true);
- // }
- // break;
- //}
-
- }
- private IEnumerator LoadSceneAndSetActive(string sceneName)
- {
- Debug.Log("LOAD");
- var sceneActive = SceneManager.GetActiveScene();
- if (sceneActive.name != "Loc_2")
- {
- SceneManager.UnloadSceneAsync(sceneActive.buildIndex);
- var async = SceneManager.LoadSceneAsync(1, LoadSceneMode.Additive);
- while (!async.isDone)
- {
- yield return new WaitForEndOfFrame();
- }
- Debug.Log("DONE LOAD");
- SceneManager.SetActiveScene(SceneManager.GetSceneByName("Loc_2".ToString()));
- Destroy(LevelManager.Instance.ListLevels[0].gameObject);
- }
- yield return new WaitForEndOfFrame();
- Debug.Log("No LOAD");
- //var async = Application.LoadLevelAdditive("Loc_1");
- //Debug.Log(currentLevel.IndexEnvironment.ToString());
- }
- //public void IncreaseLevelPlayer()
- //{
- // PlayerData.Level++;
- //}
- public void IncreaseStagePlayer()
- {
- PlayerData.Stage++;
- Core.Instance.Save();
- }
- public void Load()
- {
-
- PlayerData.Stage = PlayerPrefs.GetInt("Stage");
- }
- public void Save()
- {
- PlayerPrefs.SetInt("Stage", PlayerData.Stage);
- PlayerPrefs.Save();
- }
- private void OnApplicationPause(bool pause)
- {
- //Save();
- }
- private void OnApplicationQuit()
- {
- //Save();
- }
- private void OnApplicationFocus(bool focus)
- {
- //Debug.LogError("Save");
- //Save();
- }
- }
|