SceneController.cs 909 Bytes
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
using UnityEngine;
using SimpleJSON;

namespace dlu
{

public class SceneController : MonoBehaviour
{
    public string json = "test";

    public void Start()
    {
        string jsonContent = Resources.Load<TextAsset>(json).text;
        // Debug.Log(JsonUtility.ToJson(GameObject.Find("Objects/cup").GetComponent<Entity>()));
        // List<Entity> scene = JsonConvert.DeserializeObject<List<Entity>>(jsonContent);
        JSONArray scene = JSON.Parse(jsonContent) as JSONArray;
        foreach (JSONObject obj in scene)
        {
            SetGameObjectState(obj);
        }
    }

    private void SetGameObjectState(JSONObject sceneObject)
    {
        string name = sceneObject["name"];
        // Debug.Log($"name {name}");
        GameObject go = GameObject.Find($"Objects/{name}");
        if (go != null) {
            // Debug.Log(go);
        }
    }
}

}