Executing from script

Announcements, support questions, and discussion for the Dialogue System.
OldNoob
Posts: 7
Joined: Sun Jul 15, 2018 4:10 pm

Executing from script

Post by OldNoob »

Hello,

I'm trying to use trial version and instead of using unity editor I like to use scripting for cutscenes dialogs.

Is there any complete example. I see some examples however I did not found any suitable examples.

my current setup was based on Adventure Creator and I think DS was more suitable my needs and I want to make sure I can use from scripting. (from my point of view altering large sequences in visual editor was painful)

Here for short example. I had lots of those files. (my game a kind of visual novel, there where lots of dialogs and camera works.)

Code: Select all

using AC;
using UnityEngine;
using System.Collections;


public class dialogue_NewGame_PartOne : MonoBehaviour {

	
	public Marker Camera_A_POS_A;
	public Marker Camera_A_POS_B;
	
	public Marker Cam_B_Start;
	public Marker Camera_B_POS_A;
	public Marker Camera_B_POS_B;	

	public Marker Aldo_Start;
	public Marker Lucy_Start;
	public Marker Richardo_Start;
	public Marker Richardo_POS_B;
	
	public NPC Richard;
	public NPC Lucy;

	private _Camera _camA;
	private _Camera _camB;
	
	public void DialogueStart()
	{
		// Start Dialog CoRoutine
		_camA = GameObject.Find("GameCamera_A").GetComponent<_Camera>();
		_camB = GameObject.Find("GameCamera_B").GetComponent<_Camera>();

		cameraStartPosition();
		
		StartCoroutine (Coroutine_Dialogue_NewGame ());
	}
	
	private IEnumerator Coroutine_Dialogue_NewGame ()
	{
		KickStarter.player.Teleport(Aldo_Start.transform.position);
		Richard.Teleport(Richardo_Start.transform.position);
		Lucy.Teleport(Lucy_Start.transform.position);

		KickStarter.stateHandler.StartCutscene ();
	
		KickStarter.dialog.StartDialog (Richard, "And you will spend a month in here, because of your new school. Is that so Aldo", false, -1);
		while (Richard.isTalking)
		{
			yield return new WaitForFixedUpdate ();
		}
	
		KickStarter.dialog.StartDialog (KickStarter.player, "Yes Mr.Rivera", false, -1);
		while (KickStarter.player.isTalking)
		{
			yield return new WaitForFixedUpdate ();
		}

		_camA.transform.position = Camera_A_POS_A.transform.position;
		_camA.transform.rotation = Camera_A_POS_A.transform.rotation;

		KickStarter.mainCamera.Crossfade(0.1f,_camA);
		KickStarter.mainCamera.SetGameCamera(_camA,0f);

		KickStarter.dialog.StartDialog (Lucy, "Good, it has quite while since we got any visitors isn't it Richard", false, -1);
		while (Lucy.isTalking)
		{
			yield return new WaitForFixedUpdate ();
		}

		
		KickStarter.stateHandler.EndCutscene ();
		
		__App.Game.State.SetIntro(1);
		GameObject fsm = GameObject.Find("Scene_FiniteStateMachine");
		fsm.SendMessage("InitScene");
	}
	
	private void cameraStartPosition()
	{
		_camB.transform.position = Cam_B_Start.transform.position;
		_camB.transform.rotation = Cam_B_Start.transform.rotation;

		KickStarter.mainCamera.Crossfade(0.1f,_camB);
		KickStarter.mainCamera.SetGameCamera(_camB,0f);		
	}	
}
In short I had tons of blabla and camera here npc there and I want to do it from C#. Can DS do this ? if so is there any complete example.

My Humble regards
User avatar
Tony Li
Posts: 22085
Joined: Thu Jul 18, 2013 1:27 pm

Re: Executing from script

Post by Tony Li »

It's possible, but I don't think the Dialogue System is the best tool for that.

However, the Dialogue System embraces a similar philosphy. You can script the cutscenes for all dialogue entry nodes, with purpose-built commands that make the code shorter than C#. For future readers who don't use Adventure Creator (AC), I'll first provide a non-AC example of what I mean:

Image

Each node has a Sequence field that contains a short script of sequencer commands. You can also define your own sequencer commands in C# scripts.

The first Sequence script shown above is:

Code: Select all

MoveTo(Aldo_Start, Aldo);
MoveTo(Richard_Start, Richard);
MoveTo(Lucy_Start, Lucy);
AudioWait(entrytag)
It moves the characters to their positions and plays an audio clip, waiting until the audio clip is done. I've used the special keyword 'entrytag', but you could just as easily use a similar AC-specific sequencer command to play a line of dialogue through AC:

Code: Select all

ACSpeech(Richard42)
The Dialogue System's AC Support package provides some AC-specific sequencer commands so you don't have to write them yourself in C#. For example, to crossfade to Camera_A over 0.1 seconds:

Code: Select all

ACCam(Camera_A, 0.1)
So you could set Lucy's Sequence (the last node of the conversation) to:

Code: Select all

ACCam(Camera_A, 0.1);
ACSpeech(entrytag)->Message(DoneTalking);
SendMessage(InitScene,,Scene_FiniteStateMachine)@Message(DoneTalking)
The last command, SendMessage(), is basically equivalent to your C# code:

Code: Select all

GameObject fsm = GameObject.Find("Scene_FiniteStateMachine");
fsm.SendMessage("InitScene");
The middle command (ACSpeech) sends a sequencer message "DoneTalking" when it's done. The last command doesn't run until the sequencer receives this message.


If you want to write the entire conversation in a single text file, you can use the JLC Converter on the Dialogue System Extras page, or Ink Support.


Finally, it's possible to do this all in C#, but you'll bypass a lot of the benefits of the Dialogue System. To run a conversation, you'd need to manually open the dialogue UI:

Code: Select all

DialogueManager.dialogueUI.Open();
and then manually create Subtitle objects and pass them to ShowSubtitle & HideSubtitle:

Code: Select all

var subtitle = new Subtitle(...); // parameters omitted from this example.
DialogueManager.dialogueUI.ShowSubtitle(subtitle);
...
DialogueManager.dialogueUI.HideSubtitle(subtitle);
and do the same for showing response menus. You'll want to set the subtitle's Sequence to a dummy command that makes it stay onscreen until you manually hide it using HideSubtitle, such as "WaitForMessage(Forever)".
OldNoob
Posts: 7
Joined: Sun Jul 15, 2018 4:10 pm

Re: Executing from script

Post by OldNoob »

Hello,

Thanks for reply. I give try.

I'm planning to move from AC to DS or any suitable system. Also with latest Unity with Latest AC things get outof control. I lost my confidence.

Anyway.

My problem with visual systems when things get bigger, managing and debugging gets harder.

I'm using same scenes with multiple states.

Like if variable this a and variable that 2 execute converstation_b

And using multiple functions not problem. If I understood them correctly I can easly write wrapper functions for single liners.

My humble regards.
User avatar
Tony Li
Posts: 22085
Joined: Thu Jul 18, 2013 1:27 pm

Re: Executing from script

Post by Tony Li »

OldNoob wrote: Mon Jul 16, 2018 1:35 amMy problem with visual systems when things get bigger, managing and debugging gets harder.
I understand your point. The Dialogue System is still primarily a visual system, but it's designed to support large commercial games, so it includes a lot of features to make it easier to manage. You may still find that it's not the right fit for your needs. If you have more questions about that, just let me know.
OldNoob wrote: Mon Jul 16, 2018 1:35 am I'm using same scenes with multiple states.

Like if variable this a and variable that 2 execute converstation_b

And using multiple functions not problem. If I understood them correctly I can easly write wrapper functions for single liners.
Yes. You'll also want to be familiar with the DialogueLua class, and Logic & Lua in the Dialogue System in general. I think you'll like it. Since it runs a scripting environment under the hood, it's nice for programmers to use. You can just bypass a lot of the visual features that make it easy for devs who don't want to deal with programming.
OldNoob
Posts: 7
Joined: Sun Jul 15, 2018 4:10 pm

Re: Executing from script

Post by OldNoob »

Hello again.

Many thanks for information.

I believe, visual front end was main point of your product. For nonprogrammers it was necessity and for larger teams nobody employ a programmer for dialogue management.

And I had some programming experience and feel confident with text editors.

Also I do not have formal english and programming education. You documentation was so wast (probably one of the best for an unity asset) and I'm not sure I can extract necessary info whithout an example.

I'm a find examples, play, broke, fix then extend it guy.

Can you point me a piece of code which contains similar contents which I add the first post.

My humble regards.
User avatar
Tony Li
Posts: 22085
Joined: Thu Jul 18, 2013 1:27 pm

Re: Executing from script

Post by Tony Li »

OldNoob
Posts: 7
Joined: Sun Jul 15, 2018 4:10 pm

Re: Executing from script

Post by OldNoob »

Wow...

An example from ground up for a uncertain customer.

Man I hope you payed well...

I been in this business more than 30 years and done tons of this or that (from Oracle to Cisco).

This was my best customer support I ever get.

I'm speechless.

My humble regards.
User avatar
Tony Li
Posts: 22085
Joined: Thu Jul 18, 2013 1:27 pm

Re: Executing from script

Post by Tony Li »

Glad to help. It didn't take long to put together. Don't feel obligated to use Dialogue System, though. I happen to think it's pretty good ;) , but it still might not be the best fit if you're going to code everything in script.
OldNoob
Posts: 7
Joined: Sun Jul 15, 2018 4:10 pm

Re: Executing from script

Post by OldNoob »

Hello Again.

Let say, 20 years ago, when I'm building 30 node wan with voip support using with latest Cisco equipment plus with 10.000 usd support package. It was like hell. Every day and nigh I'm battling against Cisco hq in belguim with my crappy english to find solutions for alpha quality software after 3 months plus thousant dolars of memory upgrade (from 32 to 64 mb) it was barelly working and that was different universe.

I respect your working ethics.

Anyway with your help plus your menu framework I setup my game with DS and my assets. Everything was running however I had some questions.

It seem DS required default camera state or planned to be follow player in all time except camera commands in squence.

However my game was Visual Novel. Noting was animated, player does not need move in scene. Maybe short default idle animation thats it. Face expressions from shapekeys and other animations are one frame poses.

I want to cross fade between cameras and when I cross fade a camera I wish to stay camera here.

Like movies.
Closeup to char A say something then Closeup to Player say something then crossfade to general view to say some more lines.

And in my test runs camera always back to default position.
  • Is there any way to Crossfade between cameras and make last camera default.
  • Can I use (and save) Json or is there any way to group related variables
  • Can I use bark baloons as dialogue baloons.
  • There was a continue option for conversations and our target group likes to mouse click to next line. Is there any way to wait conversation line to mouse click. (anywhere in the script unless something clickable)
Thanks for assistance.

My Humble Regards.
User avatar
Tony Li
Posts: 22085
Joined: Thu Jul 18, 2013 1:27 pm

Re: Executing from script

Post by Tony Li »

Hi,
OldNoob wrote: Tue Jul 17, 2018 3:46 pmIs there any way to Crossfade between cameras and make last camera default.
Yes. Don't use the Camera() command. The Dialogue System will only take control of the camera if you use the Camera() command. Instead, write a custom sequencer command to crossfade your cameras. Custom sequencer commands are easy to write. The Dialogue System includes a starter template script in the Templates / Scripts folder.
OldNoob wrote: Tue Jul 17, 2018 3:46 pmCan I use (and save) Json or is there any way to group related variables
Yes. Use the Save System. To do this, add a Save System component to the Dialogue Manager GameObject. To get the JSON of the Dialogue System's current state, including variable values:

Code: Select all

using PixelCrushers;
...
string json = SaveSystem.Serialize(SaveSystem.RecordSavedGameData());
To restore a saved JSON string back into the Dialogue System:

Code: Select all

SaveSystem.ApplySavedGameData(SaveSystem.Deserialize<SavedGameData>(json));
OldNoob wrote: Tue Jul 17, 2018 3:46 pmCan I use bark baloons as dialogue baloons.
You can use dialogue balloons. Add a Dialogue Actor component to the NPC. Set Dialogue UI Settings > Subtitle Panel Number to Custom. Assign Plugins / Pixel Crushers / Dialogue System / Prefabs / Standard UI Prefabs / Templates / Bubble / Bubble Template Standard UI Subtitle Panel to the Custom Subtitle Panel field. You can make a custom copy of this prefab and add it as a child of the character's GameObject if you prefer.
OldNoob wrote: Tue Jul 17, 2018 3:46 pmThere was a continue option for conversations and our target group likes to mouse click to next line. Is there any way to wait conversation line to mouse click. (anywhere in the script unless something clickable)
Set the Dialogue Manager's Subtitle Settings > Continue Button mode to Always. Then configure your continue button to cover the whole screen, and set its image's Alpha to 0 to make it invisible.

Examine the Basic Standard Dialogue UI's continue button. It has a component called Standard UI Continue Button Fast Forward. The button's OnClick() event calls this component's OnFastForward() method. OnFastForward() checks the subtitle's typewriter effect. If the typewriter is still typing, it skips to the end of the text. If the typewriter is done typing, it actually continues to the next line. You may want to use this component.
Post Reply