예제 #1
0
        public void SoundTest()
        {
            CueController test = new CueController(new List <Cue>());

            test.BeginPlayback("TestingAudio/man-scream-01.mp3");
            System.Threading.Thread.Sleep(3000);
        }
예제 #2
0
파일: LogicAI.cs 프로젝트: sonxoans2/CoThu
	public void ShotCue (CueController cueController)
	{
		StopCoroutine("WaitAndShotCue");
		if(!ServerController.serverController.isMyQueue)
		{
			StartCoroutine("WaitAndShotCue", cueController);
		}
	}
예제 #3
0
 void Awake () {
     //collider.enabled = false;
     for(int i = 0; i < nodes.Length; i++) {
         nodes[i].GetComponent<Renderer> ().enabled = false;
     }
     cueController = CueController.FindObjectOfType (typeof (CueController)) as CueController;
     GetComponent<Renderer> ().enabled = false;
     ballSpline = new AnimationSpline (WrapMode.Clamp);
 }
예제 #4
0
 // Use this for initialization
 void Start()
 {
     anim2 = blackRect.GetComponent <Animator>();
     anim  = GameObject.Find("cueSpinBallBig").GetComponent <Animator>();
     cueControllerScript = GameObject.Find("WhiteBall").GetComponent <CueController>();
     initialPosStart     = circle2.transform.localPosition;
     localPosInit        = circle1.transform.localPosition;
     rectCollider        = blackRect.GetComponent <BoxCollider>();
 }
예제 #5
0
 public void resetPositions()
 {
     circle1.transform.localPosition = localPosInit;
     circle2.transform.localPosition = initialPosStart;
     if (cueControllerScript == null)
     {
         cueControllerScript = GameObject.Find("WhiteBall").GetComponent <CueController>();
     }
     cueControllerScript.trickShotAdd = new Vector3(0, 0, 0);
 }
예제 #6
0
    void Awake()
    {
        instance = this;
        Application.targetFrameRate = Constant.FRAMERATE;
        CreateAndSortBalls();
        kitchenLine.SetPosition(0, new Vector3(-Constant.TABLE_W / 2.0f, 0, -Constant.TABLE_W / 2.0f));
        kitchenLine.SetPosition(1, new Vector3(-Constant.TABLE_W / 2.0f, 0, Constant.TABLE_W / 2.0f));
#if !MOBILE
        canControlled = true;
#endif
    }
예제 #7
0
    public void SetProgresbar()
    {
        CueController cueController         = GameObject.FindGameObjectWithTag("Player").GetComponent <CueController>();
        float         currentForceMagnitude = cueController.forceMagnitude;
        float         rate = currentForceMagnitude / cueController.maxForce;

        float progressbarContainerHeight = progressbarImage.transform.parent.GetComponent <RectTransform>().rect.height;

        progressbarImage.GetComponent <RectTransform>().sizeDelta = new Vector2(
            progressbarImage.GetComponent <RectTransform>().rect.width,
            progressbarContainerHeight * rate
            );
    }
예제 #8
0
    public void UpdateShadow(CueController inCueController, int inColorNumber)
    {
        cueController = inCueController;

        for (int i = 0; i < cueController.allBallControllers.Length; i++)
        {
            Shadows[i].GetComponent <SelectBall>().ChangeSelect(false);
        }

        if (inColorNumber != 0)
        {
            Shadows[inColorNumber].GetComponent <SelectBall>().ChangeSelect(true);
        }
    }
예제 #9
0
	IEnumerator WaitAndFindCueController (Preloader preloader)
	{
		cueController = null;
		while(!preloader.isDone)
		{
			yield return null;
		}
		while(!cueController)
		{
			cueController = CueController.FindObjectOfType<CueController>();
			yield return null;
		}
		Debuger.DebugOnScreen("CueController " + (cueController != null).ToString());
		OnFindCueController();
	}
예제 #10
0
    public void InitShadow(CueController inCueController)
    {
        cueController = inCueController;

        for (int i = 0; i < cueController.allBallControllers.Length; i++)
        {
            GameObject Group = (GameObject)Instantiate(ShadowPrefabs[i], (Vector3)ShadowGroup.transform.position, (Quaternion)ShadowPrefabs[i].transform.rotation);

            Group.transform.parent         = ShadowGroup.transform;
            Group.transform.localPosition  = cueController.allBallControllers[i].GetComponent <Rigidbody>().position;
            Group.transform.localPosition += new Vector3(0.0f, shadowBoxHeight, 0.0f);
            Group.transform.localScale     = new Vector3(0.24f, 0.24f, 0.24f);
            Group.GetComponent <Renderer>().material.mainTexture = ShadowTexture;
            Group.GetComponent <Renderer>().material.color       = new Color(1, 1, 1, 1);

            Shadows.Add(Group);
        }
    }
예제 #11
0
    void Start()
    {
        gameManager = PoolGameManager.Instance;
        cueScript   = GameObject.Find("WhiteBall").GetComponent <CueController>();

        initialPos = cue.transform.position;
        setIndicatorColor();
        initColor = shotColorIndicator.GetComponent <SpriteRenderer>().color;
        anim      = mainObject.GetComponent <Animator>();
        if (PoolGameManager.Instance.roomOwner)
        {
            anim.Play("MakeVisible");
        }
        else
        {
            anim.Play("ShotPowerAnimation");
        }
    }
예제 #12
0
    public int id = 1; // ids are 1 2 3 4 5 6, so be careful

    void Awake()
    {
        for (int j = 0; j < initialNodes.Length; j++)
        {
            initialNodes[j].GetComponent <Renderer>().enabled = false;
        }

        initialBallSpline = new AnimationSpline(WrapMode.Clamp);

        for (int i = 0; i < finalNodes.Length; i++)
        {
            finalNodes[i].GetComponent <Renderer>().enabled = false;
        }

        finalBallSpline = new AnimationSpline(WrapMode.Clamp);

        cueController = CueController.FindObjectOfType(typeof(CueController)) as CueController;

        GetComponent <Renderer>().enabled = false;
    }
예제 #13
0
    IEnumerator WaitAndFindCueController(Preloader preloader)
    {
        cueController = null;

        while (!preloader.isDone)
        {
            yield return(null);
        }

        while (cueController == null)
        {
            cueController = CueController.FindObjectOfType <CueController>();

            yield return(null);
        }

        yield return(new WaitForEndOfFrame());

        cueController.enabled = true;                 // this is the golden line that shows the game to our players

        StartCoroutine(UpdateSlaveStillPositions(0)); // 0th shot
    }
예제 #14
0
    void Awake()
    {
        TableData     = new List <BallData>();
        MsgTemplate   = new SQEle(ConvToBytes(), DefaultCallback);
        enabled       = false;
        timer         = new Timer(WaitTimeVel);
        cueController = gameObject.transform.Find("CueBall").GetComponent <CueController>();
        ballData      = new BallData("init", Vector3.zero);
        foreach (Rigidbody rb in gameObject.GetComponentsInChildren <Rigidbody>())
        {
            rbBalls.Add(rb.gameObject.name, rb);
        }
        posball_y = rbBalls["CueBall"].position.y;
        var tableno_str = gameObject.transform.parent.name.Split('_')[1];

        TableNo = int.Parse(tableno_str) - 1;
        GameProcess.tables[TableNo] = this;
        serializable_tabledata      = new SerializableTableData(TableData, TableNo);
        TablePosition    = gameObject.transform.parent.transform.position;
        TablePosition.y += posball_y;
        execution_timer  = new Stopwatch();
        //UnityEngine.Debug.Log(GameProcess.tables[0]);
    }
예제 #15
0
파일: LogicAI.cs 프로젝트: sonxoans2/CoThu
	public void CheckCueBallHit (CueController cueController, Vector3 localPosition)
	{
		Ray ray = new Ray(cueController.collisionSphere.position, cueController.secondVelocity.normalized);
		RaycastHit hit;
		if(Physics.SphereCast(ray, 0.1f*cueController.ballRadius, out hit, 1000.0f, cueController.wallAndBallMask))
		{
			if(hit.collider.GetComponent<HolleController>())
			{
				CheckSetCueBallPivot(cueController, localPosition);
			}
		}
	}
예제 #16
0
파일: LogicAI.cs 프로젝트: sonxoans2/CoThu
	private void CheckSetCueBallPivot (CueController cueController, Vector3 localPosition )
	{
		if(MenuControllerGenerator.controller.AISkill == 1 || !targetBallController)
		{
			return;
		}
		Vector3 shotBack = (cueBallStartPosition - targetBallController.transform.position).normalized;
		Ray ray = new Ray(cueBallStartPosition, shotBack);
		RaycastHit hit;
		if(Physics.SphereCast(ray, 0.1f*cueController.ballRadius, out hit, 1000.0f, cueController.wallAndBallMask))
		{
			if(!hit.collider.GetComponent<HolleController>())
			{
				cueController.cueBallPivot.SetPosition(localPosition);
			}

		}
	}
예제 #17
0
파일: LogicAI.cs 프로젝트: sonxoans2/CoThu
	IEnumerator StretchCue (CueController cueController)
	{
		float stretchTime = 1.3f;
		float time = stretchTime;
		cueController.cueDisplacement = 0.0f;
		Vector3  ballPivotLocalPosition = Random.Range(0, 2) == 0? Vector3.down:Vector3.up;
		while(time > 0.0f)
		{
			if(targetBallController)
			{
				CheckCueBallHit(cueController, ballPivotLocalPosition);
			}
			time -= stretchTime*Time.fixedDeltaTime;
			cueController.cueDisplacement = Mathf.Clamp01 ((stretchTime - time)/stretchTime)*cueController.cueMaxDisplacement;
			cueController.cueDisplacement *= Mathf.Clamp01( (allDistance/40.0f)*(1.0f/Mathf.Clamp(realHitAngle, 0.3f, 1.0f)));
			cueController.OnControlCue ();
			cueController.cueForceValue = 1.0f;
            yield return new WaitForFixedUpdate ();
        }
    }
예제 #18
0
    // Use this for initialization
    void Start()
    {
        audioSources        = GetComponents <AudioSource>();
        shotPowerScript     = shotPowerObject.GetComponent <ShotPowerScript>();
        cueControllerScript = cueController.GetComponent <CueController>();
        playerTime          = PoolGameManager.Instance.playerTime;
        imageClock1         = GameObject.Find("AvatarClock1").GetComponent <Image>();
        imageClock2         = GameObject.Find("AvatarClock2").GetComponent <Image>();

        messageBubble     = GameObject.Find("MessageBubble").GetComponent <Animator>();
        messageBubbleText = GameObject.Find("BubbleText").GetComponent <Text>();

        if (PoolGameManager.Instance.offlineMode)
        {
            GameObject.Find("Name1").GetComponent <Text>().text = PoolStaticStrings.offlineModePlayer1Name;
            // if (GameManager.Instance.avatarMy != null)
            //     GameObject.Find("Avatar1").GetComponent<Image>().sprite = GameManager.Instance.avatarMy;

            GameObject.Find("Name2").GetComponent <Text>().text     = PoolStaticStrings.offlineModePlayer2Name;
            GameObject.Find("Avatar2").GetComponent <Image>().color = Color.red;

            // if (GameManager.Instance.avatarOpponent != null)
            //     GameObject.Find("Avatar2").GetComponent<Image>().sprite = GameManager.Instance.avatarOpponent;
        }
        else
        {
            GameObject.Find("Name1").GetComponent <Text>().text = PoolGameManager.Instance.nameMy;
            if (PoolGameManager.Instance.avatarMy != null)
            {
                GameObject.Find("Avatar1").GetComponent <Image>().sprite = PoolGameManager.Instance.avatarMy;
            }

            GameObject.Find("Name2").GetComponent <Text>().text = PoolGameManager.Instance.nameOpponent;

            if (PoolGameManager.Instance.avatarOpponent != null)
            {
                GameObject.Find("Avatar2").GetComponent <Image>().sprite = PoolGameManager.Instance.avatarOpponent;
            }
        }

        // GameObject.Find ("Name1").GetComponent <Text> ().text = GameManager.Instance.nameMy;
        // if (GameManager.Instance.avatarMy != null)
        //     GameObject.Find ("Avatar1").GetComponent <Image> ().sprite = GameManager.Instance.avatarMy;

        // GameObject.Find ("Name2").GetComponent <Text> ().text = GameManager.Instance.nameOpponent;

        // if (GameManager.Instance.avatarOpponent != null)
        //     GameObject.Find ("Avatar2").GetComponent <Image> ().sprite = GameManager.Instance.avatarOpponent;



        playerTime = playerTime * Time.timeScale;


        if (PoolGameManager.Instance.roomOwner)
        {
            showMessage(PoolStaticStrings.youAreBreaking);
        }
        else
        {
            showMessage(PoolGameManager.Instance.nameOpponent + " " + PoolStaticStrings.opponentIsBreaking);
        }

        if (!PoolGameManager.Instance.roomOwner)
        {
            currentImage = 2;
        }
    }
예제 #19
0
    // Use this for initialization
    void Start()
    {
        animator      = GameObject.Find("ShotPower").GetComponent <Animator>();
        ballsInMotion = true;

        spinControl = GameObject.Find("cueSpinBallBig").GetComponent <SpinController>();

        cueControllerScript = whiteBallPrefab.GetComponent <CueController>();
        // Disable screen dimming
        Screen.sleepTimeout = SleepTimeout.NeverSleep;


        //cueControllerScript = GameObject.Find ("WhiteBall").GetComponent <CueController> ();
        //16
        balls          = new GameObject[16];
        renderers      = new MeshRenderer[16];
        rigidbodies    = new Rigidbody[16];
        enabledScripts = new LockZPosition[16];

        whiteBallPrefab.transform.tag = "WhiteBall";
        balls[0]          = whiteBallPrefab;
        renderers[0]      = whiteBallPrefab.GetComponent <MeshRenderer>();
        rigidbodies[0]    = whiteBallPrefab.GetComponent <Rigidbody>();
        enabledScripts[0] = whiteBallPrefab.GetComponent <LockZPosition>();

        PoolGameManager.Instance.whiteBall = balls[0];

        Rigidbody rigid = balls[0].GetComponent <Rigidbody>();

        rigid.maxAngularVelocity = 150;
        //		rigid.useConeFriction = false;
        //rigid.collisionDetectionMode = CollisionDetectionMode.Discrete;

        Debug.Log(PoolGameManager.Instance.whiteBall.GetComponent <Rigidbody>().maxAngularVelocity + " MAX ANG");

        float radius  = ballPrefab.GetComponent <SphereCollider>().radius;
        int   counter = 1;
        //5



        List <int> freeI = new List <int>();

        freeI.Add(0);
        freeI.Add(1);
        freeI.Add(1);
        freeI.Add(2);
        freeI.Add(2);
        freeI.Add(3);
        freeI.Add(3);
        freeI.Add(3);
        freeI.Add(3);

        freeI.Add(4);
        freeI.Add(4);
        freeI.Add(4);



        freeI.Add(4);
        freeI.Add(4);
        freeI.Add(2);


        List <int> freeJ = new List <int>();

        freeJ.Add(0);

        freeJ.Add(0);
        freeJ.Add(1);


        freeJ.Add(0);
        freeJ.Add(2);

        freeJ.Add(0);
        freeJ.Add(1);
        freeJ.Add(2);
        freeJ.Add(3);

        freeJ.Add(1);
        freeJ.Add(2);
        freeJ.Add(3);


        freeJ.Add(0);
        freeJ.Add(4);
        freeJ.Add(1);

        Vector3[] positions = new Vector3[15];

        for (int i = 0; i < 5; i++)
        {
            for (int j = 0; j < i + 1; j++)
            {
                GameObject ball = Instantiate(ballPrefab);
                ball.GetComponent <Renderer>().material.SetTexture("_MainTex", texturesArray[counter - 1]);
                ball.transform.tag      = "Ball" + counter.ToString();
                balls[counter]          = ball;
                renderers[counter]      = ball.GetComponent <MeshRenderer>();
                rigidbodies[counter]    = ball.GetComponent <Rigidbody>();
                enabledScripts[counter] = ball.GetComponent <LockZPosition>();

                Rigidbody ballRigidbody = ball.GetComponent <Rigidbody>();


                ballRigidbody.maxAngularVelocity = 150;
                //				ballRigidbody.useConeFriction = false;

                //ballRigidbody.collisionDetectionMode = CollisionDetectionMode.Discrete;

                if (PoolGameManager.Instance.roomOwner)
                {
                    int minus = 4;
                    if (counter > 9)
                    {
                        minus = 1;
                    }

                    int iii = Random.Range(0, freeI.Count - minus);



                    if (counter == 1)
                    {
                        iii = freeI.Count - 3;
                    }
                    else if (counter == 9)
                    {
                        iii = freeI.Count - 2;
                    }
                    else if (counter == 8)
                    {
                        iii = freeI.Count - 1;
                    }

                    float posY = ballPrefab.GetComponent <Rigidbody>().transform.position.y + freeI[iii] * (radius * ballPrefab.transform.localScale.x /*0.325f*/);

                    Vector3 position = ballRigidbody.transform.position;


                    position.x += freeI[iii] * (radius * (ball.transform.localScale.x * 2 * 0.9f) * 1.0f);
                    position.y  = posY - freeJ[iii] * (radius * (ball.transform.localScale.x * 2) * 1.0f);

                    freeI.RemoveAt(iii);
                    freeJ.RemoveAt(iii);

                    ballRigidbody.transform.position = position;
                    positions[counter - 1]           = position;
                }
                else
                {
                    ball.SetActive(false);
                }

                //ball.SetActive (false);


                ballRigidbody.maxAngularVelocity = 150;
                counter++;
                //ballRigidbody.Sleep ();
            }
        }

        PoolGameManager.Instance.balls = balls;

        if (PoolGameManager.Instance.roomOwner)
        {
            Debug.Log("Raise 198");
            if (!PoolGameManager.Instance.offlineMode)
            {
                PhotonNetwork.RaiseEvent(198, positions, true, null);
            }
        }
        else
        {
            for (int i = 0; i < PoolGameManager.Instance.initPositions.Length; i++)
            {
                PoolGameManager.Instance.balls[i + 1].GetComponent <Rigidbody>().transform.position = PoolGameManager.Instance.initPositions[i];
                PoolGameManager.Instance.balls[i + 1].SetActive(true);
            }
        }
    }
예제 #20
0
파일: LogicAI.cs 프로젝트: sonxoans2/CoThu
	bool CheckAllWalls(CueController cueController, float ballRadius, Vector3 cueBallPosition, Vector3 targetBallHitPoint, BallController targetBall, ref Vector3 checkPoint, ref float hitAngle)
	{
		return
			CheckWall(Vector3.right, cueController, ballRadius, cueBallPosition, targetBallHitPoint, targetBall, ref checkPoint, ref hitAngle) |
				CheckWall(Vector3.left, cueController, ballRadius, cueBallPosition, targetBallHitPoint, targetBall, ref checkPoint, ref hitAngle) |
				CheckWall(Vector3.forward, cueController, ballRadius, cueBallPosition, targetBallHitPoint, targetBall, ref checkPoint, ref hitAngle) |
				CheckWall(Vector3.back, cueController, ballRadius, cueBallPosition, targetBallHitPoint, targetBall, ref checkPoint, ref hitAngle);
		
	}
예제 #21
0
파일: LogicAI.cs 프로젝트: sonxoans2/CoThu
	bool CheckWall(Vector3 direction, CueController cueController, float ballRadius, Vector3 cueBallPosition, Vector3 targetBallHitPoint, BallController targetBall, ref Vector3 checkPoint, ref float hitAngle)
	{
		Ray ray = new Ray(cueBallPosition, direction);
		RaycastHit hit;
		if(Physics.Raycast(ray, out hit, 1000.0f, cueController.wallMask))
		{
			float height = Vector3.Distance(hit.point, cueBallPosition) - 0.99f*cueController.ballRadius;
			float deltaHeight = Vector3.Dot( targetBallHitPoint - cueBallPosition, direction);
			Vector3 orient = VectorOperator.getPerpendicularToVector(direction, targetBallHitPoint - cueBallPosition).normalized;
			float distance = Vector3.Project(targetBallHitPoint - cueBallPosition, orient).magnitude;

			Vector3 needPoint = cueBallPosition + height*direction + (distance*height/(2.0f*height - deltaHeight))*orient;


			Vector3 checkDirection1 = (needPoint - cueBallPosition).normalized;
			Vector3 checkDirection2 = (targetBallHitPoint - needPoint).normalized;


			Ray checkPointRay = new Ray(cueBallPosition, checkDirection1);
			RaycastHit checkPointHit;
			if(Physics.SphereCast(checkPointRay, 0.99f*cueController.ballRadius, out checkPointHit, 1000.0f, cueController.wallAndBallMask))
			{
				if(checkPointHit.collider.gameObject.layer == LayerMask.NameToLayer("Wall"))
				{

					if(Vector3.Dot(checkPointHit.normal, -direction) > 0.9f)
					{

						Ray targetRay = new Ray(needPoint + 0.02f*cueController.ballRadius*checkDirection2, checkDirection2);
						RaycastHit targetHit;
						if(Physics.SphereCast(targetRay, 0.99f*cueController.ballRadius, out targetHit, 1000.0f, cueController.wallAndBallMask))
						{
							BallController currentTargetBall = targetHit.collider.GetComponent<BallController>();
							if(currentTargetBall && currentTargetBall == targetBall)
							{
								float currentHitAngle = Vector3.Dot(checkDirection2, (targetBall.transform.position - targetBallHitPoint).normalized);
								ballDistance = Vector3.Distance(cueBallPosition, needPoint) + Vector3.Distance(needPoint, targetBallHitPoint); 
								if(currentHitAngle > hitAngle )
								{
									checkPoint = needPoint;
									hitAngle = currentHitAngle;
									realHitAngle = hitAngle;
									haveWallTarget = true;
									targetBallController = targetBall;
									return true;
								}
							}
						}
					}
				}
			}
		}
		return false;
	}
예제 #22
0
	IEnumerator WaitAndEnabledCueController ()
	{
		Debuger.DebugOnScreen("StartEnabledCueController");
		Debuger.DebugOnScreen((cueController != null).ToString());
		Debuger.DebugOnScreen((ServerController.serverController.menuButtonsIsActive).ToString());

		Debuger.DebugOnScreen((ServerController.serverController.otherNetworkPlayer < 1).ToString());
		Debuger.DebugOnScreen((!MenuControllerGenerator.controller.playWithAI).ToString());

		while(!cueController || ServerController.serverController.menuButtonsIsActive || 
		      (ServerController.serverController.otherNetworkPlayer < 1 && !MenuControllerGenerator.controller.playWithAI))
		{
			cueController = CueController.FindObjectOfType<CueController>();
			yield return null;
		}
		Debuger.DebugOnScreen("WaitForEndOfFrame");
        yield return new WaitForEndOfFrame();
        cueController.enabled = true;
		cueController.cueFSMController.enabled = true;
		string info = ServerController.serverController.isMyQueue? "Bạn đánh!":"Đối thủ đánh!";
		//cueController.gameManager.ShowGameInfo(info, 2.5f);
        cueController.gameManager.ShowGameInfoError (info);
		Debuger.DebugOnScreen("EndEnabledCueController");
	}
예제 #23
0
파일: LogicAI.cs 프로젝트: sonxoans2/CoThu
	IEnumerator WaitAndShotCue(CueController cueController)
	{
		shotIsStarted = true;

		yield return new WaitForSeconds(0.5f);

		targetPoint = Vector3.zero;
		targetBallController = null;
		haveBallTarget = false;
		haveWallTarget = false;
		float ballHitAngle = 0.0f;
		float wallHitAngle = 0.0f;

		holleDistance = 0.0f;
		ballDistance = 0.0f;
		allDistance = 40.0f;
		realHitAngle = 0.1f;
		bool haveFirsHit = false;
		if (targetsAI && targetsAI.targets != null)
		{
			foreach (Target target in targetsAI.targets) {
				foreach (BallController ballController in cueController.ballControllers) {
					if (ballController == cueController.ballController) {
						continue;
					}
					if (ballController.isBlack && !cueController.gameManager.afterOtherRemainedBlackBall) {
						continue;
					} 
					if (!cueController.gameManager.tableIsOpened &&
                        (cueController.gameManager.ballType == ballController.ballType || cueController.gameManager.otherProfileNew.checkBallCard(ballController.id))) {
						continue;
					}

					Vector3 direction = (target.transform.position - ballController.transform.position).normalized;
					Vector3 origin = ballController.transform.position + 2.0f * cueController.ballRadius * direction;
					Vector3 checkPoint = ballController.transform.position - 1.99f * cueController.ballRadius * direction;
					if (!haveBallTarget && !haveWallTarget) {
						targetPoint = checkPoint;
					}

					RaycastHit targetHit;

					if (Physics.SphereCast (origin, 0.99f * cueController.ballRadius, direction, out targetHit, cueController.wallAndBallMask | cueController.mainBallMask)) {
						if (targetHit.collider.GetComponent<BallController> ()) {
							continue;
						}

						if (targetHit.collider.GetComponent<HolleController> ()) {
							cueBallStartPosition = cueController.ballController.transform.position;

							Vector3 cueBallMoveOrient = (checkPoint - ballController.transform.position).normalized;
							Ray cueBallMoveRay = new Ray (checkPoint + 0.04f * cueController.ballRadius * cueBallMoveOrient, cueBallMoveOrient);
							Ray checkOtherBallRay = new Ray (checkPoint + 2.0f * cueController.ballRadius * Vector3.up, -Vector3.up);

							Transform StartOrMoveCube = cueController.isFirsTime ? cueController.StartCube : cueController.MoveCube;
							Vector3 point = checkPoint + cueController.ballRadius * cueBallMoveOrient;
							if (VectorOperator.sphereInCube (point, cueController.ballRadius, StartOrMoveCube) && cueController.cueFSMController.moveInTable
								&& !Physics.SphereCast (cueBallMoveRay, 0.99f * cueController.ballRadius, 2.0f * cueController.ballRadius, cueController.wallAndBallMask)
								&& !Physics.SphereCast (checkOtherBallRay, 1.1f * cueController.ballRadius, 4.0f * cueController.ballRadius, cueController.ballMask)) {
								//Can move the main (cue ) ball
								Debug.Log ("cueBallStartPosition " + cueBallStartPosition);
								haveFirsHit = true;
								cueBallStartPosition = point;
								targetBallController = ballController;
								Vector3 cueBallOrient = (checkPoint - cueBallStartPosition).normalized;
								float distance = Vector3.Distance (cueBallStartPosition, checkPoint);
								float currentHitAngle = Vector3.Dot (cueBallOrient, direction);

								CheckSetCueBallPivot (cueController, 0.5f * currentHitAngle * Vector3.down);
								holleDistance = Vector3.Distance (ballController.transform.position, target.transform.position);
								ballDistance = distance;
								allDistance = holleDistance + ballDistance;
								ballHitAngle = currentHitAngle;
								realHitAngle = ballHitAngle;
								targetPoint = checkPoint;
								haveBallTarget = true;
								targetBallController = ballController;
								break;

							} else {
					
								Vector3 cueBallOrient = (checkPoint - cueBallStartPosition).normalized;

								float distance = Vector3.Distance (cueBallStartPosition, checkPoint);

								Ray ray = new Ray (cueBallStartPosition, cueBallOrient);
								if (!Physics.SphereCast (ray, 0.99f * cueController.ballRadius, distance - 0.02f * cueController.ballRadius, cueController.wallAndBallMask)) {
									float currentHitAngle = Vector3.Dot (cueBallOrient, direction);
									if (currentHitAngle > ballHitAngle) {
										//Can throw the target ball
										CheckSetCueBallPivot (cueController, 0.5f * currentHitAngle * Vector3.down);
										holleDistance = Vector3.Distance (ballController.transform.position, target.transform.position);
										ballDistance = distance;
										allDistance = holleDistance + ballDistance;
										ballHitAngle = currentHitAngle;
										realHitAngle = ballHitAngle;
										targetPoint = checkPoint;
										haveBallTarget = true;
										targetBallController = ballController;
									} 
								} else
								if (MenuControllerGenerator.controller.AISkill == 3 && !haveBallTarget && CheckAllWalls (cueController, cueController.ballRadius, cueBallStartPosition, checkPoint, ballController, ref targetPoint, ref wallHitAngle)) {
									//Can throw the target ball using the walls
									//Debug.LogWarning("have Wall Target");
								}
							}
						}
					}
					if (MenuControllerGenerator.controller.AISkill == 1) {
						cueRotation.SetLookRotation ((targetPoint + 0.2f * cueController.ballRadius * Random.onUnitSphere - cueController.cuePivot.position).normalized);
					} else {
						cueRotation.SetLookRotation ((targetPoint - cueController.cuePivot.position).normalized);
					}
				}

				if (!cueController.gameManager.isFirstShot) {
					cueController.cuePivot.rotation = cueRotation;
				} else {
					cueController.cuePivot.localRotation = Quaternion.Euler (0.093f, 0.675f, 0.0f);
				}
				if (haveFirsHit) {
					break;
				}
		
				yield return null;

			}

			if (cueController.cueFSMController.moveInTable && targetBallController) {
				cueController.ballController.GetComponent<Rigidbody> ().isKinematic = true;
				cueController.ballController.GetComponent<Rigidbody> ().position += 3.0f * cueController.ballRadius * Vector3.up;
				yield return new WaitForFixedUpdate ();
				cueController.ballController.GetComponent<Rigidbody> ().position = cueBallStartPosition + 3.0f * cueController.ballRadius * Vector3.up;
				yield return new WaitForFixedUpdate ();
				cueController.ballController.transform.position = cueBallStartPosition;
				cueController.ballController.GetComponent<Rigidbody> ().isKinematic = false;
				yield return new WaitForSeconds (0.5f);
				if (!cueController.gameManager.isFirstShot) {
					cueController.cuePivot.LookAt (targetPoint);
				}			
				yield return new WaitForFixedUpdate ();
			}
			yield return StartCoroutine (StretchCue (cueController));


			cueController.cueForceValue = Mathf.Clamp01 ((allDistance / 40.0f) * (1.0f / Mathf.Clamp (realHitAngle, 0.3f, 1.0f)));
			if (!cueController.gameManager.isFirstShot) {
				cueController.cueForceValue *= 0.85f;
			}
			cueController.OnDrawLinesAndSphere ();
			cueController.CheckShotCue ();
			shotIsStarted = false;
		}
	}
예제 #24
0
 void Start()
 {
     anim  = bigCueSpin.GetComponent <Animator>();
     anim2 = blackRect.GetComponent <Animator>();
     cueControllerScript = GameObject.Find("WhiteBall").GetComponent <CueController>();
 }