Exemplo n.º 1
0
            public override bool Action()
            {
                if (AICtrl.StateMachineAnimator.GetBool("IsDead"))
                {
                    Interrupt();
                }
                MovementControls mvmt        = AICtrl.MvmntCmp;
                SwitchDirection  dirSwitcher = AICtrl.DirSwitcherCmp;

                mvmt.SetVelocityX((mvmt.RunSpeed / 2) * dirSwitcher.Direction);
                //if(this.origAnimatorSpeed == -1)
                //    this.origAnimatorSpeed = AACmp.AnimatorCmp.speed;

                //AACmp.AnimatorCmp.speed = this.wanderAnimatorSpeed;

                float timePassed = Time.timeSinceLevelLoad - this.timeSinceLastWander;

                if (timePassed <= 1)
                {
                    return(false);
                }

                this.timeSinceLastWander = Time.timeSinceLevelLoad;
                int randDir = Random.Range(0, 2);

                randDir = randDir == 0 ? -1 : 1;
                dirSwitcher.OnSwitchDirection(randDir);
                return(true);
            }//Action
Exemplo n.º 2
0
        private void Switch(SwitchDirection direction)
        {
            // Get list of avaible images
            List <String> bitmapKeys = new List <string>(bitmap.Keys);

            int bitmapKeysIndex = bitmapKeys.IndexOf(bitmapCurrent);

            switch (direction)
            {
            case SwitchDirection.Left:
                if (bitmapKeysIndex > 0)
                {
                    Switch(bitmapKeys[bitmapKeysIndex - 1]);
                }
                else
                {
                    Switch(bitmapKeys[bitmapKeys.Count - 1]);
                }
                break;

            case SwitchDirection.Right:
                if (bitmapKeysIndex < bitmapKeys.Count - 1)
                {
                    Switch(bitmapKeys[bitmapKeysIndex + 1]);
                }
                else
                {
                    Switch(bitmapKeys[0]);
                }
                break;
            }
        }
Exemplo n.º 3
0
 public bool IsInReachOfSwitch(Transform _transform, SwitchDirection switchDir)
 {
     if (DistanceTo(_transform.position) <= interactionDistance)
     {
         if (switchDir == SwitchDirection.up && transform.position.y > _transform.position.y)
         {
             return(true);
         }
         else if (switchDir == SwitchDirection.down && transform.position.y < _transform.position.y)
         {
             return(true);
         }
         else if (switchDir == SwitchDirection.right && transform.position.x < _transform.position.x)
         {
             return(true);
         }
         else if (switchDir == SwitchDirection.left && transform.position.x < _transform.position.x)
         {
             return(true);
         }
         else
         {
             return(false);
         }
     }
     else
     {
         return(false);
     }
 }
Exemplo n.º 4
0
    Vector3 SwitchPosition(SwitchDirection direction)
    {
        Vector3 pos = mSelectCenter;

        if (m_DragMode == DragMode.Horizontal)
        {
            if (direction == SwitchDirection.Positive)
            {
                pos.x += m_BoundsDis;
            }
            else if (direction == SwitchDirection.Negative)
            {
                pos.x -= m_BoundsDis;
            }
        }
        else
        {
            if (direction == SwitchDirection.Positive)
            {
                pos.y -= m_BoundsDis;
            }
            else if (direction == SwitchDirection.Negative)
            {
                pos.y += m_BoundsDis;
            }
        }

        return(pos);
    }
Exemplo n.º 5
0
 /// <summary>
 /// The feedback timeout of the given switch it reached.
 /// Set the actual direction.
 /// </summary>
 private void OnSwitchFeedbackTimeout(ISwitchState @switch, SwitchDirection requestedDirection)
 {
     if (@switch.Direction.Requested == requestedDirection)
     {
         @switch.Direction.Actual = requestedDirection;
         Log.Debug("Switch feedback time for {0}", @switch);
     }
 }
Exemplo n.º 6
0
        /// <summary>
        /// Forward direction request to command station
        /// </summary>
        private void OnRequestedDirectionChanged(SwitchDirection value)
        {
            var cs = CommandStation;

            if (cs != null)
            {
                cs.SendSwitchDirection(this);
            }
        }
Exemplo n.º 7
0
 public static bool SwitchInReach(Transform _transform, SwitchDirection switchDir)
 {
     if (PlayerScript != null)
     {
         return(PlayerScript.IsInReachOfSwitch(_transform, switchDir));
     }
     else
     {
         return(false);
     }
 }
Exemplo n.º 8
0
        /// <summary>
        /// Send the direction of the given switch towards the railway.
        /// This method is called on my worker thread.
        /// </summary>
        private void SendSwitchRequest(Address address, SwitchDirection direction, bool invertDirection)
        {
            Log.Trace("Send: SwitchRequest: address={0}, direction={1}", address.Value, direction);
            var msg = new SwitchRequest();

            msg.Address   = address.ValueAsInt - 1;
            msg.Direction = (direction == SwitchDirection.Straight);
            if (invertDirection)
            {
                msg.Direction = !msg.Direction;
            }
            msg.Output = true;
            msg.Execute(lb);
        }
Exemplo n.º 9
0
 public void ChangeSwitchState()
 {
     if (SwitchDirection == SwitchDirection.MIDDLE)
     {
         SwitchDirection = SwitchDirection.UP;
         this._char = '/';
     }
     else if (SwitchDirection == SwitchDirection.UP)
     {
         SwitchDirection = SwitchDirection.DOWN;
         this._char = '\\';
     }
     else if (SwitchDirection == SwitchDirection.DOWN)
     {
         SwitchDirection = SwitchDirection.UP;
         this._char = '/';
     }
 }
Exemplo n.º 10
0
 public void ChangeSwitchState()
 {
     if (SwitchDirection == SwitchDirection.MIDDLE)
     {
         SwitchDirection = SwitchDirection.UP;
         this._char      = '/';
     }
     else if (SwitchDirection == SwitchDirection.UP)
     {
         SwitchDirection = SwitchDirection.DOWN;
         this._char      = '\\';
     }
     else if (SwitchDirection == SwitchDirection.DOWN)
     {
         SwitchDirection = SwitchDirection.UP;
         this._char      = '/';
     }
 }
Exemplo n.º 11
0
    bool CanSwitchDirection(SwitchDirection direction)
    {
        if (direction == SwitchDirection.Negative)
        {
            if (mNeedSync || mCurrentIndex < 0 || mCurrentIndex + 1 >= mCellCount)
            {
                return(false);
            }
        }
        else if (direction == SwitchDirection.Positive)
        {
            if (mNeedSync || mCurrentIndex <= 0)
            {
                return(false);
            }
        }

        return(true);
    }
Exemplo n.º 12
0
    void OnCellFree()
    {
        if (mCurrentCell != null && mCurrentCell.Value != null)
        {
            Vector3 srcPos = mCurrentCell.Value.transform.localPosition;
            Vector3 desPos = srcPos + mInertiaOffset;

            RestrictInBounds(ref desPos);
            Vector3 desOffset = desPos - mSelectCenter;

            if (desOffset.magnitude >= m_SwitchDis)                     // need to switch cell
            {
                SwitchDirection srcDirection = TargetDirection(srcPos);
                SwitchDirection desDirection = TargetDirection(desPos);

                if (srcDirection == desDirection)
                {
                    mSlidePos = SwitchPosition(desDirection);
                }
                else
                {
                    if (srcDirection == SwitchDirection.None && CanSwitchDirection(desDirection))
                    {
                        mSlidePos = SwitchPosition(desDirection);
                    }
                    else
                    {
                        mSlidePos = SwitchPosition(SwitchDirection.None);
                    }
                }
            }
            else
            {
                mSlidePos = SwitchPosition(SwitchDirection.None);
            }

            mSlide = true;
        }

        mInertiaOffset = Vector3.zero;
    }
Exemplo n.º 13
0
    void ResetPrepareCell(SwitchDirection direction)
    {
        mPreparedCell  = null;
        mPreparedIndex = -1;

        if (CanSwitchDirection(direction))
        {
            if (direction == SwitchDirection.Negative)
            {
                if (mCurrentCell.Next != null)
                {
                    mPreparedCell  = mCurrentCell.Next;
                    mPreparedIndex = mCurrentIndex + 1;
                }
                else
                {
                    if (m_CellMode == CellMode.Dynamic)
                    {
                        mPreparedCell  = mCellList.First;
                        mPreparedIndex = mCurrentIndex + 1;
                    }
                }
            }
            else if (direction == SwitchDirection.Positive)
            {
                if (mCurrentCell.Previous != null)
                {
                    mPreparedCell  = mCurrentCell.Previous;
                    mPreparedIndex = mCurrentIndex - 1;
                }
                else
                {
                    if (m_CellMode == CellMode.Dynamic)
                    {
                        mPreparedCell  = mCellList.Last;
                        mPreparedIndex = mCurrentIndex - 1;
                    }
                }
            }
        }
    }
Exemplo n.º 14
0
    public bool ChangeLane(SwitchDirection dir, ref float targetHeight)
    {
        if (dir == SwitchDirection.Up)
        {
            if ((int)playerLane + 1 < nLanes)
            {
                playerLane  += 1;
                targetHeight = highLaneHeight;
                return(true);
            }
        }

        if (dir == SwitchDirection.Down)
        {
            if ((int)playerLane - 1 >= 0)
            {
                playerLane  -= 1;
                targetHeight = lowLaneHeight;
                return(true);
            }
        }

        return(false);
    }
 /// <summary>
 /// Move to the next possible state
 /// </summary>
 public override void ToggleState()
 {
     Direction = Direction.Invert();
 }
 /// <summary>
 /// Add the given item to this set
 /// </summary>
 public void Add(ISwitch item, SwitchDirection direction)
 {
     Add(new SwitchWithState((Switch)item, direction));
 }
Exemplo n.º 17
0
 /// <summary>
 /// Gets the inverted direction.
 /// </summary>
 public static SwitchDirection Invert(this SwitchDirection value)
 {
     return((value == SwitchDirection.Straight) ? SwitchDirection.Off : SwitchDirection.Straight);
 }
Exemplo n.º 18
0
 /// <summary>
 /// Default ctor
 /// </summary>
 public SwitchWithState(Switch junction, SwitchDirection direction)
     : this()
 {
     Junction  = junction;
     Direction = direction;
 }
Exemplo n.º 19
0
    void Update()
    {
        if (mSlide && mCurrentCell != null && mCurrentCell.Value != null)
        {
            Vector3 offset = mSlidePos - mCurrentCell.Value.transform.localPosition;

            if (!Mathf.Approximately(offset.magnitude, 0f))
            {
                if (mSlideSpeed.magnitude < offset.magnitude)
                {
                    SwitchDirection direction = OffsetDirection(offset);
                    if (direction == SwitchDirection.Positive)
                    {
                        mCurrentCell.Value.transform.localPosition += mSlideSpeed;
                    }
                    else if (direction == SwitchDirection.Negative)
                    {
                        mCurrentCell.Value.transform.localPosition -= mSlideSpeed;
                    }
                }
                else
                {
                    mCurrentCell.Value.transform.localPosition = mSlidePos;
                }

                if (mPreparedCell != null && mPreparedCell.Value != null)
                {
                    ZoomCell(mPreparedCell.Value, mCurrentCell.Value.transform.localPosition);
                    AlphaCell(mPreparedCell.Value, mCurrentCell.Value.transform.localPosition);
                }
            }
            else
            {
                ResetCell();
                if (mPreparedCell != null && mPreparedCell.Value != null)
                {
                    SwitchDirection direction = TargetDirection(mSlidePos);
                    if (direction != SwitchDirection.None)
                    {
                        HideCell(mCurrentCell.Value);

                        mCurrentCell  = mPreparedCell;
                        mCurrentIndex = mPreparedIndex;
                        SelectCell(mCurrentCell.Value, mCurrentIndex);

                        ResetPrepareCell(SwitchDirection.None);
                    }
                    else
                    {
                        HideCell(mPreparedCell.Value);
                        ResetPrepareCell(SwitchDirection.None);
                    }
                }

                mSlide    = false;
                mSlidePos = mSelectCenter;
            }
        }

        UpdateScroll();

        // attenuate the inertia
        NGUIMath.SpringDampen(ref mInertiaOffset, 9f, 0.025f);
    }
Exemplo n.º 20
0
 /// <summary>
 /// Default ctor
 /// </summary>
 public SwitchWithState(ISwitchState @switch, SwitchDirection direction)
 {
     this.@switch   = @switch;
     this.direction = direction;
 }
Exemplo n.º 21
0
    void OnCellDrag(Vector3 offset)
    {
        if (mCurrentCell != null && mCurrentCell.Value != null)
        {
            if (!Mathf.Approximately(offset.magnitude, 0f))
            {
                Vector3 srcPos = mCurrentCell.Value.transform.localPosition;
                Vector3 desPos = srcPos + offset;
                RestrictInBounds(ref desPos);

                SwitchDirection srcDirection = TargetDirection(srcPos);
                SwitchDirection desDirection = TargetDirection(desPos);

                if (srcDirection != desDirection)
                {
                    // handle old prepared cell
                    if (mPreparedCell != null && mPreparedCell.Value != null)
                    {
                        HideCell(mPreparedCell.Value);
                        ResetPrepareCell(SwitchDirection.None);
                    }

                    // set new prepared cell
                    if (desDirection != SwitchDirection.None)
                    {
                        ResetPrepareCell(desDirection);

                        if (mPreparedCell != null && mPreparedCell.Value != null)
                        {
                            // fufeng to do: get rotation according to the direction and the beyond offset, add to current rotation
                            //Vector3 beyondOffset = desPos - mSelectCenter;
                            //Quaternion rot = mCurrentCell.Value.transform.rotation;
                            //rot.y += 0.1f;
                            //TweenRotation.Begin( mCurrentCell.Value, 0.5f, rot );

                            ShowCell(mPreparedCell.Value, mPreparedIndex);
                        }
                        else
                        {
                            // fufeng to do: get rotation according to the direction and the beyond offset, add to current rotation
                            //Vector3 beyondOffset = desPos - mSelectCenter;
                            //Quaternion rot = mCurrentCell.Value.transform.rotation;
                            //rot.y += 0.1f;
                            //TweenRotation.Begin( mCurrentCell.Value, 0.5f, rot );

                            desDirection = SwitchDirection.None;
                            desPos       = SwitchPosition(SwitchDirection.None);
                        }
                    }
                }

                offset = desPos - srcPos;
                mCurrentCell.Value.transform.localPosition = desPos;

                if (mPreparedCell != null && mPreparedCell.Value != null)
                {
                    ZoomCell(mPreparedCell.Value, desPos);
                    AlphaCell(mPreparedCell.Value, desPos);
                }

                mInertiaOffset += (offset * m_Inertia);
            }
            else
            {
                ResetCell();
            }
        }
        else
        {
            mInertiaOffset = Vector3.zero;
        }
    }