Yarn命令变化
This commit is contained in:
@@ -110,7 +110,7 @@ namespace AibisDream
|
||||
}
|
||||
}
|
||||
|
||||
[YarnCommand("actor_fade_in")]
|
||||
[YarnCommand("fade_in_actor")]
|
||||
public static IEnumerator ActorFadeIn(string actorName = ClinicSlotName, float duration = 1)
|
||||
{
|
||||
if (ActorManager.Instance.TryFindActor(actorName, out var actor))
|
||||
@@ -119,7 +119,7 @@ namespace AibisDream
|
||||
}
|
||||
}
|
||||
|
||||
[YarnCommand("actor_fade_out")]
|
||||
[YarnCommand("fade_out_actor")]
|
||||
public static IEnumerator ActorFadeOut(string actorName = ClinicSlotName, float duration = 1)
|
||||
{
|
||||
if (ActorManager.Instance.TryFindActor(actorName, out var actor))
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using AibisDream.Framework;
|
||||
using AibisDream.Utility;
|
||||
using UnityEngine;
|
||||
|
||||
namespace AibisDream
|
||||
@@ -10,6 +11,7 @@ namespace AibisDream
|
||||
base.Init(actorName, slot);
|
||||
// 赋值
|
||||
spriteRenderer.sprite = ResourceKit.LoadAssetSync<Sprite>($"Sprite/{ActorName}_Idle");
|
||||
spriteRenderer.SetAlpha(0);
|
||||
}
|
||||
|
||||
public override void ChangeState(string stateName)
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 98de6971e73e45b5ae6f1df075d7d55f
|
||||
timeCreated: 1747892423
|
||||
@@ -1,55 +0,0 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class Actor : MonoBehaviour
|
||||
{
|
||||
private Animator animator;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
// 自动获取 Animator 组件
|
||||
animator = GetComponent<Animator>();
|
||||
if (animator == null)
|
||||
{
|
||||
Debug.LogError("Animator component not found on actor.");
|
||||
}
|
||||
}
|
||||
|
||||
public void PlayAnimation(string animationName)
|
||||
{
|
||||
if (animator != null)
|
||||
{
|
||||
animator.Play(animationName);
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError("Animator not found on actor.");
|
||||
}
|
||||
}
|
||||
|
||||
public void InitializeAtSlot(Transform slot)
|
||||
{
|
||||
if (slot != null)
|
||||
{
|
||||
transform.position = slot.position;
|
||||
transform.rotation = slot.rotation;
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError("Slot transform is null.");
|
||||
}
|
||||
}
|
||||
|
||||
public void SetAnimationState(string stateName)
|
||||
{
|
||||
if (animator != null)
|
||||
{
|
||||
animator.SetTrigger(stateName);
|
||||
Debug.Log("Trigger"+stateName);
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError("Animator not found on actor.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 62e221e22720bec40b69d4bf463b3db2
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,128 +0,0 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using AibisDream.Utility;
|
||||
using UnityEngine;
|
||||
using Yarn.Unity;
|
||||
|
||||
public class ActorManager : MonoBehaviour
|
||||
{
|
||||
[Header("Actors")]
|
||||
private List<Actor> actors = new();
|
||||
|
||||
[Header("Slots")]
|
||||
public List<Transform> slotList = new(); // 用于在编辑器中设置插槽
|
||||
private Dictionary<string, Transform> slots = new();
|
||||
|
||||
[YarnCommand("fade_in_actor")]
|
||||
public IEnumerator FadeInActorByName(string actorName, float duration)
|
||||
{
|
||||
var actor = actors.Find(a => a.name == actorName);
|
||||
if (actor != null)
|
||||
{
|
||||
yield return StartCoroutine(FadeActor(actor.GetComponent<SpriteRenderer>(), 0f, 1f, duration));
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError($"Actor with name {actorName} not found.");
|
||||
}
|
||||
}
|
||||
|
||||
[YarnCommand("fade_out_actor")]
|
||||
public IEnumerator FadeOutActorByName(string actorName, float duration)
|
||||
{
|
||||
var actor = actors.Find(a => a.name == actorName);
|
||||
if (actor != null)
|
||||
{
|
||||
yield return StartCoroutine(FadeActor(actor.GetComponent<SpriteRenderer>(), 1f, 0f, duration));
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError($"Actor with name {actorName} not found.");
|
||||
}
|
||||
}
|
||||
|
||||
[YarnCommand("play_actor_animation")]
|
||||
public void PlayActorAnimation(string actorName, string animationName)
|
||||
{
|
||||
var actor = actors.Find(a => a.name == actorName);
|
||||
if (actor != null)
|
||||
{
|
||||
actor.SetAnimationState(animationName);
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError($"Actor with name {actorName} not found.");
|
||||
}
|
||||
}
|
||||
|
||||
[YarnCommand("initialize_actor_at_slot")]
|
||||
public void InitializeActorAtSlot(string actorName, string slotName)
|
||||
{
|
||||
var prefab = Resources.Load<GameObject>($"CharacterPrefab/{actorName}");
|
||||
if (prefab != null && slots.TryGetValue(slotName, out var slot))
|
||||
{
|
||||
var actorInstance = Instantiate(prefab, slot.position, slot.rotation,this.transform);
|
||||
actorInstance.name = actorName; // 去掉 "(Clone)" 后缀
|
||||
var actor = actorInstance.GetComponent<Actor>();
|
||||
if (actor != null)
|
||||
{
|
||||
actors.Add(actor);
|
||||
actor.InitializeAtSlot(slot);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError($"Actor prefab with name {actorName} not found or slot with name {slotName} not found.");
|
||||
}
|
||||
}
|
||||
|
||||
private IEnumerator FadeActor(SpriteRenderer actor, float startAlpha, float endAlpha, float duration)
|
||||
{
|
||||
float elapsedTime = 0f;
|
||||
Color color = actor.color;
|
||||
|
||||
while (elapsedTime < duration)
|
||||
{
|
||||
elapsedTime += Time.deltaTime;
|
||||
float alpha = Mathf.Lerp(startAlpha, endAlpha, elapsedTime / duration);
|
||||
actor.color = new Color(color.r, color.g, color.b, alpha);
|
||||
yield return null;
|
||||
}
|
||||
|
||||
actor.color = new Color(color.r, color.g, color.b, endAlpha);
|
||||
}
|
||||
|
||||
private void SetActorAlphaZero(SpriteRenderer actor)
|
||||
{
|
||||
actor.SetAlpha(0);
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
InitializeSlots();
|
||||
HideAllActors();
|
||||
}
|
||||
|
||||
private void InitializeSlots()
|
||||
{
|
||||
foreach (var slot in slotList)
|
||||
{
|
||||
if (slot != null)
|
||||
{
|
||||
slots[slot.name] = slot;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void HideAllActors()
|
||||
{
|
||||
foreach (var actor in actors)
|
||||
{
|
||||
var spriteRenderer = actor.GetComponent<SpriteRenderer>();
|
||||
if (spriteRenderer != null)
|
||||
{
|
||||
spriteRenderer.color = new Color(spriteRenderer.color.r, spriteRenderer.color.g, spriteRenderer.color.b, 0f);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 40a5ab0dc89da0f469155caebeaf7383
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,92 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using Yarn.Unity;
|
||||
|
||||
public class EnvironmentManager : MonoBehaviour
|
||||
{
|
||||
[Header("Time of Day Objects")]
|
||||
public List<GameObject> dayObjects;
|
||||
public List<GameObject> nightObjects;
|
||||
public List<GameObject> midnightObjects;
|
||||
|
||||
[Header("Weather Effects")]
|
||||
public GameObject snowEffect;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
// 设置默认状态
|
||||
SetTimeOfDay(TimeOfDay.Day);
|
||||
SetWeather(false);
|
||||
}
|
||||
|
||||
// [YarnCommand("set_time_of_day")]
|
||||
public void SetTimeOfDayCommand(string timeOfDay)
|
||||
{
|
||||
timeOfDay = timeOfDay.ToLower();
|
||||
if (timeOfDay == "day" && dayObjects.Count > 0)
|
||||
{
|
||||
SetTimeOfDay(TimeOfDay.Day);
|
||||
}
|
||||
else if (timeOfDay == "night" && nightObjects.Count > 0)
|
||||
{
|
||||
SetTimeOfDay(TimeOfDay.Night);
|
||||
}
|
||||
else if (timeOfDay == "midnight" && midnightObjects.Count > 0)
|
||||
{
|
||||
SetTimeOfDay(TimeOfDay.Midnight);
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError($"Invalid or unavailable time of day: {timeOfDay}");
|
||||
}
|
||||
}
|
||||
|
||||
public void SetTimeOfDay(TimeOfDay timeOfDay)
|
||||
{
|
||||
if (dayObjects.Count > 0)
|
||||
{
|
||||
foreach (var obj in dayObjects)
|
||||
{
|
||||
obj.SetActive(timeOfDay == TimeOfDay.Day);
|
||||
}
|
||||
}
|
||||
|
||||
if (nightObjects.Count > 0)
|
||||
{
|
||||
foreach (var obj in nightObjects)
|
||||
{
|
||||
obj.SetActive(timeOfDay == TimeOfDay.Night);
|
||||
}
|
||||
}
|
||||
|
||||
if (midnightObjects.Count > 0)
|
||||
{
|
||||
foreach (var obj in midnightObjects)
|
||||
{
|
||||
obj.SetActive(timeOfDay == TimeOfDay.Midnight);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// [YarnCommand("set_weather")]
|
||||
public void SetWeatherCommand(string weatherType)
|
||||
{
|
||||
bool isSnowing = weatherType.ToLower() == "snow";
|
||||
SetWeather(isSnowing);
|
||||
}
|
||||
|
||||
public void SetWeather(bool isSnowing)
|
||||
{
|
||||
if (snowEffect != null)
|
||||
{
|
||||
snowEffect.SetActive(isSnowing);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public enum TimeOfDay
|
||||
{
|
||||
Day,
|
||||
Night,
|
||||
Midnight
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9ebc4f12b48436f4985f9bf4ee8b92b1
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user