Unity插件Fungus自定义Command

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
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值