bate's blog

調べたこと実装したことなどを取りとめもなく書きます。

シーケンス

シーケンスを実装してみた。
lightmapを選ぶ

移動対象(キューブ)選択

移動先選択

移動

移動対象(キューブ)選択

・・・

https://dl.dropbox.com/u/67579260/Unity/Test03/WebPlayer/WebPlayer.html


シーケンスのenum

public enum eSequenceType {
	SelectIcon,
	SelectGoal,
	Move,
	Max,
}

シーケンス制御
MonoBehaviourのUpdateをエントリーとして使うだけ

 public void Update() {
 	m_SequenceList[(int)m_Data.State].Update();
 }


インターフェイス
実際のシーケンスはMonoBehaviourを継承しない

using UnityEngine;
using System.Collections;

public abstract class InterfaceSequence {
	
	protected DataSet refData = null;
	protected bool isOnce = false;
	
	public InterfaceSequence(DataSet data) {
		refData = data;
	}
	
	// Update is called once per frame
	public abstract void Update ();
	
	public abstract void OnGUI ();
}

実際のシーケンス
Exitで次のシーケンスに移動
refData.State = eSequenceType.SelectGoal;
後は同じような感じで次の処理を作る

using UnityEngine;
using System.Collections;

public class SelectIconSequence : InterfaceSequence {
	
	public SelectIconSequence(DataSet data)
		: base(data)
	{
	}

	// Use this for initialization
	void Start () {
	
	}
	
	void Exit() {
		isOnce = false;
		refData.State = eSequenceType.SelectGoal;
	}
	
	// Update is called once per frame
	public override void Update () {
		if(!isOnce) {
			Start();
			isOnce = true;
			return;
		}
		
		GameObject obj = Select();
		if(obj != null) {
			Exit();
		}
	}
	
	public override void OnGUI() {
	}
	
	GameObject Select() {
		Vector3 tapPos = Vector3.zero;
		if(InputManager.Instance.Tap(ref tapPos)) {
			Debug.Log("Select");
			Ray ray = Camera.main.ScreenPointToRay(tapPos);
			RaycastHit hit;
			if(Physics.Raycast(ray, out hit, Mathf.Infinity, 1<<LayerMask.NameToLayer("MapIcon"))) {
				GameObject obj = hit.collider.gameObject;
				if(obj) {
					obj.renderer.material.color = Color.red;
					int idx = obj.GetComponent<GridNodeIndex>().m_Index;
					refData.Start = refData.GridNodeList[idx];
					refData.SelectIcon = obj;
					return obj;
				}
			}
		}
		return null;
	}
}