Advertisement
Guest User

Untitled

a guest
Nov 19th, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using System;
  5.  
  6. public class StaticData : MonoBehaviour
  7. {
  8.  
  9. public static string LoadResourceTextfile(string name)
  10. {
  11. string filePath = "JsonData/" + name;
  12. TextAsset targetFile = Resources.Load<TextAsset>(filePath);
  13. return targetFile.text;
  14. }
  15.  
  16. [Serializable]
  17. public class Planets
  18. {
  19. public List<PlayObject> list;
  20. }
  21.  
  22. public Planets planets;
  23.  
  24. public PlayObject GetPlanetByKeyName (string key_name)
  25. {
  26. foreach(var i in planets.list)
  27. {
  28. if(i.keyName == key_name)
  29. {
  30. return i;
  31. }
  32. }
  33. return null;
  34. }
  35.  
  36. void Awake()
  37. {
  38. string json;
  39. DontDestroyOnLoad(this.gameObject);
  40.  
  41. json = LoadResourceTextfile("Planets");
  42. json = "{\"list\":" + json + "}";
  43. planets = JsonUtility.FromJson<Planets>(json);
  44.  
  45. foreach(var i in planets.list)
  46. {
  47. i.Init();
  48. }
  49. }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement