void Awake()
 {
     instance      = this;
     chrController = GetComponent <CharacterController>();
     anim          = GetComponentInChildren <Animator>();
     anim.SetInteger("State", (int)AnimType.Walk);
     NowAction                = ActionType.Walk;
     MapCollisionLayerMask    = LayerMask.GetMask("MapCollision");
     boxColliderHalfExtents.y = chrController.height * 0.5f - walkDownY;
     defaultLayer             = LayerMask.NameToLayer("Player");
     jumpLayer                = LayerMask.NameToLayer("Jump");
     forwardVector            = Vector3.right;
     splashParticle           = transform.Find("Splash").GetComponent <ParticleSystem>();
     splashParticle.transform.SetParent(null);
     Pivot             = transform.Find("Pivot");
     ActionBoxInstance = GetComponentInChildren <ActionBox>();
     naeActable        = null;
     ActionBoxInstance.Init();
 }
Esempio n. 2
0
 void Awake()
 {
     instance       = this;
     ChrController  = GetComponent <CharacterController>();
     waterAudio     = GetComponent <AudioSource>();
     stellaAnimator = transform.Find("Pivot").GetComponentInChildren <Animator>();
     stellaAnimator.SetInteger("State", (int)AnimType.Walk);
     NowAction = ActionType.Walk;
     boxColliderHalfExtents.y = ChrController.height * 0.5f - walkDownY;
     defaultLayer             = LayerMask.NameToLayer("Player");
     jumpLayer      = LayerMask.NameToLayer("Jump");
     forwardVector  = Vector3.right;
     splashParticle = transform.Find("Splash").GetComponent <ParticleSystem>();
     splashParticle.transform.SetParent(null);
     Pivot             = transform.Find("Pivot");
     ActionBoxInstance = GetComponentInChildren <ActionBox>();
     naeActable        = null;
     ActionBoxInstance.Init();
     SoundController.audioListener.enabled  = false;
     GetComponent <AudioListener>().enabled = true;
 }
Esempio n. 3
0
        /// <summary>
        /// 最寄りのアクション可能なオブジェクトのインスタンスを返します。
        /// </summary>
        /// <returns>有効なオブジェクトがあればnull以外のインスタンスを返します。</returns>
        public Actable GetActableInstance()
        {
            Vector3 ofs = colliderCenter;

            ofs.x *= StellaMove.forwardVector.x;
            Vector3 center = StellaMove.instance.transform.position + ofs;

            int hitCount = (Physics.BoxCastNonAlloc(center, halfExtents, StellaMove.forwardVector, hits, Quaternion.identity, 0f, layerMask));

            int lastActableCount = actableCount;

            for (int i = 0; i < lastActableCount; i++)
            {
                lastActables[i] = actables[i];
            }

            // 列挙するものがなければこの場でnullを返す
            if (hitCount == 0)
            {
                if (SelectedActable != null)
                {
                    SelectedActable.Deselect();
                }
                SelectedActable = null;
                return(null);
            }

            // 今回のものを列挙
            float   min        = float.PositiveInfinity;
            Actable nextSelect = null;

            for (int i = 0; i < hitCount; i++)
            {
                Actable[] hitActs = hits[i].collider.GetComponents <Actable>();

                for (int j = 0; j < hitActs.Length; j++)
                {
                    if (hitActs[j] == null || !hitActs[j].CanAction)
                    {
                        continue;
                    }

                    // 距離の更新確認
                    float dist = Mathf.Abs(transform.position.x - hits[i].transform.position.x);

                    if (hitActs[j] is NaeActable)
                    {
                        NaeActable naeAct = hitActs[j] as NaeActable;
                        float      tx     = hitActs[j].transform.position.x - (StellaMove.NaePutDownOffsetX + naeAct.NaeOffsetX) * StellaMove.forwardVector.x;

                        dist = Mathf.Abs(transform.position.x - tx);
                    }

                    if (dist < min)
                    {
                        min        = dist;
                        nextSelect = hitActs[j];
                    }
                }
            }

            if (SelectedActable != nextSelect)
            {
                if (SelectedActable != null)
                {
                    SelectedActable.Deselect();
                }
                if (nextSelect != null)
                {
                    nextSelect.Select();
                }
            }
            SelectedActable = nextSelect;

            return(SelectedActable);
        }
Esempio n. 4
0
 /// <summary>
 /// 指定の苗を拾うときのステラがいるべきX座標を返します。
 /// </summary>
 /// <param name="naeAct">拾う苗のインスタンス</param>
 /// <returns>目的の苗を拾う時のステラのX座標</returns>
 public static float NaeWalkTarget(NaeActable naeAct)
 {
     return(naePutPosition.x - (NaePutDownOffsetX + naeAct.NaeOffsetX) * forwardVector.x);
 }