view Assets/Application/Scripts/Item.cs @ 12:b55d586dd4eb

change bind from fmap.
author Kazuma Takeda
date Tue, 07 Feb 2017 20:48:57 +0900
parents cf20add31466
children
line wrap: on
line source

´╗┐using UnityEngine;
using System.Collections;
using JungleDB;
using System.Text;
using System;

/// <summary>
/// Base Item Class.
/// </summary>
public class Item : MonoBehaviour {

	public string Type;
	public int indexID = 0;
	public int itemID = 1;

	public Jungle jungle;

	public void SetPosition (Vector3 pos) {
		this.transform.position = pos;
	}

	public virtual void Delete() {
		
	}

	public void DeleteTreeNode () {
		jungle = SaveData.jungle;
		JungleTree tree      = jungle.getTreeByName ("SceneTree");
		JungleTreeEditor edt = tree.getTreeEditor ();

		NodePath root        = new DefaultNodePath ();
		NodePath stagePath   = root.add (1);

		Either<Error, JungleTreeEditor> e = edt.deleteChildAt (stagePath, indexID);
		if (e.isA ()) {
			print ("[Error] Try again!");
			SetCreateTreeNode ();
		}
		edt = e.b ();
		edt.commit ();
	}


	public void SetCreateTreeNode () {
		jungle = SaveData.jungle;
		JungleTree tree      = jungle.getTreeByName ("SceneTree");
		JungleTreeEditor edt = tree.getTreeEditor ();

		NodePath root        = new DefaultNodePath ();
		NodePath stagePath   = root.add (1);
		edt                  = edt.addNewChildAt(stagePath, indexID).b();

		Either<Error, JungleTreeEditor> e = edt.putAttribute (stagePath.add (indexID), "Item_ID", Encoding.UTF8.GetBytes(itemID.ToString()));
		if (e.isA ()) {
			print ("[Error] Try again!");
			SetCreateTreeNode ();
		}
		edt = e.b ();
		edt.commit ();
	}
}