void SetNewAction(UnitActionBase action) { m_action = action; if (m_action != null) { MDebug.Log("^ui Button Set Action " + m_action.ActionID); //so we can test it also without owner if (action.GetOwner() != null) { inventory = action.GetOwner().Inventory; inventory.OnInventoryUpdated += OnInventoryUpdate; action.GetOwner().Stats.OnStatUpdated -= OnStatUpdated; if (Adr_Rush != null) { Adr_Rush.Init(action.GetOwner().Stats); } } action.OnSelectAction += OnActionSelect; action.OnUnselectAction += OnActionUnselect; action.OnActionComplete += OnActionComplete; action.OnActionStart += OnActionComplete; action.GetOwner().Stats.OnStatUpdated += OnStatUpdated; SetBaseState(m_action); } }
public void Init(Unit u, GameObject mesh) { m_Unit = u; int index = u.Inventory.EquipedWeapon.WeaponMesh.WeaponIndex; m_Unit.Actions.OnTargetAction += (a, b) => { UnitAnimator.SetAimTarget(b); }; m_Unit.Actions.OnActionStarted += action => { if (action.GetType() == typeof(UnitAction_Move)) { OnMoveStart(action as UnitAction_Move); } }; m_Unit.Stats.OnDmgReceived += () => { PlayAnimation(UnitAnimationTypes.bHit); }; rush = gameObject.AddComponent <UI_AdrenalineRushBase>(); rush.Init(u.Stats); rush.OnRushGain += () => { PlayAnimation(UnitAnimationTypes.bRage); }; UnitAnimator = UnitFactory.MakeUnitAnimations(mesh, u.Inventory.EquipedWeapon.WeaponMesh, index, mesh.AddComponent <AnimationCallbackCaster>(), () => { return(rush.HasRush); }); }
void Update() { if (m_Unit == null) { m_Unit = Unit.GetAllUnitsOfOwner(0, true).FirstOrDefault(); if (m_Unit != null) { rush = m_Unit.gameObject.AddComponent <UI_AdrenalineRushBase>(); rush.Init(m_Unit.Stats); rush.OnRushGain += OnRush; rush.EnableDelay = 3f; m_Unit.Stats.OnStatUpdated += UpdatedStat; m_Unit.Inventory.OnInventoryUpdated += UpdatedInventory; Unit.OnTurnStart += OnUnitStartTurn; } } }
void SetUnit(Unit _m_Unit) { m_Unit = _m_Unit; Unit.OnUnitKilled += CheckKilled; Unit.OnUnitSelect += CheckSelected; Unit.OnTurnStart += CheckStart; m_Unit.OnIdentify += Identify; m_Unit.OnDamageReceived += DmgReceived; m_Unit.Actions.OnActionStarted += ActionStarted; m_Unit.GetComponent <Unit_EffectManager>().OnEffectAdded += ReceivedEffect; rush = gameObject.AddComponent <UI_AdrenalineRushBase>(); rush.Init(m_Unit.Stats); rush.EnableDelay = 3f; if (Config.GainAdrRush != null) { rush.OnRushGain += () => { AttemptTrigger(Config.GainAdrRush); } } ; if (TurnSystem.Instance != null) { TurnSystem.Instance.OnGlobalTurn += ResetCounter; } } void ResetCounter(int c) { selectCounter = 0; } void Identify(Unit triggerer) { if (triggerer != null) { AttemptTrigger(Config.Identify); } } void ActionStarted(UnitActionBase action) { if (Config.UseAbility != null) { AttemptTrigger(Config.UseAbility, action.ActionID); } } void DmgReceived(UnitEffect_Damage dmg) { if (dmg.GetDamage() < m_Unit.Stats.GetStatAmount(StatType.oxygen)) { SpeechTriggerConfig trigger = dmg.GetDamage() > 3 ? Config.ReceiveDamageBig : Config.ReceiveDamageSmall; if (trigger != null) { AttemptTrigger(trigger); } } } void ReceivedEffect(UnitEffect effect) { if (Config.ReceiveEffect != null) { AttemptTrigger(Config.ReceiveEffect, effect.Unique_ID); } } void CheckKilled(Unit u) { if (u == m_Unit) { if (Config.Died != null) { AttemptTrigger(Config.Died); } Unit.OnUnitKilled -= CheckKilled; } } void CheckStart(Unit u) { if (u == m_Unit) { AttemptTrigger(Config.Turn); } } void CheckSelected(Unit u) { if (u == m_Unit) { selectCounter++; if (selectCounter == 4) { if (Config.Selected != null) { AttemptTrigger(Config.Selected); } } } }