Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class LoadPersonData : MonoBehaviour,ILoadPersonData
- {
- private LoadPlayerInfo _loadPlayerInfo;
- private string _name;
- private APIScript _apiScript;
- [SerializeField] private GameObject scoreElement;
- [SerializeField] private Transform scoreboardContent;
- [SerializeField] private SaveAllUserData saveAllUserData;
- public static LoadPersonData instance;
- public SelectAnAction selectAnAction;
- public enum SelectAnAction
- {
- None,
- GetAllUserData,
- LoadPersons,
- LoadWeapon,
- LoadArmor,
- LoadHelmet,
- LoadSkins
- }
- // Start is called before the first frame update
- private void Awake()
- {
- if (instance == null)
- {
- instance = this;
- }
- else if (instance != null)
- {
- Debug.Log("Instance already exists, destroying object!");
- Destroy(this);
- }
- }
- void Start()
- {
- GetUserData();
- }
- private void GetUserData()
- {
- Debug.Log(" LoadPersonData GetUserData");
- switch (selectAnAction.ToString())
- {
- case "GetAllUserData":
- GetAllUserData();
- break;
- case "LoadPersons":
- LoadPersons();
- break;
- case "None":
- break;
- }
- }
- public void GetAllUserData()
- {
- _apiScript = APIScript.instance;
- _apiScript.GetAllUserData();
- }
- public void SaveUserData(Data allUserData)
- {
- saveAllUserData.allUserData = allUserData;
- }
- public void LoadPersons()
- {
- ClearTheListOfCharacters();
- InstanceScoresElementsPerson();
- // Debug.Log("PersonData UserInfo = " + loadCurrentLoadPersonData.data);
- }
- public void LoadHelmets()
- {
- throw new System.NotImplementedException();
- }
- public void LoadWeapons()
- {
- throw new System.NotImplementedException();
- }
- public void LoadArmors()
- {
- throw new System.NotImplementedException();
- }
- public void LoadASkins()
- {
- throw new System.NotImplementedException();
- }
- private void InstanceScoresElementsPerson()
- {
- Data userData = saveAllUserData.allUserData;
- List<API.Models.UserGetData.UserPerson> userDataUserPersons = userData.user_persons;
- Debug.Log("LoadPersons UserAllData userAllData.UserPersons Count = " +
- userDataUserPersons.Count);
- // Debug.Log("LoaadPersonData LoadPersons UserAllData userAllData.UserPersons Count = " + loadCurrentLoadPersonData.data.user_persons.Count);
- foreach (API.Models.UserGetData.UserPerson userPerson in userDataUserPersons)
- {
- if (userPerson.person.unity_identify != null)
- {
- InstanceScoresElement(userPerson);
- }
- }
- }
- private void InstanceScoresElement(API.Models.UserGetData.UserPerson userPerson)
- {
- GameObject scoreboardElement = Instantiate(scoreElement, scoreboardContent);
- scoreboardElement.GetComponent<ItemElement>().NewScoreElement(userPerson);
- }
- public void ClearTheListOfCharacters()
- {
- //Clear the list of characters on the screen
- Debug.Log("LoadPersons UserAllData lear the list of characters on the screen ");
- for (int i = 1; i < scoreboardContent.transform.childCount - 1;)
- {
- DestroyImmediate(scoreboardContent.transform.GetChild(i).gameObject);
- i++;
- }
- }
- public void UpdateTheListOfCharacters()
- {
- // TODO //Clear the list of characters on the screen
- // Root loadCurrentLoadPersonData = PersonDataSafeLoad.instance.LoadCurrentLoadPerson();
- // // Debug.Log("PersonData UserInfo = " + loadCurrentLoadPersonData.data);
- //
- // Debug.Log("LoadPersons UserAllData userAllData.UserPersons Count = " +
- // loadCurrentLoadPersonData.data.user_persons.Count);
- // // Debug.Log("LoaadPersonData LoadPersons UserAllData userAllData.UserPersons Count = " + loadCurrentLoadPersonData.data.user_persons.Count);
- // int index = 1;
- //
- // foreach (userGetdata.UserPerson userPerson in loadCurrentLoadPersonData.data.user_persons)
- // {
- // if (userPerson.person.unity_identify != null)
- // {
- // GameObject scoreboardElement = scoreboardContent.transform.GetChild(index).gameObject;
- // scoreboardElement.GetComponent<ItemElement>().NewScoreElement(userPerson);
- // index++;
- // }
- // }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement