protected override void Awake() { base.Awake(); //initialize data/variables mStats = GetComponent <StatEntityController>(); if (mStats) { mStats.HPChangedCallback += OnStatHPChanged; mStats.staminaChangedCallback += OnStatStaminaChanged; mStats.signalCallback += OnStatSignal; } mCellBind = GetComponent <CellBindController>(); mBody = GetComponent <Rigidbody2D>(); if (flock) { flock.enabled = false; mColl = flock.coll; } else { mColl = GetComponent <Collider2D>(); } }
protected override void OnStatHPChanged(StatEntityController aStats, float prev) { if (aStats.currentHP <= 0f) { state = (int)EntityState.Dead; } }
protected virtual void OnStatHPChanged(StatEntityController aStats, float prev) { if (aStats.currentHP <= 0f) { if (state != (int)EntityState.DeadInstant) { state = (int)EntityState.Dead; } } }
protected override void OnStatStaminaChanged(StatEntityController aStats, float prev) { //slow down //slow action rate float scale = aStats.currentStamina / aStats.data.stamina; if (flock) { flock.moveScale = scale; } }
protected virtual void OnStatSignal(StatEntityController aStats, GameObject sender, int signal, object data) { switch ((StatEntitySignals)signal) { case StatEntitySignals.Bind: //bind animation break; case StatEntitySignals.Unbind: //stop bind animation break; } }
void ClearSeek() { if (mSeekTriggeredStatCtrl) { if (mSeekTriggeredStatCtrl.isAlive) { mSeekTriggeredStatCtrl.SendSignal(gameObject, (int)StatEntitySignals.Unbind, null); } mSeekTriggeredStatCtrl = null; } mSeekTriggeredColl = null; }
void ApplySeekFromCollider(Collider2D coll) { if (coll && coll != mSeekTriggeredColl) { if (stats.data.IsSeekValid(coll.tag)) { //unbind prev. if (mSeekTriggeredStatCtrl) { mSeekTriggeredStatCtrl.SendSignal(gameObject, (int)StatEntitySignals.Unbind, null); } mSeekTriggeredColl = coll; mSeekTriggeredStatCtrl = coll.GetComponent <StatEntityController>(); } } }
// Use this for one-time initialization /*protected override void Start() { * base.Start(); * * //initialize variables from other sources (for communicating with managers, etc.) * }*/ protected override void OnStatHPChanged(StatEntityController aStats, float prev) { if (aStats.currentHP > 0f) { if (aStats.currentHP < prev) { if (mTakeHurtInd != -1) { animator.Play(mTakeHurtInd); } } //healed? return; } base.OnStatHPChanged(aStats, prev); }
protected override void OnStatHPChanged(StatEntityController aStats, float prev) { if (aStats.currentHP > 0f) { if (aStats.currentHP < prev) { mCurHurtDuration = stats.data.hurtDuration; if (mHurtRout == null) { mHurtRout = StartCoroutine(DoHurt()); } } //healed? return; } base.OnStatHPChanged(aStats, prev); }
protected override void OnStatSignal(StatEntityController aStats, GameObject sender, int signal, object data) { if (!stats.isAlive) { return; } switch ((StatEntitySignals)signal) { case StatEntitySignals.Bind: state = (int)EntityState.Bind; break; case StatEntitySignals.Unbind: //determine previous state state = (int)EntityState.Normal; break; } }
void SetBound(StatEntityController entStat) { if (mBoundEntityStat != entStat) { if (mBoundEntityStat != null) { mBoundEntityStat.SendSignal(gameObject, (int)StatEntitySignals.Unbind, null); } mBoundEntityStat = entStat; if (mBoundEntityStat != null) { transform.SetParent(mBoundEntityStat.transform, true); mBoundEntityStat.SendSignal(gameObject, (int)StatEntitySignals.Bind, null); } else { transform.SetParent(mDefaultParent, true); } } }
protected virtual void OnStatStaminaChanged(StatEntityController aStats, float prev) { }
public virtual void ProcessKill(Collider2D victimColl, StatEntityController victimStatCtrl, int score) { //default behaviour ScoreAt(victimStatCtrl.transform.position, score); }
IEnumerator DoVictimProcess(Collider2D coll, StatEntityController statCtrl, int score) { yield return(new WaitForSeconds(processDeathWaitDelay)); mVictimCount++; float deathProcessX = mucusFormBounds.center.x + Random.Range(processDeathPickUpXMin, processDeathPickUpXMax); float deathY = mucusFormBounds.center.y + processDeathPositionY; Transform trans = statCtrl.transform; //fall down Vector2 pos = trans.position; float yStart = pos.y; if (yStart != deathY) { var ease = DG.Tweening.Core.Easing.EaseManager.ToEaseFunction(DG.Tweening.Ease.InSine); float dist = Mathf.Abs(deathY - yStart); float delay = dist / processDeathFallSpeed; float curTime = 0f; while (curTime < delay) { yield return(null); curTime += Time.deltaTime; float t = Mathf.Clamp01(ease(curTime, delay, 0f, 0f)); trans.position = new Vector2(pos.x, Mathf.Lerp(yStart, deathY, t)); } } //move towards phagocyte float xStart = pos.x; if (xStart != deathProcessX) { float dist = Mathf.Abs(deathProcessX - xStart); float spd = Random.Range(processMoveSpeedMin, processMoveSpeedMax); float delay = dist / spd; float curTime = 0f; while (curTime < delay) { yield return(null); curTime += Time.deltaTime; float t = Mathf.Clamp01(curTime / delay); trans.position = new Vector2(Mathf.Lerp(xStart, deathProcessX, t), deathY - Mathf.Sin(curTime * processMoveWaveRate) * processMoveWaveHeight); } } //let it be eaten macrophage.Eat(statCtrl.GetComponent <M8.EntityBase>(), score); mVictimCount--; }
public override void ProcessKill(Collider2D victimColl, StatEntityController victimStatCtrl, int score) { //default behaviour //ScoreAt(victimStatCtrl.transform.position, score); StartCoroutine(DoVictimProcess(victimColl, victimStatCtrl, score)); }