Unity对话插件Fungus自定义Command
Fungus
Fungus是一个通用对话插件,可以在你的游戏里很快实现一个自己的对话系统
Fungus自定义Command
某些时候,官方的Command不是很适合的时候就需要我们自己写Command
官方也给了对应的文档这里不过多介绍,给出模板
using UnityEngine;
using Fungus;
[CommandInfo("Other", //在command里面的分类
"ExampleCommand", //在面板里显示的名称
"Just an example.")] //说明
[AddComponentMenu("")]
public class ExampleCommand : Command
{
public override void OnEnter()
{
Debug.Log("Example command");
Continue();
}
}
自己写一个Block跳转Command
其实也是模板化套用,也可以去看文档
我这里直接给出模板
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Serialization;
namespace Fungus {
[CommandInfo("Custom",
"Execute Reference Block",
"Receive an object of type Block Reference and execute it.")]
public class executeReferenceBlock : Command, IBlockCaller
{
[Tooltip("the block")]
[SerializeField] protected BlockReference whichBlock; //用BlockReference的目的是为了在面板可以选择对应的Block
public override void OnEnter(){
if(whichBlock.block != null){
whichBlock.Execute();
}
Continue();
}
/// <summary>
/// 必要的实现
/// </summary>
public override void GetConnectedBlocks(ref List<Block> connectedBlocks)
{
if (whichBlock.block != null)
{
connectedBlocks.Add(whichBlock.block);
}
}
/// <summary>
/// 主要用来实现面板里的连线
/// </summary>
public bool MayCallBlock(Block block){
return block == whichBlock.block;
}
}
}
使用中遇到的小坑
- 一个文件里最好一个Command,并且Command的类名要和文件名一致。
比如创建了GetPlayer.cs
,那你GetPlayer.cs
里就最好只有public class GetPlayer : Command