Advertisement
Eiromplays

LoadingProfiles

Sep 24th, 2019
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.91 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. using UnityEngine.SceneManagement;
  6.  
  7. public class LoadProfiles : MonoBehaviour
  8. {
  9.     public int ProfileID;
  10.     public int ProfileImage;
  11.     public string ProfileName;
  12.     public string CompanyName;
  13.  
  14.     //For UI
  15.     public GameObject ProfilesUI;
  16.     public GameObject wheretomaketheprofileUI;
  17.     GameObject ProfilesUIClone;
  18.     public Text Name;
  19.     public Text Company;
  20.     public Image img;
  21.  
  22.     //List for saving so you can save more.
  23.     static List<ProfileData> profileData = new List<ProfileData>();
  24.  
  25.     public void Start()
  26.     {
  27.         if(profileData == null)
  28.         {
  29.             Debug.Log("You got no profiles created!");
  30.             //SceneManager.LoadScene("CreateProfile");
  31.             profileData = new List<ProfileData>();
  32.         }
  33.         else
  34.         {
  35.             if (!System.IO.Directory.Exists(Application.persistentDataPath + "/Profiles"))
  36.             {
  37.                 System.IO.Directory.CreateDirectory(Application.persistentDataPath + "/Profiles");
  38.             }
  39.             if (!System.IO.File.Exists(Application.persistentDataPath + "/Profiles/profiles.dat"))
  40.             {
  41.                 System.IO.File.Create(Application.persistentDataPath + "/Profiles/profiles.dat");
  42.             }
  43.             profileData = SaveProfile.LoadProfiles();
  44.  
  45.             for (int i = 0; i < profileData.Count; i++)
  46.             {
  47.                 ProfileName = profileData[i].profileName;
  48.                 CompanyName = profileData[i].companyName;
  49.                 ProfileImage = profileData[i].profileImage;
  50.                 ProfileID = profileData[i].profileID;
  51.  
  52.                 ProfilesUIClone = Instantiate(ProfilesUI) as GameObject;
  53.                 ProfilesUIClone.transform.SetParent(wheretomaketheprofileUI.transform.parent);
  54.                 Name = ProfilesUIClone.transform.Find("Name").GetComponentInChildren<Text>();
  55.                 Company = ProfilesUIClone.transform.Find("Company").GetComponentInChildren<Text>();
  56.                 Name.text = ProfileName;
  57.                 Company.text = CompanyName;
  58.                 ProfilesUIClone.SetActive(true);
  59.                 if (ProfileImage == 0)
  60.                 {
  61.                     img = ProfilesUIClone.transform.Find("ProfileImage1").GetComponent<Image>();
  62.                     img.gameObject.SetActive(true);
  63.                 }
  64.                 else if (ProfileImage == 1)
  65.                 {
  66.                     img = ProfilesUIClone.transform.Find("ProfileImage2").GetComponent<Image>();
  67.                     img.gameObject.SetActive(true);
  68.                 }
  69.                 else if (ProfileImage == 2)
  70.                 {
  71.                     img = ProfilesUIClone.transform.Find("ProfileImage3").GetComponent<Image>();
  72.                     img.gameObject.SetActive(true);
  73.                 }
  74.             }
  75.         }
  76.        
  77.         /*ProfilesUIClone = Instantiate(ProfilesUI) as GameObject;
  78.         ProfilesUIClone.transform.SetParent(wheretomaketheprofileUI.transform.parent);
  79.         Name = ProfilesUIClone.transform.Find("Name").GetComponentInChildren<Text>();
  80.         Company = ProfilesUIClone.transform.Find("Company").GetComponentInChildren<Text>();
  81.         Name.text = ProfileName;
  82.         Company.text = CompanyName;
  83.         ProfilesUIClone.SetActive(true);
  84.         if (ProfileImage == 0)
  85.         {
  86.             img = ProfilesUIClone.transform.Find("ProfileImage1").GetComponent<Image>();
  87.             img.gameObject.SetActive(true);
  88.         }
  89.         else if (ProfileImage == 1)
  90.         {
  91.             img = ProfilesUIClone.transform.Find("ProfileImage2").GetComponent<Image>();
  92.             img.gameObject.SetActive(true);
  93.         }
  94.         else if (ProfileImage == 2)
  95.         {
  96.             img = ProfilesUIClone.transform.Find("ProfileImage3").GetComponent<Image>();
  97.             img.gameObject.SetActive(true);
  98.         }
  99.     */}
  100. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement