예제 #1
0
    public static BallShot DeserializeBallShot(string code)
    {
        BallShot shot = new BallShot();

        string[] splitCode = code.Split(':');
        shot.ballID         = int.Parse(splitCode[1]);
        shot.shooterID      = int.Parse(splitCode[2]);
        shot.direction      = StringToVector3(splitCode[3]);
        shot.isAbilityBall  = bool.Parse(splitCode[4]);
        shot.shouldHome     = bool.Parse(splitCode[5]);
        shot.homingTargetID = int.Parse(splitCode[6]);
        return(shot);
    }
            public void OnTriggerEnter(Collider other)
            {
                GridBall parentGridBall = this.transform.parent.GetComponent <GridBall>();

                if (parentGridBall != null)
                {
                    BallShot ballShotThatHitMe = other.GetComponent <BallShot>();
                    if (ballShotThatHitMe != null)
                    {
                        // only sense flying balls
                        if (ballShotThatHitMe.state == BallShot.State.Flying)
                        {
                            // before processing anything else, snap a new GridBall into place
                            GridBall newGridBall = ballShotThatHitMe.SnapTo(parentGridBall.ballGrid, this);

                            // TODO: everything below this belongs in a different class - maybe use command pattern

                            // then start processing what happens after the ball exists
                            switch (ballShotThatHitMe.ballType)
                            {
                            case BallType.PaintSplash:
                                // turn all touched balls the same color
                                foreach (GridBall neighborBall in newGridBall.neighbors)
                                {
                                    neighborBall.ballColor = newGridBall.ballColor;
                                }
                                break;

                            case BallType.Bomb:
                                // TODO: pop all balls in a radius
                                break;

                            default:
                                // basic match-3 popping
                                GameMgr.I.StartCoroutine(this.PopChainLoop(newGridBall));
                                break;
                            }
                        }
                    }
                    else
                    {
                        Debug.LogWarning("grid ball sensor hit with something other than a ball shot", this);
                    }
                }
                else
                {
                    Debug.LogWarning("orphaned grid ball sensor", this);
                }
            }
예제 #3
0
            public static BallShot Generate(Transform gunTF)
            {
                BallShot ballShot = PoolManager.I.GetPooler("BallShot").Get <BallShot>();

                ballShot.transform.SetParent(gunTF);
                ballShot.transform.localScale          = Vector3.one * 0.30f;
                ballShot.transform.localPosition       = new Vector3(0f, -0.012f, 0.46f);
                ballShot.transform.localRotation       = Quaternion.identity;
                ballShot.ballRigidBody.velocity        = Vector3.zero;
                ballShot.ballRigidBody.angularVelocity = Vector3.zero;
                ballShot.SetState(State.Loaded);
                BallColor randomColor = (BallColor)Random.Range(1, (int)BallColor.LENGTH);

                ballShot.SetColor(randomColor);
                return(ballShot);
            }
            public void LateUpdate()
            {
                if (this.isReady)
                {
                    if (this.ballShot != null)
                    {
                        // TODO: decouple this so you can choose which input to use
                        if (this.ballShot.state == BallShot.State.Loaded &&
                            OVRInput.Get(OVRInput.RawAxis1D.RIndexTrigger) > 0.75f)
                        {
                            this.ballShot.Shoot();
                        }
                    }
                    else
                    {
                        bool reload = true;

                        foreach (BallGrid ballGrid in GameMgr.I.ballGrids)
                        {
                            if (ballGrid.state != BallGrid.State.Default)
                            {
                                reload = false;
                            }
                        }

                        // TODO: decouple this so you can choose which input to use
                        if (OVRInput.Get(OVRInput.RawAxis1D.RIndexTrigger) > 0.25f)
                        {
                            reload = false;
                        }

                        if (reload)
                        {
                            this.ballShot = BallShot.Generate(this.controllerTransform);
                        }
                    }
                }
            }