97 lines
2.8 KiB
C#
97 lines
2.8 KiB
C#
using asap.core;
|
|
using game;
|
|
using GameCore;
|
|
using System;
|
|
using TMPro;
|
|
using UniRx;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class OpponentItem : MonoBehaviour
|
|
{
|
|
Head head;
|
|
TMP_Text text_name;
|
|
TMP_Text text_info;
|
|
Button btn_challenge;
|
|
OpponentItemData opponentItemData;
|
|
public Action<OpponentItemData, bool> action;
|
|
string playFabId;
|
|
IDisposable disposable;
|
|
private void Awake()
|
|
{
|
|
disposable = GContext.OnEvent<GetClubPlayInfoEvent>().Where(x => x.id == playFabId).Subscribe(SetAvatar);
|
|
head = transform.Find("btn_head").GetComponent<Head>();
|
|
text_name = transform.Find("info/text_name").GetComponent<TMP_Text>();
|
|
text_info = transform.Find("info/text_info").GetComponent<TMP_Text>();
|
|
btn_challenge = transform.Find("btn_common_green_c/btn_green_c").GetComponent<Button>();
|
|
}
|
|
public void SetGray()
|
|
{
|
|
btn_challenge.gameObject.SetActive(false);
|
|
}
|
|
private void Start()
|
|
{
|
|
btn_challenge.onClick.AddListener(() =>
|
|
{
|
|
action?.Invoke(opponentItemData, false);
|
|
});
|
|
}
|
|
public void SetData(OpponentItemData opponentItemData)
|
|
{
|
|
this.opponentItemData = opponentItemData;
|
|
playFabId = opponentItemData.playFabID;
|
|
text_info.text = opponentItemData.info;
|
|
text_info.gameObject.SetActive(!string.IsNullOrEmpty(opponentItemData.info));
|
|
//text_name.text = opponentItemData.playName;
|
|
//head.SetData(opponentItemData.url);
|
|
IUserService userService = GContext.container.Resolve<IUserService>();
|
|
PlayInfo clubPlayInfo = userService.GetPlayInfo(playFabId);
|
|
SetAvatar(clubPlayInfo);
|
|
}
|
|
|
|
public void SetTextInfo(string text)
|
|
{
|
|
text_info.text = text;
|
|
}
|
|
|
|
public void SetAvatar(PlayInfo clubPlayInfo)
|
|
{
|
|
if (clubPlayInfo != null)
|
|
{
|
|
text_name.text = clubPlayInfo.name;
|
|
head.SetData(clubPlayInfo.avatarUrl);
|
|
}
|
|
}
|
|
void SetAvatar(GetClubPlayInfoEvent getClubPlayInfoEvent)
|
|
{
|
|
if (getClubPlayInfoEvent.id == playFabId)
|
|
{
|
|
text_name.text = getClubPlayInfoEvent.name;
|
|
head.SetData(getClubPlayInfoEvent.avatarUrl);
|
|
}
|
|
}
|
|
private void OnDestroy()
|
|
{
|
|
disposable?.Dispose();
|
|
disposable = null;
|
|
}
|
|
}
|
|
public class OpponentItemData
|
|
{
|
|
public string playFabID;
|
|
//public string playName;
|
|
//public string url;
|
|
public string info;
|
|
public int BombID;
|
|
public float power;
|
|
public bool isRobot;
|
|
/// <summary>
|
|
/// 1=好友组, 2=非好友玩家组, 3=机器人组
|
|
/// </summary>
|
|
public int target_group;
|
|
/// <summary>
|
|
/// -1=机器人, 1=好友, 2=一日内活跃玩家, 3=排行榜玩家, 4=复仇玩家
|
|
/// </summary>
|
|
public int target_source;
|
|
}
|