Unity Graph View creates a graphical dialogue editing system (5)

Unity Graph View to create a graphical dialogue editing system (5) - run

Table of contents

Video Effect Demonstration

Graph View creates a graphical dialogue editing system effect display

The final source code is attached here

Click here to download the source code


NPC Component

The NPC component allows users to define NPC avatars and specify dialogue tree files.
In fact, the most critical thing is to add node operation (get the dialogue data of the node) and the method of getting the next node to DialogueTree and NodeBase. Then use the UI system to present the node data.

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

In fact, this is a singleton class that provides several static methods for calling in NPC components. This class is used to express the UI logic of the dialog, so the customization is very large, and the user can define it in any form. It is no longer discussed here.

Guess you like

Origin blog.csdn.net/sdhexu/article/details/123559497