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 LuaGetAttributeFunc; public int Side = 1; private void Start() { #if UNITY_EDITOR TryBindCharacter(); #endif } /// /// 尝试在lua端找到并绑定对应角色 /// 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 getFunc) { LuaGetAttributeFunc = getFunc; } public void TryGetAttributeFromLua() { int hashCode = gameObject.GetHashCode(); // 该脚本绑定的角色的hashcode if (LuaGetAttributeFunc != null) { LuaGetAttributeFunc(hashCode); } } /// /// 从lua端获取并刷新属性(lua调用的CS方法) /// public void GetAttribute(string attr) { UnitAttribute = JsonUtility.FromJson(attr); } } }