97 lines
2.2 KiB
C#
97 lines
2.2 KiB
C#
//============= Copyright (c) Ludic GmbH, All rights reserved. ==============
|
|
//
|
|
// Purpose: Part of the My Behaviour Tree Controller Code
|
|
//
|
|
//=============================================================================
|
|
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using MyBT;
|
|
using UnityEngine.Playables;
|
|
|
|
#if UNITY_EDITOR
|
|
using UnityEditor;
|
|
[CustomEditor(typeof(NamedTimeline))]
|
|
public class NamedTimelineInspector : ComponentHandlerInspector
|
|
{
|
|
}
|
|
#endif
|
|
|
|
[System.Serializable]
|
|
public class NamedTimeline : ComponentHandler
|
|
{
|
|
public override string TypeLabel()
|
|
{
|
|
return "Timeline";
|
|
}
|
|
|
|
public override string ContentLabel()
|
|
{
|
|
UpdateComponent();
|
|
return _playableDirector?.playableAsset.name;
|
|
}
|
|
|
|
public override void UpdateComponent()
|
|
{
|
|
base.UpdateComponent();
|
|
_playableDirector = GetComponent<PlayableDirector>();
|
|
//playableDuration = _playableDirector.duration;
|
|
}
|
|
|
|
//public double playableDuration;
|
|
|
|
private PlayableDirector _playableDirector;
|
|
//private double _startTime;
|
|
|
|
public override string titleText
|
|
{
|
|
get
|
|
{
|
|
return "Run Timeline";
|
|
}
|
|
}
|
|
|
|
public override string[][] helpText
|
|
{
|
|
get
|
|
{
|
|
return new string[][] {
|
|
new string[] {"Run", null, $"BTC.Run(\"{roomId}\", \"{gameObject.name}\")"},
|
|
};
|
|
}
|
|
}
|
|
|
|
public override void Run(MyBT.NodeState nodeState)
|
|
{
|
|
// at start
|
|
if (nodeState == NodeState.FirstRun)
|
|
{
|
|
if (_playableDirector == null)
|
|
{
|
|
Task.SetFailed();
|
|
return;
|
|
}
|
|
|
|
_playableDirector.Play();
|
|
// _startTime = Time.time;
|
|
return;
|
|
}
|
|
|
|
// during runtime
|
|
if (nodeState == NodeState.Running)
|
|
{
|
|
/* if (Time.time - _startTime >= playableDuration)
|
|
{
|
|
Task.SetSucceeded();
|
|
return;
|
|
}*/
|
|
if (_playableDirector?.state != PlayState.Playing)
|
|
{
|
|
Task.SetSucceeded();
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
}
|