Created
February 7, 2022 05:34
-
-
Save Nobuyuki-Kobayashi/3bb6b6358a24e56af9f61112a1bd54ad to your computer and use it in GitHub Desktop.
複製したTimeline Assetにバインディング情報をコピーするコンポーネント
This file contains hidden or 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
// | |
// CopyTimelineBindings.cs | |
// https://forum.unity.com/threads/duplicating-a-timeline-loses-all-the-bindings-unity-v2017-2-0b6.488138/ | |
// | |
// How to use: | |
// | |
// 1. このスクリプトを、シーン内のPlayableDirectorコンポーネントがアタッチされているゲームオブジェクトにアタッチする。 | |
// 2. PlayableDirectorにアタッチされているTimeline Assetをプロジェクトウィンドウからデュプリケートする。 | |
// 3. CopyTimelineBindingsコンポーネント中の各スロットに以下のように、指定する | |
// * Timeline ComponentスロットにPlayableDirectorコンポーネントがアタッチされているゲームオブジェクトを指定する。 | |
// * Source Timelineスロットに元のTimeline Assetsを指定する。 | |
// * Target TimelineスロットにデュプリケートしたのTimeline Assetsを指定する。 | |
// 4. CopyTimelineBindingsコンポーネント上で右クリックメニューを出し、Copy Timeline Bindingsを実行する。 | |
// | |
// 1. Attach this script to a game object in your scene that has a PlayableDirector component attached to it. | |
// 2. Duplicate the Timeline Asset that are already attached from the project window. | |
// 3. Specify each slot in the CopyTimelineBindings component as follows | |
// * Specify the game object to which the PlayableDirector component is attached in the Timeline Component slot. | |
// * Specify the original timeline assets in the Source Timeline slot. | |
// * Specify the timeline assets that you have duplicated in the Target Timeline slot. | |
// 4. Right-click on the CopyTimelineBindings component and run Copy Timeline Bindings. | |
// | |
using UnityEngine; | |
using UnityEngine.Playables; | |
public class CopyTimelineBindings : MonoBehaviour | |
{ | |
[SerializeField] PlayableDirector timelineComponent; | |
[SerializeField] PlayableAsset sourceTimeline, targetTimeline; | |
[ContextMenu("Copy Timeline Bindings")] | |
public void CopyEachItemOfBindings() | |
{ | |
var oldBindings = sourceTimeline.outputs.GetEnumerator(); | |
var newBindings = targetTimeline.outputs.GetEnumerator(); | |
while (oldBindings.MoveNext()) | |
{ | |
var oldBindings_sourceObject = oldBindings.Current.sourceObject; | |
newBindings.MoveNext(); | |
var newBindings_sourceObject = newBindings.Current.sourceObject; | |
timelineComponent.SetGenericBinding( | |
newBindings_sourceObject, | |
timelineComponent.GetGenericBinding(oldBindings_sourceObject) | |
); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment