Unity Graph View打造图形化对话编辑系统(五)

Unity Graph View打造图形化对话编辑系统(五)——运行

目录

视频效果演示

Graph View打造图形化对话编辑系统效果展示

最终源码先附在此

点击此处下载源码


NPC Component

NPC组件,允许用户定义NPC头像,以及指定对话树文件。
事实上最关键的在于为DialogueTree和NodeBase添加节点运行(获取节点的对话数据)以及获取下一个节点的方法。然后用UI系统将节点数据呈现出来。

private void Update()
{
    
    
	if (DialogueSystem.IsRuning)
		return;

	if ( Input.GetMouseButtonDown(0))
	{
    
    
		if( Physics.Raycast(mainCamera.ScreenPointToRay(Input.mousePosition), out RaycastHit hit, 1000f, npcLayer ))
		{
    
    
			if( hit.collider.GetComponent<NPCDialogue>() == this )
			{
    
    
				DialogNodeBase node = dialogueTree.GetClickedNode();
				DialogueSystem.ShowDialogue(this, node);
			}
		}
	}
	else if( IsPlayerApproached)
	{
    
    
		if ((PlayerDialogue.position - transform.position).magnitude > 2f)
			IsPlayerApproached = false;
	}
	else
	{
    
    
		if((PlayerDialogue.position - transform.position ).magnitude < 1.5f )
		{
    
    
			IsPlayerApproached = true;
			DialogNodeBase node = dialogueTree.GetApproachedNode();
			DialogueSystem.ShowDialogue(this, node);
		}
	}
}

DialogueSystem

其实这个是一个单例模式的类,提供几个静态方法,以供在NPC组件中调用。这个类用于表现对话的UI逻辑,因此自定义的成分很大,用户可以将他定义成任何一种形式。这里不再进行探讨了。

猜你喜欢

转载自blog.csdn.net/sdhexu/article/details/123559497