view Assets/Application/Scripts/SaveData.cs @ 4:2878be4487ec

add Maping Code.
author Kazuma
date Tue, 08 Nov 2016 17:07:48 +0900
parents e5ef0342d00b
children 12f4f937da7f
line wrap: on
line source

using UnityEngine;
using System.Collections;

public class SaveData : MonoBehaviour {

	public static SaveData Instance;

	private Jungle mainScene ;
	private JungleTree mainTree;
	private JungleTreeEditor TreeEditor;
	private TreeNode node;
	// Use this for initialization
	void Awake () {
		if (Instance == null) {
			Instance = this;
		}
	}

	private void Start () {
		JungleStart ();
	}

	private void JungleStart () {
		Debug.Log ("[Jungle] Start ...");
		mainScene = new DefaultJungle(null, "Main", new DefaultTreeEditor(new DefaultTraverser()));
	}

	public void CreateTree (string name) {
		mainTree = mainScene.createNewTree (name);
		Debug.Log ("[Jungle] Create " + name + " Tree");
		EditorMode ();
	}

	public void EditorMode () { 
		TreeEditor = mainTree.getTreeEditor ();
		Debug.Log ("[Jungle] Editor Mode" + TreeEditor.ToString());
	}

	public void PutAttribute (NodePath path, string key, byte[] value) {
		Either<Error, JungleTreeEditor> either = TreeEditor.putAttribute (path, key, value);
		if (either.isA ()) {
			Debug.LogError ("[Error]" + either.a());
		} else {
			Debug.Log ("[Success]");
			either.b ();
		}
	}

	public void GetAttribute (NodePath path, string key) {
		node = mainTree.getNodeOfPath (path).b ();
		byte[] target = node.getAttributes ().get (key);
		var obj = ConvertObject.UnConvert (target);
		print (obj);
	}
 
	public void Push() {
		Either<Error, JungleTreeEditor> r = TreeEditor.success();
		if (!r.isA ()) {
			Debug.LogError ("[Error]");
		} else {
			Debug.Log ("[Success]");
			TreeEditor = r.b ();
		}
	}
}