WXMC/.svn/pristine/28/28d5eb9dd4680ad79e39bd6a986d3e76b0e2614f.svn-base

206 lines
4.1 KiB
Plaintext
Raw Permalink Normal View History

2024-12-04 16:18:46 +08:00
using Spine.Unity;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PHomePet : PHomeUnit
{
[SerializeField]
private PHomePlayer m_player;
public PHomePlayer Player
{
get
{
return m_player;
}
}
public PHomePet FromPet;
[SerializeField]
private float m_followRadius;
[SerializeField]
private Vector3 m_followOffset;
[SerializeField]
private float m_moveSpeed;
[SerializeField]
private float m_easeTime;
private Vector3 m_refVelocity;
[SerializeField]
private float m_attackInterval;
[SerializeField]
private List<PHomeWeapon> m_weaponPrefabs;
[SerializeField]
private GameObject m_proejctilePrefab;
[SerializeField]
private int m_petIndex;
[SerializeField]
private string m_petName;
public string PetName
{
get
{
return m_petName;
}
}
[SerializeField]
protected Sprite m_desImage;
public Sprite DesImage
{
get
{
return m_desImage;
}
}
[SerializeField]
protected int m_level;
public PuzzleGameMode.VoidDelegate OnAfterLevelChanged;
public int Level
{
get
{
return m_level;
}
set
{
if (!m_level.Equals(value))
{
m_level = value;
OnAfterLevelChanged?.Invoke();
}
}
}
private Vector3 TargetPos
{
get
{
if (m_player == null)
{
return transform.position;
}
float deg = 2 * Mathf.PI / m_player.PetCount;
float myDeg = deg * m_petIndex;
float radius = m_followRadius;
Vector3 posOffset = new Vector3()
{
x = Mathf.Cos(myDeg),
y = -Mathf.Sin(myDeg),
z = 0,
} * radius;
return m_player.transform.position + m_followOffset + posOffset;
}
}
public void SetPetIndex(int index)
{
m_petIndex = index;
}
#region Level
[SerializeField]
private PHomePlayParticleParam m_levelUpEffect;
public void LevelUp()
{
Level += 1;
for (int j = 0; j < Weapons.Count; j++)
{
if (Weapons[j] != null)
{
Weapons[j].ResetLevel();
}
}
m_levelUpEffect.PlayParticle(gameObject);
}
public void SetMaxLevel()
{
}
#endregion
#region Attack
//private void Update_Attack()
//{
// if (m_intervalTimer >= 0)
// {
// m_intervalTimer -= Time.deltaTime;
// return;
// }
// DoAttack();
//}
//private void DoAttack()
//{
// PHomeMonster monster = PHomeGameMode.main.FindClosestMonster(transform.position, m_attackRangeBase, m_player);
// if (monster == null)
// {
// return;
// }
// AttackOnce(monster);
//}
//private void AttackOnce(PHomeMonster monster)
//{
// AudioManager.instance.AttackAudio();
// PHomeProjectile proj = PHomeGameMode.main.SpawnProjectile(m_player, transform.position, m_proejctilePrefab);
// proj.Target = monster;
// EnterCooldown();
//}
#endregion
#region Move
public Vector3 CurrentVelocity
{
get
{
return m_refVelocity;
}
}
private void Update_Movement()
{
Vector3 curPos = transform.position;
Vector3 tarPos = TargetPos;
transform.position = Vector3.SmoothDamp(curPos, tarPos, ref m_refVelocity, m_easeTime);
}
#endregion
private void Start()
{
m_player = PHomeGameMode.main.PlayerUnit;
for (int i = 0; i < m_weaponPrefabs.Count; i++)
{
PHomeGameMode.main.AddWeapon(this, m_weaponPrefabs[i]);
}
Level = 1;
}
// Update is called once per frame
protected override void VirtualUpdate()
{
Update_Movement();
//Update_Attack();
}
}