/// <summary> /// 【观察者模式】 /// /// 足球(Ball)解决求和球员的问题及当球的位置变化,所有的球员和裁判应当能够立即感知。 /// </summary> static void observers() { var ball = new FootBall(); ////'Create few players (i.e, ConcreteObservers) var Owen = new Player(ball, "Owen"); var Ronaldo = new Player(ball, "Ronaldo"); var Rivaldo = new Player(ball, "Rivaldo"); ////'Create few referees (i.e, ConcreteObservers) var Mike = new Referee(ball, "Mike"); var John = new Referee(ball, "John"); ////'Attach the observers with the ball ball.AttachObserver(Owen); ball.AttachObserver(Ronaldo); ball.AttachObserver(Rivaldo); ball.AttachObserver(Mike); ball.AttachObserver(John); System.Console.WriteLine("After attaching the observers..."); ////'Update the position of the ball. ////'At this point, all the observers should be notified automatically ball.SetBallPosition(new Position()); ////'Just write a blank line System.Console.WriteLine(); ////'Remove some observers ball.DetachObserver(Owen); ball.DetachObserver(John); System.Console.WriteLine("After detaching Owen and John..."); ////'Updating the position of ball again ////'At this point, all the observers should be notified automatically ball.SetBallPosition(new Position(10, 10, 30)); ////'Press any key to continue.. }
IEnumerator PassTheBall() { Quaternion lookAt = Quaternion.LookRotation(throwVector); transform.rotation = lookAt; throwingHand = throwingHandScript.gameObject; yield return(new WaitForSeconds(1)); //todo find way to access animation curve info. var thrownBall = Instantiate(footBall, throwingHand.transform.position, lookAt); //todo put footballs in hierarchy container thrownBall.name = "throwBall"; FootBall thrownBallScript = thrownBall.GetComponent <FootBall>(); thrownBallScript.PassFootBallToMovingTarget(this, targetOffPlayer, thrownBallScript, throwArc, throwPower); gameManager.isPassStarted = true; //Destroy(thrownBall, 3f); //todo get better solution to removing footballs }
public void PassFootBallToMovingTarget(QB ballThrower, OffPlayer receiver, FootBall footBall, float arcType, float power) { isComplete = true; SetGameManager(); gameManager.AttemptPass(ballThrower, receiver, this, arcType, power); //todo, this is ugly. Probably should be a bool for isComplete if (rb == null) { rb = GetComponent <Rigidbody>(); } //targetPos = GetPositionIn(2, wr); transform.parent = null; rb.useGravity = true; BallisticMotion motion = GetComponent <BallisticMotion>(); Vector3 targetPos = receiver.transform.position; Vector3 diff = targetPos - transform.position; Vector3 diffGround = new Vector3(diff.x, 0f, diff.z); Vector3 fireVel, impactPos; Vector3 velocity = receiver.navMeshAgent.velocity; //FTS Calculations https://github.com/forrestthewoods/lib_fts/tree/master/projects/unity/ballistic_trajectory float gravity; if (Ballistics.solve_ballistic_arc_lateral(transform.position, power, targetPos + Vector3.up, velocity, arcType, out fireVel, out gravity, out impactPos)) { GameObject go = Instantiate(targetMarker, impactPos, Quaternion.LookRotation(ballThrower.transform.position + new Vector3(0, 1, 0))); go.name = "footballMarker"; go.transform.parent = FindObjectOfType <FootBall>().transform; Destroy(go, 2); transform.forward = diffGround; motion.Initialize(transform.position, gravity); motion.AddImpulse(fireVel); gameManager.ThrowTheBall(ballThrower, receiver, this, impactPos, arcType, power, isComplete); //todo the football stores whether the pass is complete or not, not sure if thats a good idea. } //Debug.Log("Firing at " + impactPos); }
internal void LookAtBall(FootBall ball) { lookObj = ball.transform; }
public override void PlayFootBall(FootBall ballType) { Console.WriteLine("足球是用来打的"); }
public void AttemptPass(QB ballThrower, OffPlayer ballReciever, FootBall ball, float arcType, float power) { passAttempt(ballThrower, ballReciever, ball, arcType, power); }
public void ThrowTheBall(QB ballThrower, OffPlayer ballReciever, FootBall ball, Vector3 impactPos, float arcType, float power, bool isComplete) { onBallThrown(ballThrower, ballReciever, ball, impactPos, arcType, power, isComplete); }
private void BallThrown(QB thrower, WR reciever, FootBall footBall, Vector3 impactPos, float arcType, float power, bool isComplete) { }
internal void FollowBall(FootBall ball) { player = null; football = ball.gameObject; }
public abstract void PlayFootBall(FootBall ballType);