Beispiel #1
0
    void Awake()
    {
        //danan comment
        if (instance == null)
        {
            instance = this;
            DontDestroyOnLoad(gameObject); //Don't destroy the GameManager if it's not in the scene
        }
        else
        {
            Destroy(gameObject);
        }
        QuestionListData s = new QuestionListData();
        /* HARDCODED VERSION */
        //	s.questions = questionManager.questionSet.ToArray();
        /* */

        /* STREAMING ASSETS VERSION */
        string filePath = System.IO.Path.Combine(Application.streamingAssetsPath, "QuestionData.json");
        string result   = System.IO.File.ReadAllText(filePath);

        s = JsonUtility.FromJson <QuestionListData>(result);
        Debug.Log("RESULT: " + result);
        /* */

        /* RESOURCES VERSION */
        //	Object o = Resources.Load("Data/QuestionData");
        //  TextAsset data_resources = o as TextAsset;
        //	s = JsonUtility.FromJson<QuestionListData>(data_resources.text);
        /* */

        questionManager.questionSet = new List <Question>(s.questions);
    }
Beispiel #2
0
    public override bool Load()
    {
        QuestionList targetData = target as QuestionList;

        var    client = new DatabaseClient("", "");
        string error  = string.Empty;
        var    db     = client.GetDatabase(targetData.SheetName, ref error);
        var    table  = db.GetTable <QuestionListData>(targetData.WorksheetName) ?? db.CreateTable <QuestionListData>(targetData.WorksheetName);

        List <QuestionListData> myDataList = new List <QuestionListData>();

        var all = table.FindAll();

        foreach (var elem in all)
        {
            QuestionListData data = new QuestionListData();

            data = Cloner.DeepCopy <QuestionListData>(elem.Element);
            myDataList.Add(data);
        }

        targetData.dataArray = myDataList.ToArray();

        EditorUtility.SetDirty(targetData);
        AssetDatabase.SaveAssets();

        return(true);
    }