/*
     * Play note of entered ball
     */
    private MagicBallController OnBallPlayed(GameObject gameObject)
    {
        MagicBallController magicBallController = null;

        // Lock target if target was null or target changed
        if (gameObject != null)
        {
            magicBallController = gameObject.GetComponent <MagicBallController>();
            if (magicBallController != null)
            {
                // If it's not the lastest played note, play for 0.5s
                if (targetBall == null || targetBall != gameObject)
                {
                    if (midiPlayer)
                    {
                        midiPlayer.AddNote(new SingleNote(baseNote + magicBallController.index, 0.5f));
                        Invoke("ClearTargetBall", 0.5f);    // After 500ms clear target ball
                    }

                    targetBall = gameObject;
                }
            }
        }

        return(magicBallController);
    }
    public void ChargeWithMagicBall(GameObject ball)
    {
        if (ball != null && ball.CompareTag("MagicBall"))
        {
            MagicBallController magicBallController = ball.GetComponent <MagicBallController>();

            if (this.index >= 0 && (Mathf.Abs(this.index - magicBallController.index) == 2))
            {
                // NOT TO-DO: condition -> C and B... B and C have no interval...
                // If composition is possible
                this.index = (this.index + magicBallController.index) / 2;
            }
            else
            {
                this.index = magicBallController.index;
            }

            // Set Magic Indicator
            if (this.magicIndicator)
            {
                this.magicIndicator.GetComponent <Image>().color =
                    magicBallController.materials[this.index].color;
            }

            if (this.noteManager)
            {
                this.noteManager.GetComponent <Text>().text =
                    magicBallController.notes[this.index];
            }

            Destroy(ball);
        }
    }
    /*
     * Play note of entered ball
     */
    private MagicBallController OnBallGet(GameObject gameObject, GameObject origin)
    {
        MagicBallController magicBallController = null;

        if (gameObject)
        {
            magicBallController = gameObject.GetComponent <MagicBallController>();

            if (origin != null)
            {
                // Move to player
                gameObject.transform.Translate((origin.transform.position - gameObject.transform.position) * Time.deltaTime * 2.0f, Space.World);

                // Charge with the ball
                if ((origin.transform.position - gameObject.transform.position).magnitude < 0.8f)
                {
                    if (chargedIndex >= 0 && (Mathf.Abs(chargedIndex - magicBallController.index) == 2))
                    {
                        // If combinaison is possible
                        chargedIndex = (chargedIndex + magicBallController.index) / 2;
                    }
                    else
                    {
                        // Overwrite charged state
                        chargedIndex = magicBallController.index;
                    }

                    Destroy(gameObject);
                }
            }
        }

        /*if (magicBallGenerator.GetComponent<MagicBallGenerator>().HasMagicBall(hit.transform.gameObject))
         * {
         *  magicBallGenerator.GetComponent<MagicBallGenerator>().RetrieveMagicBall(hit.transform.gameObject);
         *  //magicBallController.SetRotationArround(this.transform.position);
         * }*/

        return(magicBallController);
    }
Example #4
0
 void Awake()
 {
     myPC = GetComponentInParent <MagicBallController> ();
 }
Example #5
0
    // Update is called once per frame
    void Update()
    {
        if (Controller.GetTouchDown(SteamVR_Controller.ButtonMask.Touchpad))
        {
            Vector2 cc     = Controller.GetAxis();
            float   jiaodu = VectorAngle(new Vector2(1, 0), cc);
            if ((jiaodu > 0 && jiaodu < 45) || (jiaodu > -45 && jiaodu < 0) || (jiaodu < 180 && jiaodu > 135) || (jiaodu < -135 && jiaodu > -180))
            {
                if (this.index >= 0 && this.timer <= 0)
                {
                    this.midiPlayer.setNote(this.index + this.baseNote);
                    this.timer = 1.0f;
                }
            }
        }

        if (ViveInput.GetPress(HandRole.RightHand, ControllerButton.Grip))
        {
            // Get the ball
            RaycastHit hit;

            if (Physics.Raycast(this.transform.position, this.transform.TransformDirection(Vector3.forward), out hit))
            {
                if (hit.transform.gameObject.CompareTag("MagicBall"))
                {
                    MagicBallController magicBallController = hit.transform.gameObject.GetComponent <MagicBallController>();
                    Debug.Log("hit magic ball: " + hit.transform.gameObject.name);
                    //magicBallController.SetRotationArround(new Vector3(0, 0, 0));

                    if (magicBallGenerator.GetComponent <MagicBallGenerator>().HasMagicBall(hit.transform.gameObject))
                    {
                        magicBallGenerator.GetComponent <MagicBallGenerator>().RetrieveMagicBall(hit.transform.gameObject);
                        //magicBallController.SetRotationArround(this.transform.position);
                    }

                    hit.transform.Translate((this.transform.position - hit.transform.position) * Time.deltaTime * 2.0f, Space.World);

                    // Charge with the ball
                    if ((this.transform.position - hit.transform.position).magnitude < 0.8f)
                    {
                        if (this.index >= 0 && (Mathf.Abs(this.index - magicBallController.index) == 2))
                        {
                            // NOT TO-DO: condition -> C and B... B and C have no interval...
                            // If composition is possible
                            this.index = (this.index + magicBallController.index) / 2;
                        }
                        else
                        {
                            this.index = magicBallController.index;
                        }

                        // Set Magic Indicator
                        if (this.magicIndicator)
                        {
                            this.magicIndicator.GetComponent <Image>().color =
                                magicBallController.materials[this.index].color;
                        }
                        Destroy(hit.transform.gameObject);
                    }
                }
            }
        }

        if (Controller.GetHairTriggerDown())
        {
            if (this.index >= 0)
            {
                Controller.TriggerHapticPulse(2500);
                if (this.projectiles.Length > this.index)
                {
                    GameObject projectile = Instantiate(this.projectiles[this.index], this.transform.position - new Vector3(0, 0.5f, 0), this.transform.rotation);
                    projectile.GetComponent <ProjectileFly>().index = this.index;
                    projectile.GetComponent <ProjectileFly>().SetTarget(
                        GameObject.FindGameObjectWithTag("MainCamera").
                        GetComponent <TargetLocked>().GetTarget());

                    // Set magic charge to non charge
                    this.index = -1;

                    if (this.magicIndicator)
                    {
                        this.magicIndicator.GetComponent <Image>().color = Color.white;
                    }
                }
            }
            else
            {
                Debug.Log("Not charged");
                if (this.tipsManager)
                {
                    this.timer = 3.0f;
                    this.tipsManager.GetComponent <Text>().text = "You are not charged";
                }
            }

            Debug.DrawRay(this.transform.position, this.transform.TransformDirection(Vector3.forward) * 8.0f, Color.red);
            Debug.Log(gameObject.name + " Trigger Press");
        }


        RaycastHit detect_hit;

        if (Physics.Raycast(this.transform.position, this.transform.TransformDirection(Vector3.forward), out detect_hit))
        {
            if (detect_hit.transform.gameObject.CompareTag("Enermy"))
            {
                int _index = detect_hit.transform.gameObject.GetComponent <PandaMove>().index;
                if (this.tipsManager)
                {
                    this.timer = 0.5f;
                    if (_index != -1)
                    {
                        this.tipsManager.GetComponent <Text>().text = "Target Panda " +
                                                                      GameObject.FindGameObjectWithTag("MagicBall").GetComponent <MagicBallController>().notes[_index];
                    }
                }
            }
            else if (detect_hit.transform.gameObject.CompareTag("MagicBall"))
            {
                int _index = detect_hit.transform.gameObject.GetComponent <MagicBallController>().index;
                if (this.tipsManager)
                {
                    this.timer = 0.5f;
                    if (_index != -1)
                    {
                        this.tipsManager.GetComponent <Text>().text = "Target Magic Ball " +
                                                                      GameObject.FindGameObjectWithTag("MagicBall").GetComponent <MagicBallController>().notes[_index];
                    }
                }
            }
        }
    }