Unity Fungus 动态添加Command

代码动态添加Command

using Fungus;
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class StoryManager : MonoBehaviour
{
    private Flowchart flowchart;

    private void Start()
    {
        StartCoroutine(Globe.ReadStory(Globe.server_story, delegate (string[] array) {
            flowchart = this.gameObject.AddComponent<Flowchart>();

            Block block = flowchart.CreateBlock(Vector2.zero);
            block.BlockName = "StoryBlock";

            /*添加事件*/
            MessageReceived handle = this.gameObject.AddComponent<MessageReceived>();
            handle.SetMessage("msg");
            handle.ParentBlock = block;
            block._EventHandler = handle;

            foreach (string s in array)
            {
                /*添加Command*/
                Say say = this.gameObject.AddComponent<Say>();
                //block.GetFlowchart().AddSelectedCommand(say);
                say.ParentBlock = block;
                say.ItemId = flowchart.NextItemId();
                say.CommandIndex = block.CommandList.Count;
                say.OnCommandAdded(block);
                say.SetStandardText(s);

                block.CommandList.Add(say);
            }

            if (block.CommandList.Count > 0)
                flowchart.AddSelectedCommand(block.CommandList[0]);
            flowchart.AddSelectedBlock(block);
            //StartCoroutine(block.Execute(0, new Action(delegate () { Debug.Log("已完成"); })));
        }));
    }

    public void ButtonDown()
    {
        Flowchart.BroadcastFungusMessage("msg");
    }
}

当前使用的Fungus为官网最新的版本。Fungus官网

Globe.ReadStory是读取网络文本的方法;
handle.SetMessage("msg")是在MessageReceived类中自定义的一个方法。
say.CommandIndex = block.CommandList.Count;为了解决手机播放问题
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值