浏览代码

DIrector Control Rig + Action

/main
Thomas ICHÉ 6 年前
当前提交
e6dad733
共有 3 个文件被更改,包括 138 次插入32 次删除
  1. 101
      Runtime/Rigs/DirectorControlRig.cs
  2. 58
      Runtime/Actions/DirectorControlRigAction.cs
  3. 11
      Runtime/Actions/DirectorControlRigAction.cs.meta

101
Runtime/Rigs/DirectorControlRig.cs


using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Playables;
using UnityEngine.Timeline;
public enum PlayMode
{
Stop,
Play,
Reverse
}
public enum WrapMode
{
Stop,
Loop,
PingPong
}
public bool Playing = false;
public bool Reverse = false;
public PlayMode InitialPlayMode = PlayMode.Play;
public float InitialTime = 0.0f;
public DirectorWrapMode wrapMode = DirectorWrapMode.Hold;
public WrapMode wrapMode = WrapMode.Stop;
float nextPauseTime = -1.0f;
public PlayMode playMode { get { return m_PlayMode; } set { m_PlayMode = value; } }
public float stopTime { get { return m_StopTime; } set { m_StopTime = value; } }
public float time { get { return (float)director.time; } set { director.time = value; } }
public TimelineAsset timeline { get { return director.playableAsset as TimelineAsset; } set { director.playableAsset = value; } }
float m_StopTime = -1.0f;
PlayMode m_PlayMode;
{
m_PlayMode = InitialPlayMode;
director.time = InitialTime;
}
public void Play(PlayableAsset asset = null, bool reverse = false, float time = 0.0f)
public void Update()
Playing = true;
Reverse = reverse;
if(m_PlayMode != PlayMode.Stop)
{
float dt = UnscaledGameTime? Time.unscaledDeltaTime : Time.deltaTime;
director.time = time;
float prevTime = (float)director.time;
float newTime = prevTime + (m_PlayMode == PlayMode.Reverse ? -1.0f : 1.0f) * dt;
if(asset != null)
director.playableAsset = asset;
}
if (m_StopTime >= 0.0f &&
( (m_PlayMode == PlayMode.Play && prevTime < m_StopTime && m_StopTime <= newTime)
|| (m_PlayMode == PlayMode.Reverse && newTime <= m_StopTime && m_StopTime < prevTime)
))
{
director.time = m_StopTime;
m_PlayMode = PlayMode.Stop;
m_StopTime = -1.0f;
}
else
director.time = newTime;
public void Play(PlayableAsset asset = null)
{
Play(asset, Reverse, (float)director.time);
}
director.Evaluate();
public void Pause()
{
director.Pause();
}
public void SetTime(float time, bool Reverse = false)
{
director.time = time;
director.Evaluate();
}
if((director.time <= 0.0f && m_PlayMode == PlayMode.Reverse) ||
(director.time >= director.playableAsset.duration && m_PlayMode == PlayMode.Play))
{
switch(wrapMode)
{
case WrapMode.Loop:
if (director.time <= 0.0f)
director.time = director.playableAsset.duration;
else
director.time = 0.0f;
break;
case WrapMode.PingPong:
if (m_PlayMode == PlayMode.Play)
m_PlayMode = PlayMode.Reverse;
else if (m_PlayMode == PlayMode.Reverse)
m_PlayMode = PlayMode.Play;
break;
case WrapMode.Stop:
m_PlayMode = PlayMode.Stop;
break;
}
}
public void Update()
{
if(Playing)
{
float dt = UnscaledGameTime? Time.unscaledDeltaTime : Time.deltaTime;
director.time += Reverse ? -1.0f : 1.0f * dt;
director.Evaluate();
}
}
}

58
Runtime/Actions/DirectorControlRigAction.cs


using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Timeline;
using GameplayIngredients.Rigs;
namespace GameplayIngredients.Actions
{
public class DirectorControlRigAction : ActionBase
{
[NonNullCheck]
public DirectorControlRig directorControlRig;
[Header("Play Mode")]
public bool SetPlayMode = true;
public DirectorControlRig.PlayMode PlayMode = DirectorControlRig.PlayMode.Play;
[Header("Wrap Mode")]
public bool SetWrapMode = false;
public DirectorControlRig.WrapMode WrapMode = DirectorControlRig.WrapMode.Loop;
[Header("Time")]
public bool SetTime = false;
public float Time = 0.0f;
public bool SetStopTime = false;
public float StopTime = 1.0f;
[Header("Timeline Asset")]
public bool SetTimeline = false;
public TimelineAsset TimelineAsset;
public override void Execute(GameObject instigator = null)
{
if (directorControlRig == null)
{
Debug.LogWarning("No DirectorControlRig set, ignoring Call", this.gameObject);
return;
}
if (SetTime)
directorControlRig.time = Time;
if (SetPlayMode)
directorControlRig.playMode = PlayMode;
if (SetWrapMode)
directorControlRig.wrapMode = WrapMode;
if (SetStopTime)
directorControlRig.stopTime = StopTime;
if (SetTimeline)
directorControlRig.timeline = TimelineAsset;
}
}
}

11
Runtime/Actions/DirectorControlRigAction.cs.meta


fileFormatVersion: 2
guid: 46a9752b2a3792a46b8a16cf93bafdd5
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存