Playmaker Forum

PlayMaker Help & Tips => PlayMaker Help => Topic started by: tomraegan on August 18, 2018, 03:25:37 PM

Title: Timeline Set Duration
Post by: tomraegan on August 18, 2018, 03:25:37 PM
Hi!

https://hutonggames.com/playmakerforum/index.php?topic=15465.15

This thread contains Timeline actions. It includes a Get Duration, which grabs the duration of the timeline without an issue. I want to change the duration of the timeline and then Set Duration. Set Duration does not yet exist as an action.

I was wondering if someone could help me by creating a Set Duration?

Here is the code for Get Duration:

Code: [Select]
// (c) Copyright HutongGames, LLC 2010-2017. All rights reserved.
/*--- __ECO__ __PLAYMAKER__ __ACTION__ ---*/

using System;
using UnityEngine;
using UnityEngine.Playables;

namespace HutongGames.PlayMaker.Actions
{
[ActionCategory("Timeline")]
[Tooltip("Get the current timelines duration. This action requires Unity 2017.1 or above.")]

public class  getTimelineDuration : FsmStateAction
{
[RequiredField]
[CheckForComponent(typeof(PlayableDirector))]
[Tooltip("The game object to hold the unity timeline components.")]
public FsmOwnerDefault gameObject;

[Tooltip("Returns the current timeline duration in seconds as a float.")]
[UIHint(UIHint.Variable)]
public FsmFloat duration;
private double _duration;

[Tooltip("Check this box to preform this action every frame.")]
public FsmBool everyFrame;

private PlayableDirector timeline;

public override void Reset()
{

gameObject = null;
everyFrame = false;
duration = null;
}

public override void OnEnter()
{
var go = Fsm.GetOwnerDefaultTarget(gameObject);
timeline = go.GetComponent<PlayableDirector>();

timelineAction();

if (!everyFrame.Value)
{
Finish();
}

}

public override void OnUpdate()
{

timelineAction();

}

void timelineAction()
{
var go = Fsm.GetOwnerDefaultTarget(gameObject);
if (go == null || timeline == null)
{
return;
}

_duration = timeline.duration;
duration.Value = (float)_duration;
}

}
}

Thanks!
Title: Re: Timeline Set Duration
Post by: jeanfabre on August 20, 2018, 12:10:48 AM
Hi,

 The timeline duration is a get only, you can not set it.

 What are you trying to achieve?

 Bye,

 Jean
Title: Re: Timeline Set Duration
Post by: tomraegan on August 21, 2018, 02:18:58 AM
Thanks for the reply, jeanfabre. I rely heavily on your support of these forums.

I'm trying to set the speed of the timeline, replicating what I believe (but am not sure of) is contained inside this line of code:

Code: [Select]
playableDirector.playableGraph.GetRootPlayable(0).SetSpeed
My goal is to be able to increase and decrease the speed at which timelines play in realtime.
Title: Re: Timeline Set Duration
Post by: jeanfabre on August 22, 2018, 02:31:46 AM
Hi,

 that's ok, I am here for that :)

I have pushed a new action on the Ecosystem called SetPlayableSpeed

It works on my tests, let me know if all is well on your end.


 Bye,

Jean


Title: Re: Timeline Set Duration
Post by: tomraegan on August 22, 2018, 02:43:27 PM
Hi,

 that's ok, I am here for that :)

I have pushed a new action on the Ecosystem called SetPlayableSpeed

It works on my tests, let me know if all is well on your end.


 Bye,

Jean




Works perfectly.

Thanks kindly. Such great support on these boards.