Exemplo n.º 1
0
    private IEnumerator CheckCollision()
    {
        netForce     = Vector2.zero;
        currentAngle = (EssoUtility.GetAngleFromVector(transform.right) - detectionArcAngle / 2) + 90;
        for (int i = 0; i < rayCount; i++)
        {
            Vector2 point;
            //Using utility function to convert a angle into a vector
            RaycastHit2D hitInfo = Physics2D.Raycast(transform.position, EssoUtility.GetVectorFromAngle(currentAngle), detectionRadius, detectionLayers);
            if (hitInfo)
            {
                //If it hits something the current vertex position = point
                point = hitInfo.point;
                AvoidPoint(point);
            }
            else
            {
                //If not just draw full length of ray in current angle
                point = transform.position + EssoUtility.GetVectorFromAngle(currentAngle) * detectionRadius;
            }
            Debug.DrawLine(transform.position, point, Color.green, 0.5f);
            currentAngle -= angleBetweenRays;
        }

        yield return(new WaitForSeconds(tickRate));

        if (isActive)
        {
            StartCoroutine(CheckCollision());
        }
    }
Exemplo n.º 2
0
    //Update light shape
    private void SetShapeOfLight()
    {
        Debug.Log("running in light");
        currentAngle = startingAngle + offset;
        float angleIncrease = fovAngle / lightPathPoints.Length;

        for (int i = 0; i < lightPathPoints.Length; i++)
        {
            if (i > 0)
            {
                RaycastHit2D hitInfo = Physics2D.Raycast(origin, EssoUtility.GetVectorFromAngle(currentAngle), viewDistance, ViewBlockingLayers);
                if (hitInfo)
                {
                    lightPathPoints[i] = hitInfo.point;
                    Debug.DrawLine(lightPathPoints[0], hitInfo.point);
                }
                else
                {
                    lightPathPoints[i] = origin + EssoUtility.GetVectorFromAngle(currentAngle) * viewDistance;
                    Debug.DrawRay(lightPathPoints[0], lightPathPoints[0] + EssoUtility.GetVectorFromAngle(currentAngle) * viewDistance);
                }
            }
            else
            {
                lightPathPoints[i] = origin;
            }


            currentAngle -= angleIncrease;
        }
        for (int i = 0; i < lightCone.shapePath.Length; i++)
        {
            lightCone.shapePath[i] = lightPathPoints[i];
        }
    }
Exemplo n.º 3
0
    public void Break(Vector2 dir, float force)
    {
        if (smashVFX)
        {
            ObjectPoolManager.Spawn(smashVFX, transform.position, transform.rotation);
        }
        Vector3[] partDir = EssoUtility.GetVectorsInArc(dir, brokenParts.Count, spreadAngle, spread);

        for (int i = 0; i < brokenParts.Count; i++)
        {
            Vector3    randPosition = transform.position + Random.insideUnitSphere * 0.5f;
            GameObject part         = ObjectPoolManager.Spawn(brokenParts[i], randPosition, transform.rotation);


            pieces.Add(part);
            part.GetComponent <IBreakVFX>().AddBreakForce(partDir[i], force);
        }
        if (table)
        {
            GameObject loot = table.ReturnLoot();
            if (loot)
            {
                Vector3 randPosition = transform.position + Random.insideUnitSphere * 0.5f;
                ObjectPoolManager.Spawn(loot, randPosition, transform.rotation).GetComponent <IBreakVFX>().AddBreakForce(dir, force);
            }
        }


        aSource.Play();
        DisableObject();
    }
Exemplo n.º 4
0
    public void PlayerFacePointer()
    {
        float targetAngle = Mathf.Atan2(EssoUtility.GetVectorToPointer(activeCamera, transform.position).y, EssoUtility.GetVectorToPointer(activeCamera, transform.position).x) * Mathf.Rad2Deg; //get angle to rotate

        targetAngle -= 90f;                                                                                                                                                                      // turn offset -Due to converting between forward vector and up vector
        //if (targetAngle < 0) targetAngle += 360f;
        float angle = Mathf.SmoothDampAngle(transform.eulerAngles.z, targetAngle, ref smoothRot, settings.rotationSpeed);                                                                        //rotate player smoothly to target angle

        transform.rotation = Quaternion.Euler(0f, 0f, angle);                                                                                                                                    //update angle
        //fovObject.SetAimDirection((-1)*fovObject.GetVectorFromAngle(angle));
    }
Exemplo n.º 5
0
 virtual protected void FaceTarget()
 {
     if (target != null)
     {
         float targetAngle = EssoUtility.GetAngleFromVector((target.position - transform.position).normalized);
         /* targetAngle += 90f;*/                                                                                          // turn offset -Due to converting between forward vector and up vector
                                                                                                                           //if (targetAngle < 0) targetAngle += 360f;
         float angle = Mathf.SmoothDampAngle(transform.eulerAngles.z, targetAngle, ref smoothRot, settings.rotationSpeed); //rotate player smoothly to target angle
         transform.rotation = Quaternion.Euler(0f, 0f, angle);                                                             //update angle
         //fovObject.SetAimDirection((-1)*fovObject.GetVectorFromAngle(angle));
     }
 }
Exemplo n.º 6
0
    virtual protected void DrawVisionConeShape()
    {
        //Create then number of total vertices required
        Vector3[] vertices = new Vector3[rayCount + 1 + 1];//orgin ray + ray 0

        //Create UVs to all vertices
        Vector2[] uv = new Vector2[vertices.Length];

        //D
        int[] triangles = new int[rayCount * 3];   //for every ray there should  be triangle and as the triangle has three vertices ray*3

        currentAngle = startingAngle + offset;     //Adds offset to angle player straight on
        float angleIncrease = fovAngle / rayCount; //The incremenent for each angle

        vertices[0] = origin;                      // first vertex should alwaus be at the index

        int vertexIndex   = 1;                     //start at index one  (second element)
        int triangleIndex = 0;

        for (int i = 0; i < rayCount; i++)
        {
            Vector3 vertex;
            //Using utility function to convert a angle into a vector
            RaycastHit2D hitInfo = Physics2D.Raycast(origin, EssoUtility.GetVectorFromAngle(currentAngle), viewDistance, ViewBlockingLayers);
            if (hitInfo)
            {
                //If it hits something the current vertex position = point
                vertex = hitInfo.point;
            }
            else
            {
                //If not just draw full length of ray in current angle
                vertex = origin + EssoUtility.GetVectorFromAngle(currentAngle) * viewDistance;
            }
            vertices[vertexIndex] = vertex;
            if (i > 0)//Do not do it for the first element as it is the origin
            {
                triangles[triangleIndex + 0] = 0;
                triangles[triangleIndex + 1] = vertexIndex - 1;
                triangles[triangleIndex + 2] = vertexIndex;
                triangleIndex += 3;
            }

            vertexIndex++;
            currentAngle -= angleIncrease;
        }

        //Update mesh
        mesh.vertices  = vertices;
        mesh.uv        = uv;
        mesh.triangles = triangles;
        mesh.bounds    = new Bounds(origin, Vector3.one * 1000f);//Sets bounds to size of map
    }
Exemplo n.º 7
0
    private void DisplayFirstBeat(BeatData data)
    {
        Vector2   pos;
        SMSBubble newBubble;
        float     bubbleHeight;
        float     bubbleWidth;

        switch (currentSpeaker)
        {
        case Speaker.Client:

            //Create newbubble
            newBubble = DialogueManager.instance.CreateSMSBubble(smsArea);
            newBubble.SetUp(data.DisplayText, clientBubbleColor);

            //get dimension
            bubbleHeight = newBubble.GetComponent <RectTransform>().rect.height;
            bubbleWidth  = newBubble.GetComponent <RectTransform>().rect.width;

            //calculate position at the top of the screen in the client case
            pos = (Vector2)smsClientStartPosition.position + (clientSmsOffset * EssoUtility.GetAspectRatio());

            //update postion and display text
            newBubble.transform.position = pos + new Vector2(bubbleWidth / 2, -(bubbleHeight / 2) * EssoUtility.GetAspectRatio());
            previousBubble = newBubble;

            vibrationController.BeginViewBob();
            AudioManager.instance.PlayAtRandomPitch("PhoneVibrateSFX");
            smsBubbles.Add(previousBubble);
            break;

        //calculate position at the top of the screen in the mc case
        case Speaker.MainCharacter:
            newBubble = DialogueManager.instance.CreateSMSBubble(smsArea);
            newBubble.SetUp(data.DisplayText, mcBubbleColor);

            //get dimension
            bubbleHeight = newBubble.GetComponent <RectTransform>().rect.height;
            bubbleWidth  = newBubble.GetComponent <RectTransform>().rect.width;

            //calculate position at the top of the screen in the client case
            pos = (Vector2)smsMCStartPosition.position + (mcSmsOffset * EssoUtility.GetAspectRatio());

            //update postion and display text
            newBubble.transform.position = pos + new Vector2(-bubbleWidth / 2, -(bubbleHeight / 2) * EssoUtility.GetAspectRatio());
            previousBubble = newBubble;

            smsBubbles.Add(previousBubble);
            break;
        }
    }
Exemplo n.º 8
0
 public void EjectSpawnEgg()
 {
     if (enemyCount < maxAttackCount)
     {
         if (gameObject.activeInHierarchy && aSource)
         {
             aSource.Play();
         }
         EggSpawner egg           = ObjectPoolManager.Spawn(eggSpawnerPrefab, transform.position, Quaternion.identity);
         Vector2    randDirection = EssoUtility.GetVectorFromAngle(Random.Range(0f, 360f));
         egg.EjectEgg(ejectForce, randDirection);
         egg.SetUpEgg(playerTransform, GetRandomEnemyFromList(), this);
     }
 }
Exemplo n.º 9
0
    private Vector3[] GetVectorsInArc()
    {
        Vector3[] shotDir = new Vector3[bulletsPerShot];

        for (int i = 0; i < shotDir.Length; i++)
        {
            float startingAngle = (EssoUtility.GetAngleFromVector(firePoint.up) - sprayRange / 2);
            float randOffset    = Random.Range(-spray, spray);

            shotDir[i] = EssoUtility.GetVectorFromAngle(randOffset + startingAngle + sprayRange);
        }

        return(shotDir);
    }
Exemplo n.º 10
0
    virtual protected void FaceMovementDirection(Vector2 dir)
    {
        float targetAngle = EssoUtility.GetAngleFromVector((dir.normalized));

        /// turn offset -Due to converting between forward vector and up vector
        if (targetAngle < 0)
        {
            targetAngle += 360f;
        }
        float angle = Mathf.SmoothDampAngle(transform.eulerAngles.z, targetAngle, ref smoothRot, settings.rotationSpeed); //rotate player smoothly to target angle

        transform.rotation = Quaternion.Euler(0f, 0f, angle);                                                             //update angle
        //fovObject.SetAimDirection((-1)*fovObject.GetVectorFromAngle(angle));
    }
Exemplo n.º 11
0
    private void DisplayFirstCredit(bool isCredit, CreditData newCredit)
    {
        Vector2   pos;
        SMSBubble newBubble;
        float     bubbleHeight;
        float     bubbleWidth;

        if (isCredit)
        {
            //Create newbubble
            newBubble = CreateCreditBubble();
            newBubble.SetUp(newCredit.CreditText, credits.creditColour);

            //get dimension
            bubbleHeight = newBubble.GetComponent <RectTransform>().rect.height;
            bubbleWidth  = newBubble.GetComponent <RectTransform>().rect.width;

            //calculate position at the top of the screen in the client case
            pos = (Vector2)creditsStartPos.position + (creditBubbleOffSet * EssoUtility.GetAspectRatio());

            //update postion and display text
            newBubble.transform.position = pos + new Vector2(bubbleWidth / 2, -(bubbleHeight / 2) * EssoUtility.GetAspectRatio());
            previousBubble = newBubble;


            smsBubbles.Add(previousBubble.transform);
        }
        else
        {
            newBubble = CreateCreditBubble();
            newBubble.SetUp(newCredit.CreditText, credits.authorColour);

            //get dimension
            bubbleHeight = newBubble.GetComponent <RectTransform>().rect.height;
            bubbleWidth  = newBubble.GetComponent <RectTransform>().rect.width;

            //calculate position at the top of the screen in the client case
            pos = (Vector2)authorStartPos.position + (authorBubbleOffset * EssoUtility.GetAspectRatio());

            //update postion and display text
            newBubble.transform.position = pos + new Vector2(-bubbleWidth / 2, -(bubbleHeight / 2) * EssoUtility.GetAspectRatio());
            previousBubble = newBubble;

            smsBubbles.Add(previousBubble.transform);
        }
        vibrationController.BeginViewBob();
        //AudioManager.instance.PlayAtRandomPitch("PhoneVibrateSFX");
    }
Exemplo n.º 12
0
    public void SpawnFragments()
    {
        float      angleIncrement = 360f / fragmentCounts;
        float      currentAngle   = 0f;
        GameObject currentFragment;

        for (int i = 0; i < fragmentCounts; i++)
        {
            int rand = Random.Range(0, slimeFragmentsPrefabs.Count);
            currentFragment = ObjectPoolManager.Spawn(slimeFragmentsPrefabs[rand], transform.position);

            Vector3 dir = EssoUtility.GetVectorFromAngle(currentAngle).normalized;
            currentFragment.transform.up = dir;
            IShootable frag = currentFragment.GetComponent <IShootable>();
            frag.SetUpBullet(knockBack / fragmentCounts, damage / fragmentCounts);
            frag.Shoot(dir, shotForce * 0.8f);
            currentAngle += angleIncrement;
        }
    }
Exemplo n.º 13
0
    protected void WeakenEnemy()
    {
        currentAngle = startingAngle + offset;     //Adds offset to angle player straight on
        float angleIncrease = fovAngle / rayCount; //The incremenent for each angle

        for (int i = 0; i < rayCount; i++)
        {
            RaycastHit2D hitInfo = Physics2D.Raycast(origin, EssoUtility.GetVectorFromAngle(currentAngle), viewDistance, enemyLayer);

            if (hitInfo)
            {
                if (hitInfo.transform.GetComponent <ILightWeakness>() != null)
                {
                    hitInfo.transform.GetComponent <ILightWeakness>().MakeVulnerable();
                }
                Debug.DrawRay(origin, hitInfo.point);
            }
            else
            {
                Debug.DrawRay(origin, EssoUtility.GetVectorFromAngle(currentAngle) * viewDistance);
            }
            currentAngle -= angleIncrease;
        }
    }
Exemplo n.º 14
0
 //Sets the starting angle to direction of given vector
 public void SetAimDirection(Vector3 aimDir)
 {
     startingAngle = (EssoUtility.GetAngleFromVector(aimDir) - fovAngle / 2);
 }
Exemplo n.º 15
0
    public void DisplayCredit(bool isCredit, CreditData newCredit)
    {
        Vector2   pos;
        SMSBubble newBubble;
        float     bubbleHeight = previousBubble.GetComponent <RectTransform>().rect.height;;
        float     newBubbleHeight;
        float     newBubbleWidth;

        if (isCredit)
        {
            //set up sms bubbles
            newBubble = CreateCreditBubble();
            newBubble.SetUp(newCredit.CreditText, credits.creditColour);

            //get bubble dimensions
            newBubbleHeight = newBubble.GetComponent <RectTransform>().rect.height;
            newBubbleWidth  = newBubble.GetComponent <RectTransform>().rect.width;

            //Spawn new bubble with an offset of its previous position + the offset of it's height from its centre
            pos = new Vector2(creditsStartPos.position.x + newBubbleWidth / 2, previousBubble.transform.position.y - bubbleHeight / 2 - newBubbleHeight / 2)
                  + (creditBubbleOffSet + bubbleOffset) * EssoUtility.GetAspectRatio();

            //Update position
            newBubble.transform.position = pos;
            previousBubble = newBubble;

            smsBubbles.Add(previousBubble.transform);

            if (pos.y < screenEndPoint.position.y)
            {
                float vertDistance = screenEndPoint.position.y - pos.y;
                ScrollUnitsUp(vertDistance + newBubbleHeight / 2);
            }
        }
        else
        {
            //set up sms bubbles
            newBubble = CreateCreditBubble();
            newBubble.SetUp(newCredit.CreditText, credits.authorColour);

            //get bubble dimensions
            newBubbleHeight = newBubble.GetComponent <RectTransform>().rect.height;
            newBubbleWidth  = newBubble.GetComponent <RectTransform>().rect.width;

            //Spawn new bubble with an offset of its previous position + the offset of it's height from its centre
            pos = new Vector2(authorStartPos.position.x - newBubbleWidth / 2, previousBubble.transform.position.y - bubbleHeight / 2 - newBubbleHeight / 2)
                  + (authorBubbleOffset + bubbleOffset) * EssoUtility.GetAspectRatio();

            //Update position
            newBubble.transform.position = pos;
            previousBubble = newBubble;

            smsBubbles.Add(previousBubble.transform);
            if (pos.y < screenEndPoint.position.y)
            {
                float vertDistance = screenEndPoint.position.y - pos.y;
                ScrollUnitsUp(vertDistance + newBubbleHeight / 2);
            }
        }
        vibrationController.BeginViewBob();
        AudioManager.instance.PlayAtRandomPitch("PhoneVibrateSFX");
    }
Exemplo n.º 16
0
    private void DisplaySmsBubble(BeatData data)
    {
        Vector2   pos;
        SMSBubble newBubble;
        float     bubbleHeight = previousBubble.GetComponent <RectTransform>().rect.height;;
        float     newBubbleHeight;
        float     newBubbleWidth;

        switch (currentSpeaker)
        {
        case Speaker.Client:
            //set up sms bubbles
            newBubble = DialogueManager.instance.CreateSMSBubble(smsArea);
            newBubble.SetUp(data.DisplayText, clientBubbleColor);

            //get bubble dimensions
            newBubbleHeight = newBubble.GetComponent <RectTransform>().rect.height;
            newBubbleWidth  = newBubble.GetComponent <RectTransform>().rect.width;

            //Spawn new bubble with an offset of its previous position + the offset of it's height from its centre
            pos = new Vector2(smsClientStartPosition.position.x + newBubbleWidth / 2, previousBubble.transform.position.y - bubbleHeight / 2 - newBubbleHeight / 2)
                  + (clientSmsOffset + bubbleOffset) * EssoUtility.GetAspectRatio();

            //Update position
            newBubble.transform.position = pos;
            previousBubble = newBubble;

            smsBubbles.Add(previousBubble);

            if (pos.y < smsScreenEndPoint.position.y)
            {
                float vertDistance = smsScreenEndPoint.position.y - pos.y;
                ScrollUnitsUp(vertDistance + newBubbleHeight / 2);
            }
            vibrationController.BeginViewBob();
            AudioManager.instance.PlayAtRandomPitch("PhoneVibrateSFX");

            break;

        case Speaker.MainCharacter:
            //set up sms bubbles
            newBubble = DialogueManager.instance.CreateSMSBubble(smsArea);
            newBubble.SetUp(data.DisplayText, mcBubbleColor);

            //get bubble dimensions
            newBubbleHeight = newBubble.GetComponent <RectTransform>().rect.height;
            newBubbleWidth  = newBubble.GetComponent <RectTransform>().rect.width;

            //Spawn new bubble with an offset of its previous position + the offset of it's height from its centre
            pos = new Vector2(smsMCStartPosition.position.x - newBubbleWidth / 2, previousBubble.transform.position.y - bubbleHeight / 2 - newBubbleHeight / 2)
                  + (mcSmsOffset + bubbleOffset) * EssoUtility.GetAspectRatio();

            //Update position
            newBubble.transform.position = pos;
            previousBubble = newBubble;

            smsBubbles.Add(previousBubble);
            if (pos.y < smsScreenEndPoint.position.y)
            {
                float vertDistance = smsScreenEndPoint.position.y - pos.y;
                ScrollUnitsUp(vertDistance + newBubbleHeight / 2);
            }

            break;
        }
    }