Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
親オブジェクトを切り替える(ついでに座標を(0, 0, 0)に変更)
using System;
using UnityEngine;
using UnityEngine.Playables;
using UnityEngine.Timeline;
[Serializable]
public class TransformParentBehaviour : PlayableBehaviour
{
public Transform parent;
}
using System;
using UnityEngine;
using UnityEngine.Playables;
using UnityEngine.Timeline;
[Serializable]
public class TransformParentClip : PlayableAsset, ITimelineClipAsset
{
public ExposedReference<Transform> parent;
public ClipCaps clipCaps
{
get { return ClipCaps.None; }
}
public override Playable CreatePlayable (PlayableGraph graph, GameObject owner)
{
var playable = ScriptPlayable<TransformParentBehaviour>.Create (graph);
TransformParentBehaviour clone = playable.GetBehaviour ();
clone.parent = parent.Resolve (graph.GetResolver ());
return playable;
}
}
using System;
using UnityEngine;
using UnityEngine.Playables;
using UnityEngine.Timeline;
public class TransformParentMixerBehaviour : PlayableBehaviour
{
public Transform trackBinding;
private Transform _parent;
private Vector3 _localPosition;
private Quaternion _localRotation;
private Transform preTransform = null;
public override void OnBehaviourPlay(Playable playable, FrameData info)
{
if (!trackBinding)
return;
_parent = trackBinding.parent;
_localPosition = trackBinding.localPosition;
_localRotation = trackBinding.localRotation;
}
public override void OnBehaviourPause(Playable playable, FrameData info)
{
trackBinding.parent = _parent;
trackBinding.localPosition = _localPosition;
trackBinding.localRotation = _localRotation;
}
public override void ProcessFrame(Playable playable, FrameData info, object playerData)
{
if (!trackBinding)
return;
int inputCount = playable.GetInputCount ();
Transform target = _parent;
for (int i = 0; i < inputCount; i++)
{
float inputWeight = playable.GetInputWeight(i);
if( inputWeight > 0)
{
ScriptPlayable<TransformParentBehaviour> inputPlayable = (ScriptPlayable<TransformParentBehaviour>)playable.GetInput(i);
TransformParentBehaviour input = inputPlayable.GetBehaviour();
target = input.parent;
break;
}else{
continue;
}
}
if( !object.ReferenceEquals(preTransform, target))
{
preTransform = target;
trackBinding.parent = target;
trackBinding.localPosition = Vector3.zero;
trackBinding.localRotation = Quaternion.identity;
}
}
}
using UnityEngine;
using UnityEngine.Playables;
using UnityEngine.Timeline;
[TrackColor(0.7692571f, 0.4438857f, 0.990566f)]
[TrackClipType(typeof(TransformParentClip))]
[TrackBindingType(typeof(Transform))]
public class TransformParentTrack : TrackAsset
{
public override Playable CreateTrackMixer(PlayableGraph graph, GameObject go, int inputCount)
{
var playable = ScriptPlayable<TransformParentMixerBehaviour>.Create(graph, inputCount);
var trackBinding = go.GetComponent<PlayableDirector>().GetGenericBinding(this) as Transform;
playable.GetBehaviour().trackBinding = trackBinding;
return playable;
}
}
@tsubaki

This comment has been minimized.

Copy link
Owner Author

commented Aug 26, 2018

親子関係を変更するとGatherPropertiesだと何故か上手くいかないので、値を明示的に保持する

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.