//============= 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 UnityEngine.Video; using MyBT; #if DEPTHKIT_AVAILABLE using static Depthkit.Depthkit_Clip; #endif #if UNITY_EDITOR using UnityEditor; [CustomEditor(typeof(NamedDepthkitPlayer))] public class NamedDepthkitPlayerInspector : ComponentHandlerInspector { } #endif [System.Serializable] public class NamedDepthkitPlayer : ComponentHandler { #if DEPTHKIT_AVAILABLE public override string TypeLabel () { return "Depthkit"; } public override string ContentLabel() { UpdateComponent(); string filename = depthkitClip._metaDataFilePath; if (depthkitClip._metaDataSourceType == MetadataSourceType.TextAsset) { filename = depthkitClip._metaDataFile.name; } return filename; } public override void UpdateComponent() { base.UpdateComponent(); depthkitClip = GetComponent(); } public Depthkit.Depthkit_Clip depthkitClip; public override string titleText { get { return "Show/Hide, Run Depthkit Video"; } } public override string[][] helpText { get { return new string[][] { new string[] {"Show", null, $"BTC.Show(\"{roomId}\", \"{gameObject.name}\")"}, new string[] {"Hide", null, $"BTC.Hide(\"{roomId}\", \"{gameObject.name}\")"}, new string[] {"Run", null, $"BTC.Run(\"{roomId}\", \"{gameObject.name}\")"} }; } } public override void Run (MyBT.NodeState nodeState) { // Debug.Log($"NamedDepthkitPlayer.Run {nodeState}"); switch (nodeState) { case NodeState.FirstRun: // depthkitClip.Player.CreatePlayer(); // depthkitClip.Player.Load(); //GetComponent().Rewind(true); //depthkitClip.Player.StartVideoLoad(); StartCoroutine(depthkitClip.Player.LoadAndPlay()); //GetComponent().Rewind(false); //Debug.Log("NamedDepthkitPlayer.FirstRun: Load "+Time.frameCount); // goto case NodeState.Running; break; case NodeState.Running: //if ((depthkitClip.Player.GetCurrentTime() <= 0)) { // //depthkitClip.Player.Play(); // GetComponent().Play(); // Debug.Log("NamedDepthkitPlayer.Running: Play "+depthkitClip.Player.GetCurrentTime()); //} //if (!depthkitClip.Player.IsPlaying()) { // || GetComponent(). // //depthkitClip.Player.Play(); // GetComponent().Play(); // //GetComponent().Rewind(false); //} bool isLoaded = (depthkitClip.Player.GetDuration() != 0); bool isFinishedPlaying = (depthkitClip.Player.GetCurrentTime() >= depthkitClip.Player.GetDuration() - 0.3f); if (isLoaded && !depthkitClip.Player.IsPlaying()) { depthkitClip.Player.Play(); } //Debug.Log($"[BTC] NamedDepthkitPlayer.Running: Running: {depthkitClip.Player.IsPlaying()} {isLoaded} {isFinishedPlaying} {Time.frameCount} {depthkitClip.Player.GetCurrentTime()} {depthkitClip.Player.GetDuration()}"); // on desktop if (isFinishedPlaying && isLoaded) { //Debug.Log("[BTC] NamedDepthkitPlayer.Running: !IsPlaying " + Time.frameCount); //depthkitClip.Player.Stop(); //GetComponent().Rewind(true); Task.SetSucceeded(); } break; case NodeState.Aborting: // Debug.Log("Testing "+Time.frameCount); // depthkitClip.Player.CreatePlayer(); // depthkitClip.Player.Load(); //depthkitClip.Player.Stop(); //if (GetComponent()) { // GetComponent().Stop(); //} depthkitClip.Player.Stop(); // if (depthkitClip.Player.IsPlayerSetup()) { // Debug.Log("stopping"); // depthkitClip.Player.Stop(); // } // else { // Debug.Log("not stopping"); // } break; } } public override void Show (MyBT.NodeState nodeState) { switch (nodeState) { case NodeState.FirstRun: gameObject.SetActive(true); goto case NodeState.Running; case NodeState.Running: Task.SetSucceeded(); break; case NodeState.Aborting: break; } } public override void Hide (MyBT.NodeState nodeState) { //Debug.Log($"NamedDepthkitPlayer.Hide {nodeState}"); switch (nodeState) { case NodeState.FirstRun: gameObject.SetActive(false); goto case NodeState.Running; case NodeState.Running: Task.SetSucceeded(); break; case NodeState.Aborting: break; case NodeState.NotRunning: break; } } #else [Header("Depthkit Support disabled: Window->MyBT->PreCompiler Definitions")] public string dummy; #endif }