173 lines
4.7 KiB
C#
173 lines
4.7 KiB
C#
using UnityEngine;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using Thousandto.GameUI.Form;
|
|
using Thousandto.Code.Center;
|
|
using Thousandto.Core.Base;
|
|
using Thousandto.Cfg.Data;
|
|
using System;
|
|
|
|
namespace Thousandto.Plugins.Common
|
|
{
|
|
//组件属性
|
|
public class MoneyAttr
|
|
{
|
|
#region//私有变量
|
|
private int _value = 0; //货币值
|
|
private int _iconId = 0; //货币图片id
|
|
private int _mult = 0; //倍数
|
|
#endregion
|
|
|
|
#region//公共变量
|
|
public int Value
|
|
{
|
|
get { return _value; }
|
|
set { _value = value; }
|
|
}
|
|
public int IconId
|
|
{
|
|
get { return _iconId; }
|
|
set { _iconId = value; }
|
|
}
|
|
#endregion
|
|
|
|
//获取货币组件数据
|
|
public MoneyAttr(string str, int mult = 1)
|
|
{
|
|
_mult = mult;
|
|
SetMoneyValue(str, this);
|
|
}
|
|
public MoneyAttr(int id,int num, int mult = 1)
|
|
{
|
|
_mult = mult;
|
|
_iconId = id;
|
|
_value = num * _mult;
|
|
|
|
}
|
|
public void ReSetMoneyValue(int id, int num, int mult)
|
|
{
|
|
_mult = mult;
|
|
_iconId = id;
|
|
_value = num * _mult;
|
|
}
|
|
|
|
public void ReSetMoneyValue(string str,int mult)
|
|
{
|
|
_mult = mult;
|
|
SetMoneyValue(str, this);
|
|
}
|
|
|
|
public void SetMoneyValue(int id, int num, MoneyAttr attr)
|
|
{
|
|
attr._iconId = id;
|
|
attr._value = num * attr._mult ;
|
|
}
|
|
//设置消耗货币组件的值
|
|
public void SetMoneyValue(string str, MoneyAttr attr)
|
|
{
|
|
char[] cs = new char[2];
|
|
cs[0] = ';';
|
|
cs[1] = '_';
|
|
List<SplitUtils.Analysis_Str> list = SplitUtils.AnalysisStr(cs, str);
|
|
if (list != null)
|
|
{
|
|
for (int i = 0; i < list.Count; i++)
|
|
{
|
|
if (list.Count == 1)
|
|
{
|
|
if (list[0].param.Length == 2)
|
|
{
|
|
if (_mult != 1)
|
|
{
|
|
attr.Value = _mult * list[0].param[1];
|
|
}
|
|
else
|
|
{
|
|
attr.Value = list[0].param[1];
|
|
}
|
|
attr.IconId = list[0].param[0];
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public class MoneyComponent : IUIComponentPlus<MoneyComponent, MoneyAttr>
|
|
{
|
|
|
|
#region//私有变量
|
|
private int _index = 0;
|
|
private Transform _trans = null;
|
|
private UILabel _text = null; //货币数量
|
|
private UISprite _icon = null; //货币图片
|
|
|
|
public int Index
|
|
{
|
|
get
|
|
{
|
|
return _index;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
public MoneyComponent(Transform trans)
|
|
{
|
|
if (trans != null)
|
|
{
|
|
_trans = trans;
|
|
_text = trans.Find("Money").RequireComponent<UILabel>();
|
|
_icon = trans.Find("Icon").RequireComponent<UISprite>();
|
|
}
|
|
}
|
|
|
|
#region//接口实现
|
|
public void SetActive(bool b)
|
|
{
|
|
if (_trans)
|
|
{
|
|
_trans.gameObject.SetActive(b);
|
|
}
|
|
}
|
|
|
|
//设置数据
|
|
public void SetData(MoneyAttr attr)
|
|
{
|
|
if (attr != null)
|
|
{
|
|
if (_text)
|
|
{
|
|
_text.text = attr.Value.ToString();
|
|
}
|
|
if (_icon)
|
|
{
|
|
UIIcon uiIcon = _trans.RequireComponent<UIIcon>();
|
|
if (uiIcon != null)
|
|
{
|
|
DeclareItem cfg = DeclareItem.Get(attr.IconId);
|
|
if (cfg != null)
|
|
{
|
|
uiIcon.UpdateIcon(cfg.Icon);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
public void SetSelect(bool b)
|
|
{
|
|
}
|
|
public MoneyComponent Clone(EventDelegate.Callback call,int index)
|
|
{
|
|
GameObject newGameObject = (GameObject)(GameObject.Instantiate(_trans.gameObject));
|
|
newGameObject.transform.parent = _trans.parent;
|
|
UnityUtils.Reset(newGameObject.transform);
|
|
MoneyComponent component = new MoneyComponent(newGameObject.transform);
|
|
return component;
|
|
}
|
|
public void Remove()
|
|
{ }
|
|
#endregion
|
|
}
|
|
}
|
|
|