Executing from script

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

Re: Executing from script

Post by OldNoob »

Awesome.

I'll try today.

Also

I start try to learn Unity probably six months ago. Last six month was constat uphill battle which I begin to tire out.

Thanks for support.

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

Re: Executing from script

Post by Tony Li »

Sounds good. If you have any questions, just let me know. Unity is a big system. It takes a while to learn, especially the programming side.
OldNoob
Posts: 7
Joined: Sun Jul 15, 2018 4:10 pm

Re: Executing from script

Post by OldNoob »

Okay I do the camera change.

It works with camera and empty game object.

Create a camera. name CamA
Create a empty GameObject name CamA_Start

While you selected the CamA_Start on hieracy On scene move to your view to your desired camera position then hit ctrl + shift + f

then use in your sequence like
CameraCrossfade(CamA,CamA_Start);

Code: Select all

using UnityEngine;
using System.Collections;
using PixelCrushers.DialogueSystem;

namespace PixelCrushers.DialogueSystem.SequencerCommands
{
    public class SequencerCommandCameraCrossfade : SequencerCommand
    {
        public void Start()
        {
            string targetCamera = GetParameter(0);
            string targetMark = GetParameter(1);

            if (string.IsNullOrEmpty(targetCamera)) {
                Debug.LogError("target camera is null");
                Stop();
            }

            if (string.IsNullOrEmpty(targetMark)) {
                Debug.LogError("target mark is null");
                Stop();
            }
            
            Camera tCam = GameObject.Find(targetCamera).GetComponent<Camera>();
            GameObject tMark = GameObject.Find(targetMark);

            tCam.transform.position = tMark.transform.position;
            tCam.transform.rotation = tMark.transform.rotation;

            DialogueManager.DisplaySettings.cameraSettings.sequencerCamera = tCam;
            
            Stop();           
        }

        public void OnDestroy()
        {
            // Add your finalization code here. This is critical. If the sequence is cancelled and this
            // command is marked as "required", then only Start() and OnDestroy() will be called.
            // Use it to clean up whatever needs cleaning at the end of the sequencer command.
            // If you don't need to do anything at the end, you can delete this method.
        }

    }
}
And I did not found any info about where to put this script ? And I put in Menu Framework Sequence Commands dir.

My Best Regards
User avatar
Tony Li
Posts: 22189
Joined: Thu Jul 18, 2013 1:27 pm

Re: Executing from script

Post by Tony Li »

Hi,

The script can be anywhere in your project, except don't put it inside a folder named 'Editor'. (Scripts inside 'Editor' folders are not included in builds.)

If you want to avoid the overhead of GameObject.Find(), you can change this:

Code: Select all

string targetCamera = GetParameter(0);
string targetMark = GetParameter(1);
to:

Code: Select all

Transform targetCamera = GetSubject(0);
Transform targetMark = GetSubject(1);
Then you can work with the transform without having to find it. The full API reference for SequencerCommand is here.

You don't need this line:

Code: Select all

DialogueManager.DisplaySettings.cameraSettings.sequencerCamera = tCam;
It may cause problems. Your command should bypass the Dialogue System's camera controls entirely, so you don't need to set sequencerCamera.
Post Reply