1
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using Animancer;
|
||||
using NodeCanvas.DialogueTrees;
|
||||
using UnityEngine;
|
||||
|
||||
namespace BITKit.NodeCanvas.Director
|
||||
{
|
||||
public class ActorRandomAnimation : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private AnimancerComponent animancerComponent;
|
||||
[SerializeField] private AnimationClip[] clips;
|
||||
private IDialogueActor _actor;
|
||||
private void OnEnable()
|
||||
{
|
||||
_actor = GetComponent<IDialogueActor>();
|
||||
DialogueTree.OnSubtitlesRequest += OnSubtitlesRequest;
|
||||
}
|
||||
private void OnDisable()
|
||||
{
|
||||
DialogueTree.OnSubtitlesRequest -= OnSubtitlesRequest;
|
||||
}
|
||||
|
||||
private void OnSubtitlesRequest(SubtitlesRequestInfo obj)
|
||||
{
|
||||
if(obj.actor != _actor) return;
|
||||
animancerComponent.Stop();
|
||||
var state =animancerComponent.Play(clips.Random());
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 40c7a825d953b804c862d2e8295de71c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
22
Src/UnityPluginsSupport/NodeCanvas/Director/DirectorNode.cs
Normal file
22
Src/UnityPluginsSupport/NodeCanvas/Director/DirectorNode.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using NodeCanvas.Framework;
|
||||
using UnityEngine;
|
||||
|
||||
namespace BITKit.NodeCanvas.Director
|
||||
{
|
||||
public class DirectorNode : ActionTask
|
||||
{
|
||||
public BBParameter<string> directorName;
|
||||
public bool isStart;
|
||||
protected override void OnExecute()
|
||||
{
|
||||
base.OnExecute();
|
||||
if(isStart)
|
||||
DirectorService.Register(directorName.value);
|
||||
else
|
||||
DirectorService.UnRegister(directorName.value);
|
||||
EndAction();
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8392b577f14613c4181afa893b8d9643
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,79 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using Cinemachine;
|
||||
using NodeCanvas.DialogueTrees;
|
||||
using UnityEngine;
|
||||
|
||||
namespace BITKit.NodeCanvas.Director
|
||||
{
|
||||
public class DirectorService : MonoBehaviour
|
||||
{
|
||||
[RuntimeInitializeOnLoadMethod]
|
||||
private static void Reload()
|
||||
{
|
||||
allowDirector.Clear();
|
||||
}
|
||||
private static readonly ValidHandle allowDirector = new();
|
||||
public static void Register(string directorName)
|
||||
{
|
||||
allowDirector.AddElement(directorName);
|
||||
}
|
||||
public static void UnRegister(string directorName)
|
||||
{
|
||||
allowDirector.RemoveElement(directorName);
|
||||
}
|
||||
|
||||
[SerializeField] private CinemachineVirtualCamera directorCamera;
|
||||
|
||||
private Cinemachine3rdPersonFollow _trd;
|
||||
|
||||
private Transform _lastActor;
|
||||
|
||||
private Vector3 _defaultShoulderOffset;
|
||||
private void OnEnable()
|
||||
{
|
||||
DialogueTree.OnSubtitlesRequest += OnSubtitlesRequest;
|
||||
allowDirector.AddListener(OnAllow);
|
||||
|
||||
_trd = directorCamera.GetCinemachineComponent<Cinemachine3rdPersonFollow>();
|
||||
_defaultShoulderOffset = _trd.ShoulderOffset;
|
||||
}
|
||||
private void OnDisable()
|
||||
{
|
||||
DialogueTree.OnSubtitlesRequest -= OnSubtitlesRequest;
|
||||
allowDirector.RemoveListener(OnAllow);
|
||||
}
|
||||
|
||||
private void OnSubtitlesRequest(SubtitlesRequestInfo obj)
|
||||
{
|
||||
if (obj.actor is not MonoBehaviour monoBehaviour) return;
|
||||
var transform1 = monoBehaviour.transform;
|
||||
|
||||
|
||||
directorCamera.LookAt = transform1;
|
||||
directorCamera.Follow = _lastActor ? _lastActor : transform1;
|
||||
|
||||
var newOffset = _defaultShoulderOffset;
|
||||
|
||||
newOffset.z = _lastActor ? _defaultShoulderOffset.z : 3;
|
||||
|
||||
_trd.ShoulderOffset = newOffset;
|
||||
|
||||
_lastActor = transform1;
|
||||
}
|
||||
|
||||
private void OnAllow(bool allow)
|
||||
{
|
||||
if (allow)
|
||||
{
|
||||
directorCamera.Priority = 64;
|
||||
}
|
||||
else
|
||||
{
|
||||
directorCamera.Priority = -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ad95d668b0ed8264c892fc2969bc5f38
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Reference in New Issue
Block a user