Created
January 28, 2025 06:38
-
-
Save baobao/bb2988bf7e5ecc1edc1115dcbe72d3e2 to your computer and use it in GitHub Desktop.
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; | |
// PlayableBehaviourを継承する | |
public class CustomPlayableBehaviour : PlayableBehaviour | |
{ | |
private float _direction = 1f; | |
public Transform target; | |
public override void ProcessFrame(Playable playable, FrameData info, object playerData) | |
{ | |
if (target != null) | |
{ | |
if (target.position.x >= 1f || target.position.x <= -1f) | |
{ | |
_direction *= -1f; | |
} | |
target.Translate(Vector3.right * info.deltaTime * _direction); | |
} | |
base.ProcessFrame(playable, info, playerData); | |
} | |
} |
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 CustomPlayableTest : MonoBehaviour | |
{ | |
private PlayableGraph _graph; | |
void Awake() | |
{ | |
// PlayableGraphの作成 | |
_graph = PlayableGraph.Create("CustomGraph"); | |
// Playableの作成 | |
var playable = ScriptPlayable<CustomPlayableBehaviour>.Create(_graph); | |
// PlayableBehaviourの取得 | |
var behaviour = playable.GetBehaviour(); | |
// PlayableBehaviourのセットアップ | |
behaviour.target = transform; | |
// PlayableOutputの作成 | |
var output = ScriptPlayableOutput.Create(_graph, "CustomOutput"); | |
// PlayableOutputにPlayableを接続 | |
output.SetSourcePlayable(playable); | |
// PlayableGraphを再生 | |
_graph.Play(); | |
} | |
void OnDestroy() | |
{ | |
// 使い終わったらPlayableGraphを破棄 | |
_graph.Destroy(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment