129 lines
3.0 KiB
C#
129 lines
3.0 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using DG.Tweening;
|
|
using DragonLi.Core;
|
|
using Mirror;
|
|
using UnityEngine;
|
|
using UnityEngine.XR;
|
|
|
|
/// <summary>
|
|
/// 手类型
|
|
/// </summary>
|
|
public enum HandType
|
|
{
|
|
Left,
|
|
Right
|
|
}
|
|
|
|
/// <summary>
|
|
/// 手状态
|
|
/// </summary>
|
|
public enum HandState
|
|
{
|
|
/// <summary>
|
|
/// 空手
|
|
/// </summary>
|
|
Empty,
|
|
/// <summary>
|
|
/// 有武器
|
|
/// </summary>
|
|
HaveWeapon
|
|
}
|
|
|
|
public class Player : MonoBehaviour
|
|
{
|
|
public Transform LeftHand;
|
|
public Transform RightHand;
|
|
|
|
[Header("经验系统")]
|
|
public int exp; // 当前经验值
|
|
public int[] levelThresholds = { 100, 250, 500 }; // 每级经验阈值
|
|
private int bowLevel = 0;
|
|
|
|
[Header("弓管理")]
|
|
public Bow[] bows; // 不同等级的弓
|
|
public GameObject levelUpEffect; // 升级特效预制体
|
|
public GameObject levelUpEndEffect; // 升级爆炸特效预制体
|
|
private Bow currentBow;
|
|
|
|
public void Start()
|
|
{
|
|
GameLocal.Ins.self = this;
|
|
// 默认装备第一把弓
|
|
EquipBow(0);
|
|
}
|
|
|
|
// 增加经验
|
|
public void GetEx(int amount, Vector3 fromPos)
|
|
{
|
|
// 生成经验特效飞向弓
|
|
StartCoroutine(ShowExpEffect(fromPos));
|
|
|
|
exp += amount;
|
|
Debug.Log($"获得经验:{amount},当前经验:{exp}");
|
|
|
|
// 检查是否升级
|
|
CheckLevelUp();
|
|
}
|
|
|
|
private IEnumerator ShowExpEffect(Vector3 fromPos)
|
|
{
|
|
GameObject expFx = GameObject.CreatePrimitive(PrimitiveType.Sphere);
|
|
expFx.transform.position = fromPos;
|
|
expFx.transform.localScale = Vector3.one * 0.1f;
|
|
expFx.GetComponent<Collider>().enabled = false;
|
|
expFx.GetComponent<MeshRenderer>().material.color = Color.yellow;
|
|
|
|
Transform target = RightHand != null ? RightHand : transform;
|
|
|
|
// 使用 DOTween 飞向弓
|
|
expFx.transform.DOMove(target.position, 0.8f).SetEase(Ease.InQuad);
|
|
yield return new WaitForSeconds(0.8f);
|
|
Destroy(expFx);
|
|
}
|
|
|
|
private void CheckLevelUp()
|
|
{
|
|
if (bowLevel < levelThresholds.Length && exp >= levelThresholds[bowLevel])
|
|
{
|
|
bowLevel++;
|
|
EquipBow(bowLevel);
|
|
|
|
// 生成升级特效
|
|
if (levelUpEffect != null)
|
|
{
|
|
Instantiate(levelUpEffect, RightHand.position, Quaternion.identity);
|
|
}
|
|
|
|
Debug.Log($"弓升级到 Lv{bowLevel + 1}");
|
|
}
|
|
}
|
|
|
|
private void EquipBow(int index)
|
|
{
|
|
for (int i = 0; i < bows.Length; i++)
|
|
{
|
|
bows[i].gameObject.SetActive(i == index);
|
|
}
|
|
currentBow = bows[index];
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
// 滚轮切换弓
|
|
if (Input.mouseScrollDelta.y > 0)
|
|
{
|
|
int prev = Mathf.Max(0, bowLevel - 1);
|
|
EquipBow(prev);
|
|
}
|
|
else if (Input.mouseScrollDelta.y < 0)
|
|
{
|
|
int next = Mathf.Min(bows.Length - 1, bowLevel);
|
|
EquipBow(next);
|
|
}
|
|
}
|
|
}
|
|
|
|
|