示例#1
0
    // Update is called once per frame
    void FixedUpdate()
    {
        //----------------------------------
        // Initiate
        //----------------------------------

        if (
            gestureManager.noSpellActive() &&
            leapManager.PalmNormalNearIgnore(gestureManager.calibratedDown, 0.65f, false, true, false) &&
            leapManager.PalmBetweenY(yThreshold, Mathf.Infinity) &&
            leapManager.GetFingerIsExtendedPattern(false, false, false, false, false) &&
            leapManager.GetHandGrabStrength() >= 0.8f
            )
        {
            gestureManager.activeSpell = thisSpell;
            gustProgression            = leapManager.GetPalmPosition().y;
            gestureManager.setHandColor(Color.yellow);
            gestureManager.glowController.Burst(1f);

            charge   = 0;
            released = false;

            audioManager.PlayLoop("gustLoop", handManager.audioplayerCasting);
        }

        //----------------------------------
        // Maintain
        //----------------------------------

        float palmY = leapManager.GetPalmPosition().y;

        palmWorldPosition = leapManager.GetPalmWorldPosition();
        gustCenter        = new Vector3(palmWorldPosition.x, 5f, palmWorldPosition.z);

        if (gestureManager.activeSpell.Equals(thisSpell))
        {
            //Debug.Log ("Gust is active!");
            if (
                leapManager.PalmNormalNearIgnore(gestureManager.calibratedDown, 0.85f, false, true, false) &&
                leapManager.GetFingerIsExtendedPattern(false, false, false, false, false) &&
                leapManager.GetHandGrabStrength() >= 0.6f
                //&& leapManager.PalmNearIgnore (tempPalmWorldPosition, 7f, false, true, true)
                && palmY < gustProgression + 1.5f
                )
            {
                if (charge < 0.1f)
                {
                    gestureManager.glowController.setIntensity(1f - charge * 10f);
                }
                else
                {
                    gestureManager.glowController.setIntensity(charge);
                }
                gestureManager.glowController.Flicker(charge);

                //Handle charge
                charge    = Mathf.Min(1, charge + 0.0075f);
                pulsebase = (pulsebase + (charge * 20f * Time.deltaTime)) % (2 * Mathf.PI);
                gestureManager.setHandColor(Color.Lerp(Color.white, Color.yellow, Mathf.Sin(pulsebase)));

                //If the hand is actually moving downwards, make some wind
                if (palmY < gustProgression - 1.5f)
                {
                    //Flash lights
                    FlashLights(charge);

                    if (!released)
                    {
                        audioManager.Stop(handManager.audioplayerCasting);
                        audioManager.Play("gustRelease", handManager.audioplayerCastingGust);
                        released = true;
                    }

                    gestureManager.glowController.setIntensity(0);
                    gestureManager.glowController.Burst(0.5f);


                    //Determine charge for this particular fixed update (NOTE - a different use of 'charge' than in GestureHurricane!)
                    float pull = gustProgression - palmY;

                    //Create drag
                    float searchRadiusSqr = 280.0f;

                    GameObject[] players       = GameObject.FindGameObjectsWithTag("Player");
                    GameObject[] objects       = GameObject.FindGameObjectsWithTag("Interactables");
                    GameObject[] intactObjects = GameObject.FindGameObjectsWithTag("Shatterables");

                    foreach (GameObject o in intactObjects)
                    {
                        ShatterOnCollision      scrA = o.GetComponent <ShatterOnCollision> ();
                        ShatterIndexOnCollision scrB = o.GetComponent <ShatterIndexOnCollision> ();

                        if (scrA != null || scrB != null)
                        {
                            //get pull direction (and distance to hand)
                            Vector3 dir = gustCenter - o.transform.position;

                            if (dir.sqrMagnitude <= searchRadiusSqr - Random.Range(0f, 50f))
                            {
                                IntactObject scr2 = o.GetComponentInChildren <IntactObject> ();
                                if (scr2 != null)
                                {
                                    scr2.SetHitvector(dir.normalized * 0.2f);
                                }

                                if (scrA != null)
                                {
                                    scrA.ShatterObject();
                                }
                                else if (scrB != null)
                                {
                                    scrB.ShatterObject();
                                }
                            }
                        }
                    }

                    foreach (GameObject o in objects)
                    {
                        Rigidbody rb = o.GetComponent <Rigidbody> ();
                        if (rb != null)
                        {
                            //get pull direction (and distance to hand)
                            Vector3 dir = gustCenter - rb.position;

                            if (dir.sqrMagnitude <= searchRadiusSqr)                               //Ignore if above threshold

                            //Calculate drag, based on distance to hand (reverse proportional), and scale by totalForceMultiplier
                            {
                                float force = Mathf.Clamp(searchRadiusSqr - dir.sqrMagnitude, 0f, searchRadiusSqr) * charge * pull * 6.0f;
                                //Set magnitude to force
                                dir = dir.normalized * force;
                                //Rotate pull, to create hurricane effect
                                dir = Quaternion.Euler(0f, 15f, 0f) * dir;

                                //Apply
                                rb.AddForce(dir);
                            }
                        }
                    }

                    foreach (GameObject o in players)
                    {
                        Rigidbody rb = o.GetComponent <Rigidbody> ();
                        if (rb != null)
                        {
                            //get pull direction (and distance to hand)
                            Vector3 dir = gustCenter - rb.position;
                            //Calculate drag, based on distance to hand (reverse proportional)
                            float force = Mathf.Clamp(searchRadiusSqr - dir.sqrMagnitude, 0, searchRadiusSqr) * pull * 0.001f;
                            //Set magnitude to force
                            dir = dir.normalized * force;
                            //Rotate pull, to create hurricane effect
                            dir = Quaternion.Euler(0, 30f, 0) * dir;

                            //Apply
                            rb.AddForce(dir);
                        }
                    }

                    gustProgression = palmY;
                }
            }

            else
            {
                gustProgression = -10f;                 //Incapacitate gustProgression
                gestureManager.clearActiveSpell();

                levelLight.intensity = levelLightBaseIntensity;
                gestureManager.glowController.setIntensity(0);

                if (!released)
                {
                    audioManager.Play("summonStop", handManager.audioplayerCasting);
                }
            }
        }


        //Handle flickering

        if (lightflicker > 0)
        {
            lightflicker -= 0.05f;

            //Flash the lights!
            levelLight.intensity = levelLightBaseIntensity + Random.Range(-0.4f, 2f) * lightflicker;
        }
        else
        {
            levelLight.intensity = levelLightBaseIntensity;
        }
    }
示例#2
0
    // Update is called once per frame
    void FixedUpdate()
    {
        if (levelGenerator != null)
        {
            origoY = levelGenerator.GetLevelAreaHeights() [Mathf.Clamp(Mathf.FloorToInt(leapManager.GetPalmWorldPosition().z), 0, 299)];
        }
        else
        {
            origoY = 0f;
        }
        //----------------------------------
        // Initiate
        //----------------------------------

        if (
            gestureManager.noSpellActive() &&
            leapManager.PalmNormalNear(gestureManager.calibratedDown, 0.35f) &&
            leapManager.GetPalmSmoothedVelocity() <= 1.0f &&
            leapManager.PalmBetweenY(origoY + 2f, -10f) &&
            leapManager.GetFingerIsExtendedPattern(true, true, true, true, true)
            //&& manager.GetPalmVelocity().magnitude < 5f
            )
        {
            gestureManager.activeSpell = thisSpell;
            blockCounter          = 1;
            tempPalmWorldPosition = leapManager.GetPalmWorldPosition();
            tempPalmPosition      = leapManager.GetPalmPosition();

            gestureManager.setHandColor(Color.yellow);
            gestureManager.glowController.Burst(1f);

            audioManager.PlayLoop("summonLoop", handManager.audioplayerCasting);
        }

        //----------------------------------
        // Maintain
        //----------------------------------

        if (gestureManager.activeSpell.Equals(thisSpell))
        {
            if (
                leapManager.PalmNormalNear(gestureManager.calibratedDown, 0.45f) &&
                leapManager.GetFingerIsExtendedPattern(true, true, true, true, true) &&
                leapManager.PalmNearIgnore(tempPalmPosition, 5f, false, true, true)
                )
            {
                gestureManager.glowController.setIntensity(0.5f);

                float palmY      = leapManager.GetPalmPosition().y;
                float nextBlockY = origoY + 1.2f + blockCounter * 0.75f;                 //Insert something about relative height here!

                if (palmY > nextBlockY && blockCounter < 7)
                {
                    //As the first block is being summoned, update palm position and summon frame-object
                    if (blockCounter == 1)
                    {
                        tempPalmWorldPosition = leapManager.GetPalmWorldPosition();
                        shard = Instantiate(summonedObjectType, new Vector3(tempPalmWorldPosition.x, origoY - 0.6f, tempPalmWorldPosition.z + 1f), Quaternion.Euler(0, 0, 0)) as GameObject;
                        ShatterIndexOnCollision shatterManager = shard.GetComponent <ShatterIndexOnCollision> ();

                        //Index subshards
                        foreach (Transform t in shard.transform)
                        {
                            //Find intact child, by checking begining of name
                            if (t.name.StartsWith("intactObject"))
                            {
                                //Read index, and add 00 as prefix, because bug-safely.
                                string strIndex = t.name.Insert(12, "00").Substring(12, 3);
                                int    index    = 1;

                                if (strIndex != null)
                                {
                                    index = int.Parse(strIndex);
                                }

                                subShard [index - 1] = t.gameObject;
                            }

                            subShard [0].GetComponent <Rigidbody>().AddTorque(new Vector3(0, -50, 0), ForceMode.Impulse);
                            subShard [0].GetComponent <Rigidbody>().AddForce(Vector3.up * 0.1f);
                        }

                        //Animate shard
                        //Rigidbody shardRb = shard.GetComponent<Rigidbody>();
                        //shardRb.rotation = new Quaternion (0, 1, 0, 0);
                    }

                    //For all other blocks, just activate and deactivate appropriately
                    else
                    {
                        //Dublicate rotation etc.
                        Rigidbody oldRb = subShard [blockCounter - 1].GetComponent <Rigidbody>();

                        Quaternion rot    = oldRb.rotation;
                        Vector3    pos    = oldRb.position;
                        Vector3    angVel = oldRb.angularVelocity;

                        //Deactivate and activate
                        for (int i = 0; i < subShard.Length; i++)
                        {
                            subShard [i].SetActive(false);
                        }

                        subShard [blockCounter].SetActive(true);

                        //Dublicate rotation etc.
                        Rigidbody newRb = subShard [blockCounter].GetComponent <Rigidbody>();

                        newRb.rotation        = rot;
                        newRb.position        = pos;
                        newRb.angularVelocity = angVel;

                        //A a bit of torque
                        subShard [blockCounter].GetComponent <Rigidbody>().AddTorque(new Vector3(0, -50, 0), ForceMode.Impulse);
                    }

                    //Either way, count the block, and play a sound
                    audioManager.Play("summonInstance", handManager.audioplayerCastingSupporting, blockCounter - 1, blockCounter - 1);
                    gestureManager.glowController.Burst(0.5f);

                    blockCounter++;
                }
            }
            else
            {
                gestureManager.clearActiveSpell();
                gestureManager.glowController.setIntensity(0);
                audioManager.Play("summonStop", handManager.audioplayerCasting);
            }
        }
    }