Advertisement
Denisimus

Untitled

Feb 10th, 2022
796
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 5.16 KB | None | 0 0
  1.   public class LoadPersonData : MonoBehaviour,ILoadPersonData
  2.     {
  3.         private LoadPlayerInfo _loadPlayerInfo;
  4.         private string _name;
  5.         private APIScript _apiScript;
  6.  
  7.         [SerializeField] private GameObject scoreElement;
  8.         [SerializeField] private Transform scoreboardContent;
  9.         [SerializeField] private SaveAllUserData saveAllUserData;
  10.  
  11.         public static LoadPersonData instance;
  12.  
  13.         public SelectAnAction selectAnAction;
  14.  
  15.         public enum SelectAnAction
  16.         {
  17.             None,
  18.             GetAllUserData,
  19.             LoadPersons,
  20.             LoadWeapon,
  21.             LoadArmor,
  22.             LoadHelmet,
  23.             LoadSkins
  24.         }
  25.  
  26.         // Start is called before the first frame update
  27.         private void Awake()
  28.         {
  29.             if (instance == null)
  30.             {
  31.                 instance = this;
  32.             }
  33.             else if (instance != null)
  34.             {
  35.                 Debug.Log("Instance already exists, destroying object!");
  36.                 Destroy(this);
  37.             }
  38.         }
  39.  
  40.         void Start()
  41.         {
  42.             GetUserData();
  43.         }
  44.  
  45.         private void GetUserData()
  46.         {
  47.             Debug.Log(" LoadPersonData GetUserData");
  48.  
  49.             switch (selectAnAction.ToString())
  50.             {
  51.                 case "GetAllUserData":
  52.                     GetAllUserData();
  53.                     break;
  54.                 case "LoadPersons":
  55.                     LoadPersons();
  56.                     break;
  57.                 case "None":
  58.                     break;
  59.             }
  60.         }
  61.  
  62.         public void GetAllUserData()
  63.         {
  64.             _apiScript = APIScript.instance;
  65.             _apiScript.GetAllUserData();
  66.         }
  67.  
  68.         public void SaveUserData(Data allUserData)
  69.         {
  70.             saveAllUserData.allUserData = allUserData;
  71.         }
  72.  
  73.  
  74.         public void LoadPersons()
  75.         {
  76.             ClearTheListOfCharacters();
  77.             InstanceScoresElementsPerson();
  78.  
  79. //        Debug.Log("PersonData UserInfo = " + loadCurrentLoadPersonData.data);
  80.         }
  81.         public void LoadHelmets()
  82.         {
  83.             throw new System.NotImplementedException();
  84.         }
  85.  
  86.         public void LoadWeapons()
  87.         {
  88.             throw new System.NotImplementedException();
  89.         }
  90.  
  91.         public void LoadArmors()
  92.         {
  93.             throw new System.NotImplementedException();
  94.         }
  95.  
  96.         public void LoadASkins()
  97.         {
  98.             throw new System.NotImplementedException();
  99.         }
  100.        
  101.         private void InstanceScoresElementsPerson()
  102.         {
  103.             Data userData = saveAllUserData.allUserData;
  104.             List<API.Models.UserGetData.UserPerson> userDataUserPersons = userData.user_persons;
  105.             Debug.Log("LoadPersons UserAllData userAllData.UserPersons Count = " +
  106.                       userDataUserPersons.Count);
  107.  
  108.             //  Debug.Log("LoaadPersonData LoadPersons UserAllData userAllData.UserPersons Count = " + loadCurrentLoadPersonData.data.user_persons.Count);
  109.  
  110.             foreach (API.Models.UserGetData.UserPerson userPerson in userDataUserPersons)
  111.             {
  112.                 if (userPerson.person.unity_identify != null)
  113.                 {
  114.                     InstanceScoresElement(userPerson);
  115.                 }
  116.             }
  117.         }
  118.  
  119.         private void InstanceScoresElement(API.Models.UserGetData.UserPerson userPerson)
  120.         {
  121.             GameObject scoreboardElement = Instantiate(scoreElement, scoreboardContent);
  122.             scoreboardElement.GetComponent<ItemElement>().NewScoreElement(userPerson);
  123.         }
  124.  
  125.  
  126.         public void ClearTheListOfCharacters()
  127.         {
  128.             //Clear the list of characters on the screen
  129.             Debug.Log("LoadPersons UserAllData lear the list of characters on the screen ");
  130.             for (int i = 1; i < scoreboardContent.transform.childCount - 1;)
  131.             {
  132.                 DestroyImmediate(scoreboardContent.transform.GetChild(i).gameObject);
  133.                 i++;
  134.             }
  135.         }
  136.  
  137.         public void UpdateTheListOfCharacters()
  138.         {
  139. //       TODO  //Clear the list of characters on the screen
  140. //         Root loadCurrentLoadPersonData = PersonDataSafeLoad.instance.LoadCurrentLoadPerson();
  141. // //        Debug.Log("PersonData UserInfo = " + loadCurrentLoadPersonData.data);
  142. //
  143. //         Debug.Log("LoadPersons UserAllData userAllData.UserPersons Count = " +
  144. //                   loadCurrentLoadPersonData.data.user_persons.Count);
  145. //         //  Debug.Log("LoaadPersonData LoadPersons UserAllData userAllData.UserPersons Count = " + loadCurrentLoadPersonData.data.user_persons.Count);
  146. //         int index = 1;
  147. //
  148. //         foreach (userGetdata.UserPerson userPerson in loadCurrentLoadPersonData.data.user_persons)
  149. //         {
  150. //             if (userPerson.person.unity_identify != null)
  151. //             {
  152. //                 GameObject scoreboardElement = scoreboardContent.transform.GetChild(index).gameObject;
  153. //                 scoreboardElement.GetComponent<ItemElement>().NewScoreElement(userPerson);
  154. //                 index++;
  155. //             }
  156. //         }
  157.         }
  158.     }
  159. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement