Пример #1
0
 public static SupportAttacker Instance()
 {
     if (instance == null)
     {
         instance = new SupportAttacker();
     }
     return(instance);
 }
Пример #2
0
 private void Awake()
 {
     if (instance == null)
     {
         instance = this;
     }
     else if (instance != this)
     {
         Destroy(this.gameObject);
     }
     DontDestroyOnLoad(this.gameObject);
 }
Пример #3
0
    public override bool OnMessage(GameObject CallingObject, Message Msg)
    {
        FieldPlayer PlayerScript = CallingObject.GetComponent <FieldPlayer>();


        switch (Msg.Msg)
        {
        case PlayerMessages.ReceiveBall:
        {
            //GCHandle Handle = (GCHandle)Msg.ExtraInfo;
            //Vector2 Pos = (Vector2)Handle.Target;

            Steer2D.Arrive Arr = (Steer2D.Arrive)PlayerScript.GetSteeringController().GetBehaviourByTypeName("Steer2D.Arrive");
            Arr.TargetPoint = Msg.ExtraInfo;

            PlayerScript.ChangeState(CallingObject, ReceiveBall.Instance());
            return(true);
        }

        case PlayerMessages.SupportAttacker:
        {
            if (PlayerScript.IsInState(SupportAttacker.Instance()))
            {
                return(true);
            }

            //TODO Behaviour
            PlayerScript.ChangeState(CallingObject, SupportAttacker.Instance());
            return(true);
        }


        case PlayerMessages.Wait:
        {
            PlayerScript.ChangeState(CallingObject, Wait.Instance());
            return(true);
        }

        case PlayerMessages.PassToMe:
        {
            GameObject Reciever = Msg.Sender;

            //If there is already a recieving player or the ball isnt in range then cant pass pall to requesting player
            if (PlayerScript.GetTeam().RecievingPlayer != null || !PlayerScript.BallInKickingRange())
            {
                //Debug.Log("Can't make requested Pass");
                return(true);
            }

            //TODO double check this

            Vector2 PassTarget = PlayerScript.AddNoiseToTarget(Reciever.gameObject.transform.position);

            //Get the direction of the shot
            Vector2 KickDir = (PassTarget - (Vector2)PlayerScript.Ball.transform.position).normalized;

            float dot       = Vector3.Dot(CallingObject.transform.right, (PlayerScript.Ball.transform.position - CallingObject.transform.position).normalized);
            float KickPower = PlayerScript.PassingForce * dot;

            //Add force to the ball

            if (!PlayerScript.IsReadyForNextKick())
            {
                return(true);
            }

            PlayerScript.Ball.GetComponent <Football>().AddForce(KickDir * KickPower, PassTarget, "Passing To Reqested Pass");



            //GCHandle Handle = GCHandle.Alloc(Reciever.transform.position);
            //System.IntPtr PositionPtr = (System.IntPtr)Handle;

            Dispatcher.Instance().DispatchMessage(0, CallingObject, Reciever, PlayerMessages.ReceiveBall, PassTarget);

            PlayerScript.ChangeState(CallingObject, Wait.Instance());

            PlayerScript.FindSupport();

            return(true);
        }

        case PlayerMessages.GoHome:
        {
            PlayerScript.SetDefaultHomeRegion();
            PlayerScript.ChangeState(CallingObject, ReturnToHomeRegion.Instance());
            return(true);
        }
        }


        return(false);
    }