69 lines
1.8 KiB
C#
69 lines
1.8 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using System;
|
|
|
|
namespace BF
|
|
{
|
|
[Serializable]
|
|
public class BattleUnitAttribute
|
|
{
|
|
public long hp = 0;
|
|
public long max_hp = 0;
|
|
public long atk = 0;
|
|
public long atk_red = 0;
|
|
public long atk_yellow = 0;
|
|
public long atk_green = 0;
|
|
public long atk_blue = 0;
|
|
public long atk_purple = 0;
|
|
public long sheild_hp = 0;
|
|
}
|
|
|
|
public class BattleUnitAttr : MonoBehaviour
|
|
{
|
|
[HideInInspector]
|
|
public BattleUnitAttribute UnitAttribute;
|
|
[HideInInspector]
|
|
public Action<int> LuaGetAttributeFunc;
|
|
public int Side = 1;
|
|
private void Start()
|
|
{
|
|
#if UNITY_EDITOR
|
|
TryBindCharacter();
|
|
#endif
|
|
}
|
|
|
|
/// <summary>
|
|
/// 尝试在lua端找到并绑定对应角色
|
|
/// </summary>
|
|
protected void TryBindCharacter()
|
|
{
|
|
int hashCode = gameObject.GetHashCode(); // 该脚本绑定的角色的hashcode
|
|
string lua = @"ModuleManager.BattleManager:bindBattleUnitAttribute({0}, {1})";
|
|
BFMain.Instance.LuaMgr.luaEnv.DoString(string.Format(lua, hashCode, Side));
|
|
}
|
|
|
|
public void BindGetAttributeFunc(Action<int> getFunc)
|
|
{
|
|
LuaGetAttributeFunc = getFunc;
|
|
}
|
|
|
|
public void TryGetAttributeFromLua()
|
|
{
|
|
int hashCode = gameObject.GetHashCode(); // 该脚本绑定的角色的hashcode
|
|
|
|
if (LuaGetAttributeFunc != null)
|
|
{
|
|
LuaGetAttributeFunc(hashCode);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 从lua端获取并刷新属性(lua调用的CS方法)
|
|
/// </summary>
|
|
public void GetAttribute(string attr)
|
|
{
|
|
UnitAttribute = JsonUtility.FromJson<BattleUnitAttribute>(attr);
|
|
}
|
|
}
|
|
} |