playMaker

Author Topic: Play Aperture Cutscene  (Read 5208 times)

elbows

  • Playmaker Newbie
  • *
  • Posts: 15
Play Aperture Cutscene
« on: February 18, 2012, 01:07:56 PM »
Hello,

This is an Action I quickly made for the Aperture Cutscene Editor which was released in the appstore recently.  Im not sure as its perfect as it was a bit of a quick hack based on the 'Play Animation' Action but its a reasonable start. If the author of Aperture Cutscene Editor adds some requests such as the ability to control the playback speed or playback position then I will update the action. I didn't get round to creating other actions such as a Stop Cutscene Playback one, but as you can probably see from the end of my code this should be really easy to achieve if needed.

Code: [Select]
using System;

using UnityEngine;

 

namespace HutongGames.PlayMaker.Actions

{

    [ActionCategory(ActionCategory.Animation)]

    [Tooltip("Plays an Aperture Cutscene on a Game Object.")]

    public class PlayApertureCutscene : FsmStateAction

    {

        [RequiredField]

        [CheckForComponent(typeof(Cutscene))]

        [Tooltip("Game Object which has a cutscene.")]

        public FsmOwnerDefault gameObject;

       

        [Tooltip("Event to send when the cutscene has finished playing. NOTE: Not sent with Loop mode!")]

        public FsmEvent finishEvent;

 

        [Tooltip("Event to send when the cutscene loops. If you want to send this event to another FSM use Set Event Target. NOTE: This event is only sent with Loop mode.")]

        public FsmEvent loopEvent;

 

        [Tooltip("Stop playing the cutscene when this state is exited.")]

        public bool stopOnExit;

       

        [Tooltip("Loop the cutscene.")]

        public bool loopCutscene;

       

        [Tooltip("Play the cutscene in reverse. Only works if the cutscene has already been played forwards by some amount.")]

        public bool reverseCutscene;

       

        public override void Reset()

        {

            gameObject = null;

            finishEvent = null;

            loopEvent = null;

            stopOnExit = false;

            loopCutscene = false;

            reverseCutscene = false;

        }

 

        public override void OnEnter()

        {

            DoPlayCutscene();

        }

 

        void DoPlayCutscene()

        {

            var go = Fsm.GetOwnerDefaultTarget(gameObject);

            if (go == null)

            {

                Finish();

                return;

            }

            Cutscene thecutscene = go.GetComponent<Cutscene>();

            if (thecutscene == null)

            {

                LogWarning("Missing cutscene component!");

                Finish();

                return;

            }

            if (loopCutscene)

            {

                thecutscene.loop = true;

            }

            else

            {   

                thecutscene.loop = false;

            }

            if (reverseCutscene)

            {

                thecutscene.Rewind();

            }

            else

            {   

                thecutscene.Play();

            }

           

           

        }

 

        public override void OnUpdate()

        {

            var go = Fsm.GetOwnerDefaultTarget(gameObject);

            if (go == null)

            {

                return;

            }

            Cutscene thecutscene = go.GetComponent<Cutscene>();

           

            if (thecutscene == null)

            {

                LogWarning("Missing cutscene component!");

                Finish();

                return;

            }

           

            if (!thecutscene.playing && !reverseCutscene)

            {

                Fsm.Event(finishEvent);

                Finish();

            }

           

            if (reverseCutscene && (thecutscene.totalPlays == 0))

            {

                Fsm.Event(finishEvent);

                Finish();

            }

            if (loopCutscene && (thecutscene.totalPlays > 1))

            {

                Fsm.Event(loopEvent);

            }

        }

 

        public override void OnExit()

        {

            if (stopOnExit)

            {

                StopCutscene();

            }

        }

 

        void StopCutscene()

        {

            var go = Fsm.GetOwnerDefaultTarget(gameObject);

            if (go != null)

            {   

                Cutscene thecutscene = go.GetComponent<Cutscene>();

                if (thecutscene !=null)

                {

                    thecutscene.Stop();

                }

            }

        }

    }

}

Lars Steenhoff

  • Beta Group
  • Playmaker Newbie
  • *
  • Posts: 46
Re: Play Aperture Cutscene
« Reply #1 on: July 09, 2012, 07:26:24 PM »
Really nice, I use aperture for a title screen animation loop and would like to trigger the aperture sequence to stop after clicking on a start GUI button, can you make a stop button for playmaker too ?

Many thanks

Lars Steenhoff

  • Beta Group
  • Playmaker Newbie
  • *
  • Posts: 46
Re: Play Aperture Cutscene
« Reply #2 on: July 14, 2012, 05:07:20 PM »
Does this work well or do I need to add something?


Code: [Select]

using UnityEngine;

namespace HutongGames.PlayMaker.Actions
{
[ActionCategory(ActionCategory.Animation)]
[Tooltip("Stops an Aperture Cutscene on a Game Object.")]
public class StopApertureCutscene : FsmStateAction
{
[RequiredField]
[CheckForComponent(typeof(Cutscene))]
[Tooltip("Game Object which has a cutscene.")]
public FsmOwnerDefault gameObject;

public override void Reset()
{
gameObject = null;
}

public override void OnEnter()
{
var go = Fsm.GetOwnerDefaultTarget(gameObject);
if (go != null)
{
Cutscene thecutscene = go.GetComponent<Cutscene>();
if (thecutscene !=null)
{
thecutscene.Stop();
}
}

Finish();
}
}
}