You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
254 lines
7.9 KiB
254 lines
7.9 KiB
using DG.Tweening;
|
|
using DG.Tweening.Core;
|
|
using DG.Tweening.Plugins.Options;
|
|
using Spine.Unity;
|
|
using UnityEngine;
|
|
using UnityEngine.AddressableAssets;
|
|
using UnityEngine.ResourceManagement.AsyncOperations;
|
|
using AnimationState = Spine.AnimationState;
|
|
|
|
public class IVGuardian : MonoBehaviour
|
|
{
|
|
[SerializeField]
|
|
private Transform trfTarget;
|
|
private IVCharacter ivchar;
|
|
[SerializeField]
|
|
private float fMoveSpeed = 0.1f;
|
|
[SerializeField]
|
|
private Vector3 v3Offset = Vector3.zero;
|
|
private Vector3 v3OffsetRev = Vector3.zero;
|
|
private Vector3 v3posto;
|
|
private Vector3 v3RandomPos;
|
|
private Vector3 v3dir;
|
|
|
|
[SerializeField]
|
|
private SkeletonAnimation skAnim;
|
|
|
|
private TweenerCore<Vector3, Vector3, VectorOptions> twcSummon = null;
|
|
private TweenerCore<Vector3, Vector3, VectorOptions> twcSummonRev = null;
|
|
private TweenerCore<Vector3, Vector3, VectorOptions> twcUnsummon = null;
|
|
private TweenerCore<Vector3, Vector3, VectorOptions> twcUnsummonRev = null;
|
|
private TweenerCore<Vector3, Vector3, VectorOptions> twcMove = null;
|
|
private TweenerCore<Vector3, Vector3, VectorOptions> twcMoveX = null;
|
|
|
|
private int Key = -1;
|
|
private bool bFrontRight = true;
|
|
private float bFrontRightCahr = -1;
|
|
|
|
private bool bInitNeed = true;
|
|
[SerializeField]
|
|
private bool bSet = true;
|
|
private bool bMove = false;
|
|
private bool bMoveFlag = false;
|
|
private bool bSummoning = false;
|
|
|
|
private AnimationState anState;
|
|
private AsyncOperationHandle<SkeletonDataAsset> handlePet;
|
|
|
|
public void Init()
|
|
{
|
|
Transform trfwrapper = transform.GetChild(0);
|
|
Transform trfpet = trfwrapper.GetChild(0);
|
|
//skAnim = trfpet.GetComponent<SkeletonAnimation>();
|
|
//skAnim.
|
|
|
|
twcSummon = transform.DOScale(Vector3.one * 0.3f, 0.2f).ChangeStartValue(Global.V3_001).SetEase(Ease.OutQuad).OnComplete(SummonEnd).SetAutoKill(false).Pause();
|
|
twcSummonRev = transform.DOScale(Global.oneRev * 0.3f, 0.2f).ChangeStartValue(Global.V3_001XRev).SetEase(Ease.OutQuad).OnComplete(SummonEnd).SetAutoKill(false).Pause();
|
|
twcUnsummon = transform.DOScale(Global.V3_001, 0.2f).ChangeStartValue(Vector3.one * 0.3f).SetEase(Ease.InQuad).OnComplete(UnsummonEnd).SetAutoKill(false).Pause();
|
|
twcUnsummonRev = transform.DOScale(Global.V3_001XRev, 0.2f).ChangeStartValue(Global.oneRev * 0.3f).SetEase(Ease.InQuad).OnComplete(UnsummonEnd).SetAutoKill(false).Pause();
|
|
transform.position = trfTarget.position + Random.insideUnitSphere * Random.Range(5, 7);
|
|
ivchar = trfTarget.GetComponent<IVCharacter>();
|
|
//twcMove = trfwrapper.DOLocalMoveY(0.5f, 1.35f).SetEase(Ease.InOutQuad).SetLoops(-1, LoopType.Yoyo).SetAutoKill(false).Pause();
|
|
//twcMoveX = trfwrapper.DOLocalMoveX(0.5f, Random.Range(1.5f, 2f)).SetEase(Ease.InOutQuad).SetLoops(-1, LoopType.Yoyo).SetAutoKill(false).Pause();
|
|
|
|
bInitNeed = false;
|
|
}
|
|
|
|
public void OffGuardian()
|
|
{
|
|
twcMove.Pause();
|
|
twcMoveX.Pause();
|
|
gameObject.SetActive(false);
|
|
}
|
|
// �� ��ȯ �Ϸ�.
|
|
private void SummonEnd()
|
|
{
|
|
twcMove.Play();
|
|
twcMoveX.Play();
|
|
bSummoning = false;
|
|
}
|
|
|
|
// �� ��ȯ ���� �Ϸ�.
|
|
private void UnsummonEnd()
|
|
{
|
|
gameObject.SetActive(false);
|
|
}
|
|
public void Unsummon()
|
|
{
|
|
if (Key < 0)
|
|
return;
|
|
|
|
bSummoning = true;
|
|
twcMove.Pause();
|
|
twcMoveX.Pause();
|
|
if (bFrontRight)
|
|
twcUnsummon.Restart();
|
|
else
|
|
twcUnsummonRev.Restart();
|
|
}
|
|
// �� ��ȯ.
|
|
public void Summon()
|
|
{
|
|
if (Key < 0)
|
|
return;
|
|
v3RandomPos = Random.insideUnitCircle * Random.Range(3, 5);
|
|
transform.position = new Vector3(trfTarget.position.x + v3RandomPos.x, trfTarget.position.y + v3RandomPos.y, (trfTarget.position.y + v3RandomPos.y) * 0.1f);
|
|
|
|
if (bFrontRight)
|
|
twcSummon.Restart();
|
|
else
|
|
twcSummonRev.Restart();
|
|
gameObject.SetActive(true);
|
|
anState = skAnim.AnimationState;
|
|
if (bSet)
|
|
{
|
|
bMove = false;
|
|
anState.SetAnimation(0, "idle", true);
|
|
}
|
|
}
|
|
|
|
public void SetGuardian(int key)
|
|
{
|
|
// ������� ����.
|
|
if (key == Key)
|
|
return;
|
|
|
|
// �� ����.
|
|
if (key < 0)
|
|
{
|
|
if (Key >= 0)
|
|
{
|
|
Key = -1;
|
|
bSet = false;
|
|
if (skAnim.skeletonDataAsset != null)
|
|
skAnim.skeletonDataAsset.Clear();
|
|
skAnim.ClearState();
|
|
gameObject.SetActive(false);
|
|
}
|
|
return;
|
|
}
|
|
|
|
// �� ����.
|
|
Key = key;
|
|
bSet = false;
|
|
CoverCamera.Hold();
|
|
if (skAnim.skeletonDataAsset != null)
|
|
skAnim.skeletonDataAsset.Clear();
|
|
skAnim.ClearState();
|
|
|
|
//@ for test
|
|
switch (key)
|
|
{
|
|
case 33:
|
|
key = 44;
|
|
break;
|
|
}
|
|
Addressables.LoadAssetAsync<SkeletonDataAsset>(FormatString.StringFormat(AddressableMgr.PathGuardian, key.ToString())).Completed += ALoadGuardianComp;
|
|
}
|
|
|
|
public void SetFront(bool bfrontright)
|
|
{
|
|
bFrontRight = bfrontright;
|
|
if (bFrontRight)
|
|
{
|
|
transform.localScale = Vector3.one * 0.3f;
|
|
transform.position = trfTarget.position + v3Offset;
|
|
}
|
|
else
|
|
{
|
|
transform.localScale = Global.oneRev * 0.3f;
|
|
transform.position = trfTarget.position + v3OffsetRev;
|
|
}
|
|
}
|
|
|
|
public void ChangeFront(bool bfrontright)
|
|
{
|
|
if (bfrontright == bFrontRight)
|
|
return;
|
|
bFrontRight = bfrontright;
|
|
if (bFrontRight)
|
|
transform.localScale = Vector3.one * 0.3f;
|
|
else
|
|
transform.localScale = Global.oneRev * 0.3f;
|
|
}
|
|
public void ChangeFrontToTarget()
|
|
{
|
|
if (transform.position.x - v3posto.x < -0.1f)
|
|
transform.localScale = Vector3.one * 0.3f;
|
|
else if (transform.position.x - v3posto.x > 0.1f)
|
|
transform.localScale = Global.oneRev * 0.3f;
|
|
else
|
|
return;
|
|
}
|
|
|
|
protected void LateUpdate()
|
|
{
|
|
if (bInitNeed || bSummoning)
|
|
return;
|
|
|
|
|
|
//bMoveFlag = true;
|
|
//BattleMgr.SCalcDistance(trfTarget.position, transform.position);
|
|
|
|
if (BattleMgr.SCalcDistance(trfTarget.position, transform.position) > 2.5f && !bMoveFlag)
|
|
{
|
|
bMoveFlag = true;
|
|
anState.SetAnimation(0, "move", true);
|
|
}
|
|
|
|
|
|
if (bMoveFlag)
|
|
{
|
|
if (ivchar.IsLookRight)
|
|
bFrontRightCahr = 1.5f;
|
|
else
|
|
bFrontRightCahr = -1.5f;
|
|
|
|
v3posto = new Vector3(trfTarget.position.x + bFrontRightCahr, trfTarget.position.y + 2, (trfTarget.position.y + 2) * 0.1f);
|
|
v3dir = (v3posto - transform.position).normalized;
|
|
transform.position = transform.position + v3dir * (0.1f * fMoveSpeed);
|
|
|
|
float fdistance = BattleMgr.SCalcDistance(transform.position, v3posto);
|
|
ChangeFrontToTarget();
|
|
if (fdistance <= 0.6f)
|
|
{
|
|
//bMove = false;
|
|
bMoveFlag = false;
|
|
anState.SetAnimation(0, "idle", true);
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
private void ALoadGuardianComp(AsyncOperationHandle<SkeletonDataAsset> obj)
|
|
{
|
|
skAnim.skeletonDataAsset = obj.Result;
|
|
skAnim.Initialize(true);
|
|
anState = skAnim.AnimationState;
|
|
//AtlasUtilities.ClearCache();
|
|
|
|
if (handlePet.IsValid())
|
|
{
|
|
Addressables.Release(handlePet);
|
|
AddressableMgr.SAddUnload();
|
|
}
|
|
|
|
handlePet = obj;
|
|
CoverCamera.Release();
|
|
bSet = true;
|
|
|
|
if (BattleMgr.Instance.BattlePause)
|
|
return;
|
|
Summon();
|
|
}
|
|
}
|