Last active
April 3, 2018 14:45
-
-
Save andybak/997aabc2dbb826c7d089cda413c1617d to your computer and use it in GitHub Desktop.
Simple Playable Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using UnityEngine.Playables; | |
public class ToggleComponentAsset : PlayableAsset { | |
public ExposedReference<MonoBehaviour> Component; | |
public bool EnabledOnStart; | |
public bool EnabledOnEnd; | |
public override Playable CreatePlayable(PlayableGraph graph, GameObject owner) { | |
var playable = ScriptPlayable<ToggleComponentPlayable>.Create(graph); | |
var toggleComponentPlayable = playable.GetBehaviour(); | |
var component = Component.Resolve(graph.GetResolver()); | |
toggleComponentPlayable.Initialize(component, EnabledOnStart, EnabledOnEnd); | |
return playable; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using UnityEngine.Playables; | |
public class ToggleComponentPlayable : PlayableBehaviour { | |
private MonoBehaviour _component; | |
private bool _enabledOnStart; | |
private bool _enabledOnEnd; | |
public void Initialize(MonoBehaviour component, bool enabledOnStart, bool enabledOnEnd) { | |
_component = component; | |
_enabledOnStart = enabledOnStart; | |
_enabledOnEnd = enabledOnEnd; | |
} | |
public override void OnBehaviourPlay(Playable playable, FrameData info) { | |
if (_component != null) { | |
_component.enabled = _enabledOnStart; | |
} | |
} | |
public override void OnBehaviourPause(Playable playable, FrameData info) { | |
if (_component != null) { | |
_component.enabled = _enabledOnEnd; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment