136 lines
3.8 KiB
C#
136 lines
3.8 KiB
C#
using System;
|
||
using System.Collections;
|
||
using System.Collections.Generic;
|
||
using DarkTonic.MasterAudio;
|
||
using DG.Tweening;
|
||
using DragonLi.Behaviour;
|
||
using DragonLi.Core;
|
||
using Mirror;
|
||
using TMPro;
|
||
using UnityEngine;
|
||
using Valheim;
|
||
using Action = System.Action;
|
||
|
||
public class AiDr : NetworkBehaviour
|
||
{
|
||
public Animator animator;
|
||
public TMP_Text speedTxt;
|
||
public int curState;
|
||
|
||
private const float TxtSpeed = 1; //文字显示时间
|
||
|
||
[SoundGroup] public string lineSound1;
|
||
[SoundGroup] public string lineSound2;
|
||
[SoundGroup] public string lineSound3;
|
||
|
||
public void Init()
|
||
{
|
||
ChangeState(0);
|
||
}
|
||
|
||
public void ChangeState(int state)
|
||
{
|
||
curState = state;
|
||
switch (curState)
|
||
{
|
||
case 0:
|
||
StartState();
|
||
break;
|
||
case 1:
|
||
ChangeCardState();
|
||
break;
|
||
case -1:
|
||
Idle();
|
||
break;
|
||
}
|
||
}
|
||
|
||
public void Idle()
|
||
{
|
||
animator.SetBool("Speed",false);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 开场
|
||
/// </summary>
|
||
public void StartState()
|
||
{
|
||
animator.SetBool("Speed",true);
|
||
StartTxt("欢迎来到小小幻宠的世界,这里是一片现实与奇幻交织的世界,你将在这里,遇到属于你的小小幻宠,和他们并肩作战.");
|
||
MasterAudio.StopAllSoundsOfTransform(transform);
|
||
MasterAudio.PlaySound3DAtTransform(lineSound1, transform);
|
||
MonoSingleton<CoroutineTaskManager>.Instance.WaitSecondTodo(() =>
|
||
{
|
||
if (curState == 0)
|
||
{
|
||
ChangeState(-1);
|
||
}
|
||
GameInit.Ins.laboratory.ShowCards();
|
||
},19f);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 选择了卡片
|
||
/// </summary>
|
||
public void ChangeCardState()
|
||
{
|
||
if(GameManager.Ins.userPet!=null)
|
||
return;
|
||
animator.SetBool("Speed",true);
|
||
StartTxt("看他的样子,他也很喜欢你呢!");
|
||
MasterAudio.StopAllSoundsOfTransform(transform);
|
||
MasterAudio.PlaySound3DAtTransform(lineSound2, transform);
|
||
MonoSingleton<CoroutineTaskManager>.Instance.WaitSecondTodo(() =>
|
||
{
|
||
ToGameState();
|
||
},8f);
|
||
MonoSingleton<CoroutineTaskManager>.Instance.WaitSecondTodo(() =>
|
||
{
|
||
if (curState == 1)
|
||
{
|
||
ChangeState(-1);
|
||
}
|
||
},2f);
|
||
}
|
||
|
||
|
||
public void ToGameState()
|
||
{
|
||
animator.SetBool("Speed",true);
|
||
StartTxt("我现在已经开启了去往幻宠世界的传送门 请选择你喜欢的宠物 去探险吧");
|
||
MasterAudio.StopAllSoundsOfTransform(transform);
|
||
MasterAudio.PlaySound3DAtTransform(lineSound3, transform);
|
||
MonoSingleton<CoroutineTaskManager>.Instance.WaitSecondTodo(() =>
|
||
{
|
||
ChangeState(-1);
|
||
CreateDoor();
|
||
},8f);
|
||
}
|
||
|
||
public void CreateDoor()
|
||
{
|
||
GameObject door= GameManager.Ins.CreateDoorCoiider(GameInit.Ins.doorPos.position,Vector3.zero);
|
||
MonoSingleton<CoroutineTaskManager>.Instance.WaitSecondTodo(() =>
|
||
{
|
||
GameManager.Ins.ShowPetWorld(door);
|
||
},5f);
|
||
}
|
||
|
||
public void StartTxt(string txt,Action cb=null)
|
||
{
|
||
speedTxt.text = txt;
|
||
//初始时设置文字的透明度为0(完全透明)
|
||
speedTxt.color = new Color(speedTxt.color.r, speedTxt.color.g, speedTxt.color.b, 0f);
|
||
// 使用DoTween实现文字的渐显效果
|
||
speedTxt.DOFade(1f, TxtSpeed).SetEase(Ease.Linear).OnComplete(() =>
|
||
{
|
||
cb?.Invoke();
|
||
}); // 渐显到完全不透明,使用线性缓动效果
|
||
}
|
||
|
||
private void Update()
|
||
{
|
||
transform.GetComponent<Transform>().LookAt(new Vector3(GameInit.Ins.MRCamera.transform.position.x,0,GameInit.Ins.MRCamera.transform.position.z));
|
||
}
|
||
}
|