Ejemplo n.º 1
0
        public void RemoveAxisEventListener(int nPlayerID, int nAxisID
                                            , DirectionType2D eDirection, AxisEventType eEvent, UnityAction hAction
                                            , EventOrder eOrder = EventOrder.Normal)
        {
            if (!HasPlayerID(nPlayerID) || !HasAxisID(nPlayerID, nAxisID))
            {
                return;
            }

            var hAxis = m_lstPlayerInput[nPlayerID].m_arrAxis[nAxisID];

            switch (eDirection)
            {
            case DirectionType2D.Left:
                hAxis.m_hLeftEvent?.Remove(eEvent, hAction, eOrder);
                break;

            case DirectionType2D.Right:
                hAxis.m_hRightEvent?.Remove(eEvent, hAction, eOrder);
                break;

            case DirectionType2D.Up:
                hAxis.m_hUpEvent?.Remove(eEvent, hAction, eOrder);
                break;

            case DirectionType2D.Down:
                hAxis.m_hDownEvent?.Remove(eEvent, hAction, eOrder);
                break;
            }
        }
Ejemplo n.º 2
0
 public void Play(CharacterAnimation2D animation, DirectionType2D directionType)
 {
     if (animation == null)
     {
         return;
     }
     Play(animation.GetClipByDirection(directionType));
 }
 public void UpdateCurrentDirection(Vector2 direction)
 {
     currentDirection   = direction;
     localDirectionType = GameplayUtils.GetDirectionTypeByVector2(direction);
     if (IsServer)
     {
         currentDirectionType.Value = (byte)localDirectionType;
     }
 }
Ejemplo n.º 4
0
        static void MainRemoveAxisEventListener(int nPlayerID, int nAxisID
                                                , DirectionType2D eDirection, AxisEventType eEvent, UnityAction hAction
                                                , EventOrder eOrder = EventOrder.Normal)
        {
            if (m_hBaseInstance == null)
            {
                return;
            }

            m_hBaseInstance.gameInputData
            .RemoveAxisEventListener(nPlayerID, nAxisID, eDirection, eEvent, hAction, eOrder);
        }
Ejemplo n.º 5
0
        public AnimationClip GetClipByDirection(DirectionType2D directionType)
        {
            switch (directionType)
            {
            case DirectionType2D.Down:
                return(down);

            case DirectionType2D.Up:
                return(up);

            case DirectionType2D.Left:
                return(left);

            case DirectionType2D.Right:
                return(right);

            case DirectionType2D.DownLeft:
                // Return down if it is support 4-direction
                if (downLeft == null)
                {
                    return(down);
                }
                return(downLeft);

            case DirectionType2D.DownRight:
                // Return down if it is support 4-direction
                if (downRight == null)
                {
                    return(down);
                }
                return(downRight);

            case DirectionType2D.UpLeft:
                // Return up if it is support 4-direction
                if (upLeft == null)
                {
                    return(up);
                }
                return(upLeft);

            case DirectionType2D.UpRight:
                // Return up if it is support 4-direction
                if (upRight == null)
                {
                    return(up);
                }
                return(upRight);
            }
            // Default direction is down
            return(down);
        }
 public void UpdateCurrentDirection(Vector2 direction)
 {
     if (direction.magnitude > 0f)
     {
         localDirection     = direction;
         localDirectionType = GameplayUtils.GetDirectionTypeByVector2(direction);
     }
     if (IsServer && movementSecure == MovementSecure.ServerAuthoritative)
     {
         currentDirection.Value     = localDirection;
         currentDirectionType.Value = (byte)localDirectionType;
     }
     if (IsOwnerClient && movementSecure == MovementSecure.NotSecure)
     {
         CallNetFunction(NetFuncUpdateDirection, FunctionReceivers.Server, (sbyte)(localDirection.x * 100f), (sbyte)(localDirection.y * 100f));
     }
 }
Ejemplo n.º 7
0
        public void AddAxisEventListener(int nPlayerID, int nAxisID
                                         , DirectionType2D eDirection, AxisEventType eEvent, UnityAction hAction
                                         , EventOrder eOrder = EventOrder.Normal)
        {
            if (!HasPlayerID(nPlayerID) || !HasAxisID(nPlayerID, nAxisID))
            {
                return;
            }

            var hAxis = m_lstPlayerInput[nPlayerID].m_arrAxis[nAxisID];

            switch (eDirection)
            {
            case DirectionType2D.Left:
                hAxis.m_hLeftEvent ??= new EventCallback <AxisEventType>();
                hAxis.m_hLeftEvent.Add(eEvent, hAction);
                break;

            case DirectionType2D.Right:
                hAxis.m_hRightEvent ??= new EventCallback <AxisEventType>();
                hAxis.m_hRightEvent.Add(eEvent, hAction);
                break;

            case DirectionType2D.Up:
                hAxis.m_hUpEvent ??= new EventCallback <AxisEventType>();
                hAxis.m_hUpEvent.Add(eEvent, hAction);
                break;

            case DirectionType2D.Down:
                hAxis.m_hDownEvent ??= new EventCallback <AxisEventType>();
                hAxis.m_hDownEvent.Add(eEvent, hAction);
                break;
            }

            m_lstPlayerInput[nPlayerID].m_arrAxis[nAxisID] = hAxis;
        }
Ejemplo n.º 8
0
        public static DirectionType2D GetDirectionTypeByVector2(Vector2 direction)
        {
            Vector2 normalized = direction.normalized;
            float   absX       = Mathf.Abs(normalized.x);
            float   absY       = Mathf.Abs(normalized.y);

            if (absX / absY > 0.8f)
            {
                if (normalized.x < 0)
                {
                    return(DirectionType2D.Left);
                }
                if (normalized.x > 0)
                {
                    return(DirectionType2D.Right);
                }
            }
            else if (absY / absX > 0.8f)
            {
                if (normalized.y < 0)
                {
                    return(DirectionType2D.Down);
                }
                if (normalized.y > 0)
                {
                    return(DirectionType2D.Up);
                }
            }
            else
            {
                DirectionType2D result = DirectionType2D.Down;
                if (normalized.x > 0.01f)
                {
                    result = DirectionType2D.Left;
                    if (normalized.y > 0.01f)
                    {
                        result |= DirectionType2D.Up;
                    }
                    if (normalized.y < -0.01f)
                    {
                        result |= DirectionType2D.Down;
                    }
                }
                else if (normalized.x < -0.01f)
                {
                    result = DirectionType2D.Right;
                    if (normalized.y > 0.01f)
                    {
                        result |= DirectionType2D.Up;
                    }
                    if (normalized.y < -0.01f)
                    {
                        result |= DirectionType2D.Down;
                    }
                }
                else if (normalized.y > 0.01f)
                {
                    result = DirectionType2D.Up;
                }
                return(result);
            }
            return(DirectionType2D.Down);
        }
Ejemplo n.º 9
0
 public static void RemoveAxisEventListener(int nPlayerID, int nAxisID
                                            , DirectionType2D eDirection, AxisEventType eEvent, UnityAction hAction
                                            , EventOrder eOrder)
 {
     MainRemoveAxisEventListener(nPlayerID, nAxisID, eDirection, eEvent, hAction, eOrder);
 }
Ejemplo n.º 10
0
 /// <summary>
 /// Remove axis event listener from player id 0.
 /// </summary>
 /// <param name="nAxisID"></param>
 /// <param name="eDirection"></param>
 /// <param name="eEvent"></param>
 /// <param name="hAction"></param>
 public static void RemoveAxisEventListener(int nAxisID
                                            , DirectionType2D eDirection, AxisEventType eEvent, UnityAction hAction)
 {
     MainRemoveAxisEventListener(0, nAxisID, eDirection, eEvent, hAction);
 }
Ejemplo n.º 11
0
 public static void AddAxisEventListener(int nPlayerID, int nAxisID
                                         , DirectionType2D eDirection, AxisEventType eEvent, UnityAction hAction)
 {
     MainAddAxisEventListener(nPlayerID, nAxisID, eDirection, eEvent, hAction);
 }
Ejemplo n.º 12
0
 /// <summary>
 /// Add axis event listener to player id 0.
 /// </summary>
 /// <param name="nAxisID"></param>
 /// <param name="eDirection"></param>
 /// <param name="eEvent"></param>
 /// <param name="hAction"></param>
 /// <param name="eOrder"></param>
 public static void AddAxisEventListener(int nAxisID
                                         , DirectionType2D eDirection, AxisEventType eEvent, UnityAction hAction
                                         , EventOrder eOrder)
 {
     MainAddAxisEventListener(0, nAxisID, eDirection, eEvent, hAction, eOrder);
 }