【Game Creator】変数やキャラをInspector項目に追加できるクラス【Unityアセット】

Game Creatorサムネ

Unityアセット「Game Creator」には自作Trigger・Condition・Actionをする際に利用できる、Inspectorで予め変数からの取得などを可能にした便利な拡張クラスが存在します。そのいくつかを紹介します。

Target Character

Game CreatorのCharacterクラス、及びCharacterクラスを継承しているキャラを取得します。

using GameCreator.Characters;

public TargetCharacter character = new TargetCharacter();

public override bool InstantExecute(GameObject target, IAction[] actions, int index)
{
	Character characterTarget = this.character.GetCharacter(target);
	if (characterTarget == null) return true;

	return true;
}
Game Creator Target Character1
Game Creator Target Character2

Target Game Object

ゲームオブジェクトを取得します。

public TargetGameObject instance = new TargetGameObject();

public override bool InstantExecute(GameObject target, IAction[] actions, int index)
{
	GameObject Target = this.instance.GetGameObject(target);
	if (Target == null) return true;

	return true;
}
Game Creator Target GameObject1
Game Creator Target GameObject2

Target Position

ポジションをVector3で取得します。

public TargetPosition position = new TargetPosition();

public override bool InstantExecute(GameObject target, IAction[] actions, int index)
{
	Vector3 Target = this.position.GetPosition(target);
	if (Target == null) return true;

	return true;
}
Game Creator Target Position1
Game Creator Target Position2

Target Direction

Direction(方向)をVector3で取得します。

public TargetDirection direction = new TargetDirection();

public override bool InstantExecute(GameObject target, IAction[] actions, int index)
{
	Vector3 Target = this.direction.GetDirection(target);
	if (Target == null) return true;

	return true;
}
Game Creator Target direction

変数と直接入力の混合

各種変数に格納可能な型や変数は、Inspectorからの直接入力、又は変数から選択することが可能なクラスが用意されています。それぞれGetValueで取得可能です。

BoolPropertyBool型
NumberPropertyFloat型
StringPropertyString型
Vector2PropertyVector2型
Vector3PropertyVector3型
ColorPropertyColor型
SpritePropertySprite型
Texture2DTexture2D型
GameObjectGameObject型
VariableProperty型は値による(型チェックが必要)
using GameCreator.Variables;
//~
//()の中に初期値を入れると、Inspectorの初期値になります。
public BoolProperty boolP = new BoolProperty(true);
public NumberProperty numP = new NumberProperty(5f);
public StringProperty stringP = new StringProperty("Hello");
public Vector2Property vec2P = new Vector2Property(Vector2.zero);
public Vector3Property vec3P = new Vector3Property(Vector3.zero);

public ColorProperty colorP = new ColorProperty();
public SpriteProperty spriteP = new SpriteProperty();
public Texture2DProperty texP = new Texture2DProperty();
public GameObjectProperty goP = new GameObjectProperty();

public VariableProperty vaP = new VariableProperty();

public override bool InstantExecute(GameObject target, IAction[] actions, int index)
{
	bool boolGet = this.boolP.GetValue(target);
	float numGet = this.numP.GetValue(target);
	string stringGet = this.stringP.GetValue(target);
	Vector2 vec2Get = this.vec2P.GetValue(target);
	Vector3 vec3Get = this.vec3P.GetValue(target);

	Color colorGet = this.colorP.GetValue(target);
	Sprite spGet = this.spriteP.GetValue(target);
	Texture2D texGet = this.texP.GetValue(target);
	GameObject goGet = this.goP.GetValue(target);

	var vaGet = this.vaP.Get(target);

	return true;
}
Game Creator Target Variable

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です

CAPTCHA