void OnTriggerExit(Collider _collider) { var tag = _collider.gameObject.tag; var layer = _collider.gameObject.layer; if (layer == (int)Common.GAMEOBJECT_LAYER.GROUND_UNDER) { mCollision.isTrigger = false; } if (tag == Common.GetGameObjectTagName(Common.GAMEOBJECT_TAG.TOWER)) { var tower = _collider.gameObject.GetComponent <UnitManagerTower>(); if (tower.TeamId == mTeamId) { mUnitState &= ~UNIT_STATE.IS_HIT_TOWER; } } if (tag == Common.GetGameObjectTagName(Common.GAMEOBJECT_TAG.LADDER)) { mUnitState &= ~UNIT_STATE.IS_HIT_LADDER; } if (tag == Common.GetGameObjectTagName(Common.GAMEOBJECT_TAG.CREATE_LOCATION)) { var unitCreate = _collider.gameObject.GetComponent <UnitManagerCreateLocation>(); mUnitState &= ~UNIT_STATE.IS_HIT_CREATE_LOCATION; mCurrentCreateLocation = null; mUICreateUnitProperty.gameObject.SetActive(false); mUIUnitCreateLocationDish.gameObject.SetActive(false); mUIPlayerUnitProperty.SetIsInput(true); } }
// set action private void setAction(UNIT_STATE state) { for (int i = 0; i < m_Units.Length; ++i) { m_Units[i].SetAction(state); } }
/**********************************************************************************/ // обработчик смерти // может переопределяться для специальной обработки смерти, к примеру боссами // данная функция должна быть подключена к m_armor компоненту // /**********************************************************************************/ protected virtual void OnDead(DamageData finalStrikeData) { m_state = UNIT_STATE.FAILING; foreach (var animator in m_animators) { animator.SetTrigger("isFailing"); } // сообщаем котроллеру о том, что нас можно не учитывать GameObjectMapController.GetInstance().ReleaseUnitFromMap(this); // сообщаем зданию производившему это существо о том, что юнит погиб и оно может производить следующий объект if (m_productionBase != null) { m_productionBase.ReleaseProduction(m_unitID); } // проверяем дроп CheckUnitDrop(); // увеличиваем счётчик очков игрока за убийство int killerID = finalStrikeData.Damager.Owner; if (killerID != Owner) { GameManager.GetInstance().IncreasePlayerScoreUnitLose((PLAYER)killerID, scoreCost); } }
private IEnumerator Doge(Vector3 _dir) { if (!GetIsUnitState(UNIT_STATE.CAN_DOGE)) { yield break; } mUnitState &= ~UNIT_STATE.CAN_DOGE; mFxDoge.SetActive(true); var velocity = _dir * 10f; this.gameObject.GetComponent <Rigidbody>().AddForce(velocity, ForceMode.VelocityChange); mCurrentStamina -= 2f; mIsDaamge = false; yield return(new WaitForSeconds(0.3f)); mIsDaamge = true; yield return(new WaitForSeconds(0.5f)); mFxDoge.SetActive(false); mUnitState |= UNIT_STATE.CAN_DOGE; yield return(null); }
//------------------------------------------------------------------------------------- // set action //------------------------------------------------------------------------------------- public override void SetAction(UNIT_STATE state) { m_State = state; m_IsAction = true; m_Stater.Change(state); }
private bool GetIsUnitState(UNIT_STATE _state) { if ((mUnitState & _state) == _state) { return(true); } return(false); }
protected override void Awake() { base.Awake(); animator = GetComponent <Animator>(); spriteRenderer = GetComponent <SpriteRenderer>(); state = UNIT_STATE.IDLE; objectType = OBJECT_TYPE.UNITS; actionDelayTimer = actionDelayDuration; }
public void MoveTo(Vector2 pos) { Tilemap tilemap = TileSystem.Instance.TileMap; state = UNIT_STATE.MOVE; animator.SetInteger("state", 1); path = new Queue <TileScript>( TileSystem.Instance.GetFoundPath( currentTile, TileSystem.Instance.GetTileScript(pos))); }
private IEnumerator GetItem(ItemData _data) { if (!GetIsUnitState(UNIT_STATE.IS_GET_ITE)) { yield break; } mUnitState &= ~UNIT_STATE.IS_GET_ITE; mPropertyList.Add(_data); yield return(new WaitForEndOfFrame()); mUnitState |= UNIT_STATE.IS_GET_ITE; }
/**********************************************************************************/ // обработчик отключения юнита // дожидается окончания анимации смерти // снимает все наложенные на существо эффекты и везвращает в пулл ObjectFactory // /**********************************************************************************/ protected virtual void OnFailing() { // предполагаем, что все аниматоры синхронизованы по тайменгам между собой // используем первый аниматор для индикации конца анимации Animator animator = m_animators[0]; if (animator.GetCurrentAnimatorStateInfo(0).IsName("Base_Layer.EndOfAnimation")) { gameObject.SetActive(false); m_state = UNIT_STATE.DIED; // деактивируем все эффекты m_effectMaster.DeactivateEffects(); // ресетим модификаток скорости speedMultiplier = 1.0f; ObjectFactory.GetInstance().ReturnObjectToCash(gameObject, GOType); // возвращаем объект в кеш фабрики объектов } }
private IEnumerator Jump() { if (!GetIsUnitState(UNIT_STATE.IS_JUMP)) { yield break; } mUnitState &= ~UNIT_STATE.IS_JUMP; mCurrentJumpCount++; this.transform.GetComponent <Rigidbody>().AddForce(Vector3.up * 800f); yield return(new WaitForEndOfFrame()); if (mCurrentJumpCount < mLimitJumpCount) { mUnitState |= UNIT_STATE.IS_JUMP; } yield return(null); }
protected virtual void Move() { if (path == null || path.Count <= 0) { state = UNIT_STATE.IDLE; animator.SetInteger("state", 0); return; } Vector3 direction = (path.Peek().transform.position + new Vector3(1.25f, 1.25f)) - transform.position; lastTile = currentTile; // Set sprite direction animator.SetFloat("moveX", direction.x); animator.SetFloat("moveY", direction.y); if (direction.x < 0.0f) { spriteRenderer.flipX = true; } else if (direction.x > 0.0f) { spriteRenderer.flipX = false; } if (direction.sqrMagnitude < 0.01f) { currentTile.UnitExitTile(this.gameObject); currentTile = path.Peek(); currentTile.UnitEnterTile(this.gameObject); path.Dequeue(); } Vector3 newPosition = transform.position + direction.normalized * moveSpeed * Time.deltaTime; transform.position = newPosition; }
public void AttackTarget(BaseObject go) { target = go; state = UNIT_STATE.ATTACK; path = new Queue <TileScript>(TileSystem.Instance.GetFoundPath(currentTile, go.CurrentTile, false)); }
void FixedUpdate() { if (mIsDead) { this.transform.GetComponent <Rigidbody>().isKinematic = true; return; } else { this.transform.GetComponent <Rigidbody>().isKinematic = false; } if (!GetIsUnitState(UNIT_STATE.IS_PUSE)) { //------------ // 左右奥行き移動 var moveX = Input.GetAxisRaw("joycon_horizontal_" + mPlayerId); var moveZ = Input.GetAxisRaw("joycon_vertical_" + mPlayerId) * 0.75f; // 奥行きの移動を通常の半分に制限 var moveY = 0f; if (GetIsUnitState(UNIT_STATE.IS_HIT_LADDER)) { this.transform.GetComponent <Rigidbody>().useGravity = false; if (moveZ != 0) { moveY = Mathf.Abs(moveZ); } if (moveX != 0) { moveY = Mathf.Abs(moveX); } } var moveVelocity = new Vector3(moveX, moveY, moveZ) * MoveValue; if (moveX != 0 && moveZ != 0) { moveVelocity = moveVelocity * 0.75f; } if (GetIsUnitState(UNIT_STATE.IS_DASH)) { moveVelocity = moveVelocity * 1.5f; } //------------ // 向き変更 : 移動先 or エイムターゲット(+移動量下げる) if (mUnitBattleTarget == null) { if (moveX != 0 || moveZ != 0) { var lookDir = new Vector3(moveVelocity.x, 0f, moveVelocity.z); mBody.rotation = Quaternion.LookRotation(lookDir); } } else { var look = mUnitBattleTarget.transform.position; look.y = mBody.transform.position.y; mBody.transform.LookAt(look); moveVelocity = moveVelocity * 0.75f; } //----------- // キャラクター移動 this.transform.position += moveVelocity; //----------- // 歩きアニメーション if (moveX != 0 || moveZ != 0) { if (!mAnimation.IsPlaying("Attack")) { mBody.gameObject.GetComponent <Animation>().CrossFade("Walk"); } } //------------ // スキル if (Input.GetButtonDown("joycon_button_1_" + mPlayerId) && Input.GetButtonDown("joycon_button_3_" + mPlayerId)) { OnSkill(2); } else if (Input.GetButtonDown("joycon_button_1_" + mPlayerId)) { OnSkill(0); // motion if (!mAnimation.IsPlaying("Attack")) { mAnimation.CrossFade("Attack"); } } else if (Input.GetButtonDown("joycon_button_3_" + mPlayerId)) { OnSkill(1); } //------------ // 通り抜け if (Input.GetButton("joycon_sr_" + mPlayerId)) { mUnitState |= UNIT_STATE.IS_MOVE_DOWN; } else { mUnitState &= ~UNIT_STATE.IS_MOVE_DOWN; } } if (!mAnimation.isPlaying) { mBody.GetComponent <Animation>().CrossFade("Wait"); } if (!GetIsUnitState(UNIT_STATE.IS_HIT_LADDER)) { this.transform.GetComponent <Rigidbody>().useGravity = true; this.transform.GetComponent <Rigidbody>().AddForce(Vector3.up * -20f); } }
void OnTriggerStay(Collider _collider) { var tag = _collider.gameObject.tag; var layer = _collider.gameObject.layer; if (layer == (int)Common.GAMEOBJECT_LAYER.FIELD && tag == Common.GetGameObjectTagName(Common.GAMEOBJECT_TAG.SEMITRANSPARENT)) { if (GetIsUnitState(UNIT_STATE.IS_MOVE_DOWN)) { mCollision.isTrigger = true; } } if (tag == Common.GetGameObjectTagName(Common.GAMEOBJECT_TAG.ITEM) && GetIsUnitState(UNIT_STATE.IS_GET_ITE)) { var itemObj = _collider.gameObject.GetComponent <ItemObject>(); if (mPropertyList.Count < PropertyMax) { StartCoroutine(GetItem(itemObj.Data)); Destroy(itemObj.gameObject); } } if (tag == Common.GetGameObjectTagName(Common.GAMEOBJECT_TAG.TOWER)) { var tower = _collider.gameObject.GetComponent <UnitManagerTower>(); if (tower.TeamId == mTeamId) { mUnitState |= UNIT_STATE.IS_HIT_TOWER; } } if (tag == Common.GetGameObjectTagName(Common.GAMEOBJECT_TAG.CREATE_LOCATION)) { var unitCreateLocation = _collider.gameObject.GetComponent <UnitManagerCreateLocation>(); if (unitCreateLocation.PropertyDishData != null) { } } if (tag == Common.GetGameObjectTagName(Common.GAMEOBJECT_TAG.LADDER)) { mUnitState |= UNIT_STATE.IS_HIT_LADDER; } if (tag == Common.GetGameObjectTagName(Common.GAMEOBJECT_TAG.CREATE_LOCATION)) { var unitCreateLocation = _collider.gameObject.GetComponent <UnitManagerCreateLocation>(); if (unitCreateLocation.TeamId == mTeamId) { mUnitState |= UNIT_STATE.IS_HIT_CREATE_LOCATION; mCurrentCreateLocation = unitCreateLocation; if (mCurrentCreateLocation.PropertyDishData != null) { mUnitState |= UNIT_STATE.IS_HIT_DISH_LOCATION; if (!mUIUnitCreateLocationDish.gameObject.activeSelf) { mUIUnitCreateLocationDish.gameObject.SetActive(true); mUIUnitCreateLocationDish.SetDishData(mCurrentCreateLocation.PropertyDishData); mUICreateUnitProperty.gameObject.SetActive(false); } } else { mUnitState &= ~UNIT_STATE.IS_HIT_DISH_LOCATION; if (!mUICreateUnitProperty.gameObject.activeSelf) { mUICreateUnitProperty.gameObject.SetActive(true); mUICreateUnitProperty.SetPropertyList(mCurrentCreateLocation.ItemDataList, mCurrentCreateLocation.PropertyMax); mUICreateUnitProperty.SetIsInput(false); mUIUnitCreateLocationDish.gameObject.SetActive(false); } } } else { mCurrentCreateLocation = null; mUnitState &= ~UNIT_STATE.IS_HIT_CREATE_LOCATION; mUnitState &= ~UNIT_STATE.IS_HIT_DISH_LOCATION; } } }
protected override void Update() { base.Update(); mUIStatusLevel.text = "Lv." + mStatus.Level; mUIStatusHpGauge.value = mHpGauge.value; //------------------------------------ // 地面についているか if (mUnitLeg.IsJump) { mUnitState |= UNIT_STATE.IS_JUMP; mCurrentJumpCount = 0; } else { mUnitState &= ~UNIT_STATE.IS_JUMP; } //------------------------------------ // 所持アイテムチェンジ //------------ if (Input.GetButtonDown("joycon_sl_" + mPlayerId) && Input.GetButtonDown("joycon_sr_" + mPlayerId)) { if (mUICreateUnitProperty.gameObject.activeSelf) { if (mUIPlayerUnitProperty.IsInput) { mUICreateUnitProperty.SetIsInput(true); mUIPlayerUnitProperty.SetIsInput(false); } else { mUICreateUnitProperty.SetIsInput(false); mUIPlayerUnitProperty.SetIsInput(true); } } } else if (Input.GetButtonDown("joycon_sr_" + mPlayerId)) { if (mUIPlayerUnitProperty.IsInput) { mUIPlayerUnitProperty.UpdateInput(true); } else if (mUICreateUnitProperty.IsInput) { mUICreateUnitProperty.UpdateInput(true); } } else if (Input.GetButtonDown("joycon_sl_" + mPlayerId)) { if (mUIPlayerUnitProperty.IsInput) { mUIPlayerUnitProperty.UpdateInput(false); } else if (mUICreateUnitProperty.IsInput) { mUICreateUnitProperty.UpdateInput(false); } } //------------------------------------ // アクションボタン if (Input.GetButton("joycon_button_2_" + mPlayerId)) { mActionButtonTimer += Time.deltaTime; if (mActionButtonTimer > mButtonSwtichGapTime) { mUIButtonDescription.ButtonPushed(mActionButtonTimer - mButtonSwtichGapTime, mActionButtonSwitchTime - mButtonSwtichGapTime); } if (mActionButtonSwitchTime < mActionButtonTimer) { if (GetIsUnitState(UNIT_STATE.IS_HIT_CREATE_LOCATION)) { StartCoroutine(OnItemUseToCreateLocation()); } else { StartCoroutine(OnItemUse()); } mUnitState |= UNIT_STATE.IS_PUSHED_ACTION_BUTTON; mActionButtonTimer = -mButtonSwtichGapTime; mUIButtonDescription.ResetButtonPushed(); } } if (Input.GetButtonUp("joycon_button_2_" + mPlayerId)) { if (mActionButtonTimer > 0f && mActionButtonTimer < mButtonSwtichGapTime && !GetIsUnitState(UNIT_STATE.IS_PUSHED_ACTION_BUTTON)) { if (GetIsUnitState(UNIT_STATE.IS_HIT_CREATE_LOCATION)) { if (GetIsUnitState(UNIT_STATE.IS_HIT_DISH_LOCATION)) { StartCoroutine(OnTeakDishForCreateLocation()); } else { StartCoroutine(OnItemDropToCreateLocation()); } } else { StartCoroutine(OnItemDrop()); } } mUnitState &= ~UNIT_STATE.IS_PUSHED_ACTION_BUTTON; mUIButtonDescription.ResetButtonPushed(); mActionButtonTimer = 0; } if (GetIsUnitState(UNIT_STATE.IS_HIT_CREATE_LOCATION)) { if (mActionButtonTimer > mButtonSwtichGapTime) { mUIButtonDescription.SetText("料理を開始する"); } else if (GetIsUnitState(UNIT_STATE.IS_HIT_DISH_LOCATION)) { mUIButtonDescription.SetText("料理をとる"); } else { mUIButtonDescription.SetText("食材をいれる"); } } else { if (mActionButtonTimer > mButtonSwtichGapTime) { mUIButtonDescription.SetText("食べる!"); } else { mUIButtonDescription.SetText("アイテムドロップ"); } } //------------------------------------ // スティック押し込み if (Input.GetButtonDown("joycon_button_stick_" + mPlayerId)) { if (mUnitBattleTarget == null) { if (mScoutUnitPlayer.NearUnitEnemy != null) { mUnitBattleTarget = mScoutUnitPlayer.NearUnitEnemy; } } else { mUnitBattleTarget = null; } mAimBatlleTarget.SetTarget(mUnitBattleTarget == null ? null : mUnitBattleTarget.transform); } //------------------------------------ // ダッシュ if (Input.GetButton("joycon_button_0_" + mPlayerId)) { mInteractiveButtonTimer += Time.deltaTime; if (mInteractiveButtonTimer > mInteractiveButtonSwitchTime) { mUnitState |= UNIT_STATE.IS_DASH; mCurrentStamina -= Time.deltaTime; if (!mFxTireSmoke.isPlaying && !mFxTireSmoke.main.loop) { mFxTireSmoke.Play(); var main = mFxTireSmoke.main; main.loop = true; } } } else { var main = mFxTireSmoke.main; main.loop = false; mUnitState &= ~UNIT_STATE.IS_DASH; } //------------ // ジャンプ if (Input.GetButtonUp("joycon_button_0_" + mPlayerId)) { if (mInteractiveButtonTimer < mButtonSwtichGapTime) { if (mUnitBattleTarget == null) { StartCoroutine(Jump()); } else { var moveX = Input.GetAxisRaw("joycon_horizontal_" + mPlayerId); var moveZ = Input.GetAxisRaw("joycon_vertical_" + mPlayerId); StartCoroutine(Doge(new Vector3(moveX, 0f, moveZ))); } } mUnitState &= ~UNIT_STATE.IS_DASH; mInteractiveButtonTimer = 0f; } //------------------------------------ // スタミナゲージ更新 if (mCurrentStamina < 0f) { mCurrentHp -= Time.deltaTime * 0.5f; } else { mCurrentStamina -= Time.deltaTime * 0.5f; } mStaminaGauge.value = mCurrentStamina / mStatus.Stamina; }
//------------------------------------------------------------------------------------- // set action //------------------------------------------------------------------------------------- public virtual void SetAction(UNIT_STATE state) { }
/**********************************************************************************************/ // функция установки дефолтных параметров юнита // /**********************************************************************************************/ public virtual void SetDefaultParameter() { m_state = UNIT_STATE.ACTIVE; m_armor.SetHealth(health); }