93 lines
3.7 KiB
C#
93 lines
3.7 KiB
C#
using Assets.Framework.Tool;
|
||
using Assets.MyGame.Scripts.Net;
|
||
using DG.Tweening;
|
||
using UnityEngine;
|
||
using UnityEngine.UI;
|
||
|
||
/// <summary>
|
||
/// 鱼死亡掉落道具脚本(与 CoinScript 同级,均继承 BJBase)。
|
||
/// 行为类似金币:原地掉落 → 飞向击杀者座位 → 回收。
|
||
/// 掉落数据由服务端 RoomKillNotice.drop 下发(propNumber/propName/count),
|
||
/// 道具图标按 /uploads/{propNumber}.png 从服务端下载。
|
||
/// </summary>
|
||
public class FishKillProp : BJBase
|
||
{
|
||
/// <summary>道具图标(Inspector 绑定)</summary>
|
||
public Image propIco;
|
||
|
||
/// <summary>
|
||
/// 重写基类方法:道具不显示金币数字,而是下载并设置道具图标。
|
||
/// 和 CoinScript.SetCoinCount() 对称,供外部统一调用。
|
||
/// </summary>
|
||
public override void SetCoinCount()
|
||
{
|
||
// 修正 z 轴(和 CoinScript 一致,防止 UI 层级下 z 不为 0 导致被遮挡)
|
||
var v3 = transform.position;
|
||
v3.z = 0;
|
||
transform.position = v3;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 初始化道具(扩展 BJBase.Init,增加道具编号)。
|
||
/// 由 CreateFishManager 在收到服务端掉落推送时调用。
|
||
/// </summary>
|
||
/// <param name="propNumber">道具编号(用于下载图标 /uploads/编号.png)</param>
|
||
/// <param name="propCount">掉落数量</param>
|
||
/// <param name="startPoint">掉落起点(鱼死亡位置)</param>
|
||
/// <param name="endPoint">飞行终点(击杀者座位位置)</param>
|
||
/// <param name="userID">击杀者 ID</param>
|
||
/// <param name="sitID">座位 ID</param>
|
||
/// <param name="jobj">附加数据(透传,回调时原样返回)</param>
|
||
public void InitProp(string propNumber, int propCount, Vector3 startPoint, Vector3 endPoint,
|
||
string userID = "", int sitID = 999, object jobj = null)
|
||
{
|
||
this.startPoint = startPoint;
|
||
// 复用基类 Init 设置通用字段(道具不涉及金币数量,coinCount 传 0)
|
||
Init(0, endPoint, userID, sitID, jobj);
|
||
|
||
// 下载道具图标:固定格式 /uploads/{propNumber}.png
|
||
DownloadPropIcon(propNumber);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 从服务端下载道具图标并设置到 propIco。
|
||
/// 失败时 propIco 保留预制体上配置好的默认图(不强制兜底重试)。
|
||
/// </summary>
|
||
private void DownloadPropIcon(string propNumber)
|
||
{
|
||
if (string.IsNullOrEmpty(propNumber) || propIco == null) return;
|
||
|
||
string url = APIManager.baseURL + "/uploads/" + propNumber + ".png";
|
||
WebTool.DownImage(url, tex =>
|
||
{
|
||
// 回调时本物体可能已被销毁(飞到座位后回池/切场景),需判空
|
||
if (this == null || propIco == null) return;
|
||
if (tex != null)
|
||
{
|
||
propIco.sprite = Sprite.Create(tex,
|
||
new Rect(0, 0, tex.width, tex.height),
|
||
Vector2.one * 0.5f);
|
||
propIco.SetNativeSize();
|
||
propIco.gameObject.SetActive(true);
|
||
}
|
||
});
|
||
}
|
||
|
||
/// <summary>
|
||
/// 飞到座位位置并回收(效果同 coinEvent.HuiShou)。
|
||
/// 可由动画事件调用(预制体有掉落动画时),也可直接调用实现原地掉落后立即飞向座位。
|
||
/// </summary>
|
||
public void FlyToSeat()
|
||
{
|
||
transform.DOMove(endPoint, 0.5f).OnComplete(() =>
|
||
{
|
||
// 拾取回调(由 CreateFishManager 设置 JiaFen)
|
||
JiaFen?.Invoke(0);
|
||
// 拾取音效(复用金币拾取音效)
|
||
AudioManager.Instance.PlayerFX(61009);
|
||
// 池化回收
|
||
EffectPool.Instance.Return(gameObject);
|
||
});
|
||
}
|
||
}
|