Ejemplo n.º 1
0
    private void OnTriggerEnter(Collider collision)
    {
        //too soon
        if (Time.time < nextNailIn)
        {
            return;
        }

        if (!Hammer)
        {
            Hammer = GetComponentInParent <PlayerHammer>();
        }

        if (Hammer && Hammer.IsHammering)
        {
            Nail nail = collision.GetComponentInParent <Nail>();
            if (nail)
            {
                nextNailIn = Time.time + 0.25f;
                nail.NailMeIn();

                if (hitEffect)
                {
                    //audioSource.Play();
                    var newEffect = Instantiate(hitEffect, transform.position, Quaternion.identity);
                    Destroy(newEffect, 2f);
                }
            }
        }
    }
Ejemplo n.º 2
0
    private IEnumerator SetupWithDelay()
    {
        yield return(new WaitForSeconds(0.6f));

        data = LevelsDifficultyContainer.Houses[LevelContainer.CurrentHouseNumber - 1].levelsData[LevelContainer.CurrentLevelIndex];
        verticalMoveSpeed                      = data.rotationSpeed / 100f;
        NailsParent                            = FindObjectOfType <NailsSpawner>().gameObject;
        targetNail                             = NailsParent.transform.GetChild(targetIndex).gameObject.GetComponent <Nail>();
        EventManager.EventPerfectHit          += OnPerfectHit;
        EventManager.EventHammerSpriteChanged += OnSpriteChanged;


        cashedMaxStrength       = ConstantDataContainer.MaxHammerStrength;
        cashedPositionBeforeHit = ConstantDataContainer.PositionOverNailHeadBeforeHit;
        cashedPositionAfterHit  = ConstantDataContainer.PositionOverNailHeadAfterHit;

        myTransform.DOMove(new Vector3(myTransform.position.x, targetNail.nailHead.transform.position.y + cashedPositionBeforeHit, myTransform.position.z), 0.3f);
        yield return(new WaitForSeconds(0.3f));

        rotationZ        = myTransform.rotation.z;
        movingY          = myTransform.position.y;
        startingRotation = myTransform.rotation;
        startingPosition = myTransform.position;
        isHammerReady    = true;
        targetIndex      = 0;
    }
Ejemplo n.º 3
0
 public void AssignParent(Nail newParent)
 {
     if (parent == null)
     {
         parent = newParent;
     }
 }
Ejemplo n.º 4
0
    public void StartNail(int index)
    {
        List <Nail> nailLocations = stages[currentStage].GetNails();

        Debug.Assert(nailLocations != null && index < nailLocations.Count);
        nailLocations[index].SetShown(true);
        this.nail = nailLocations[index];
    }
Ejemplo n.º 5
0
    private void HighlightNearbyNails()
    {
        Nail nail = GetNearbyNail();

        if (nail)
        {
            nail.Highlight();
        }
    }
Ejemplo n.º 6
0
 //call to remove nail from unused nails. Call when nail is attached completely in the wall or has been hit wrong (is broken), or when gameobject is whyever destroyed
 public void RemoveNail(Nail nail)
 {
     if (UnusedNails.Contains(nail))
     {
         UnusedNails.Remove(nail);
         if (isChecking)
         {
             CheckStatus();
         }
     }
 }
Ejemplo n.º 7
0
    public void RemoveNail(GameObject nailObj)
    {
        Nail n = GetNail(nailObj);

        if (n != null)
        {
            nails.Remove(n);
        }
        Destroy(nailObj);
        HandleUnNailedProps();
    }
Ejemplo n.º 8
0
    public Line(Nail a, Nail b, float pixel_width = 1f)
    {
        nail_A = a;
        nail_B = b;

        length_m          = (b.world_pos - a.world_pos).magnitude;
        width_px          = pixel_width;
        pixel_Count       = 0;
        total_blackness   = 0f;
        average_blackness = 0f;
    }
Ejemplo n.º 9
0
    private void OnCollisionStay(Collision collision)
    {
        foreach (ContactPoint currentContact in collision.contacts)
        {
            //Check if contacting with a structure
            if (currentContact.thisCollider.name == "Tip" && currentContact.otherCollider.tag == "Structure")
            {
                //Check if the trigger being pulled
                if (ifTriggered)
                {
                    //Spawn a free nail
                    GameObject newNail   = Instantiate(nailPrefab, null);
                    Nail       newScript = newNail.GetComponent <Nail>();

                    //Reset the name
                    newNail.name = "Nail";

                    //Set the new nail's transformation
                    newNail.transform.position = tip.transform.position;
                    newNail.transform.rotation = tip.transform.rotation;
                    newNail.transform.Rotate(0.0f, -90.0f, 0.0f);

                    //Hold the nail
                    newScript.Use();

                    //Set status of nail
                    newScript.setTouch();
                    newScript.setNailed();

                    //Act to nail like a hammer
                    newScript.HitNail(3.0f, structureGroupPrefab);

                    //Nail the nail
                    newScript.NailFunction(currentContact);

                    //Act to nail like a hammer
                    //newNail.transform.Translate(newScript.getForward() * 8);

                    //Set status of nail
                    newScript.setTouch();
                    newScript.setNailed();

                    //Debug
                    //Debug.Break();
                    //Debug

                    //Reset the trigger, to make the shut only be once
                    ifTriggered = false;
                }
            }
        }
    }
Ejemplo n.º 10
0
        // POST api/values
        public HttpResponseMessage Post(Nail nail)
        {
            int    seed   = (int)DateTime.Now.Ticks;
            Random random = new Random(seed);

            nail.ReferenceId = random.Next();
            _repository.CreateScreenNailer(nail.ReferenceId, nail.Url);

            //Create a new response with an HttpStatusCode of Created 201
            var response = Request.CreateResponse <Nail>(HttpStatusCode.Created, nail);

            return(response);
        }
Ejemplo n.º 11
0
    /// <summary>
    /// Tis the magnetize effect.
    /// </summary>
    private void LookTowardsNearbyNail()
    {
        Nail nail = GetNearbyNail();

        //look towards closest nail
        if (nail)
        {
            Vector3 dirToNail = (nail.transform.position - transform.position).normalized;
            Debug.DrawRay(transform.position, dirToNail, Color.yellow, 2f);

            Vector3 eulerAngles = transform.eulerAngles;
            eulerAngles.y         = Mathf.Atan2(dirToNail.x, dirToNail.z) * Mathf.Rad2Deg;
            transform.eulerAngles = eulerAngles;
        }
    }
Ejemplo n.º 12
0
 private void SetupNextTarget()
 {
     if (targetIndex < NailsParent.transform.childCount - 1)
     {
         targetIndex++;
         targetNail        = NailsParent.transform.GetChild(targetIndex).gameObject.GetComponent <Nail>();
         startingPosition += new Vector3(targetNail.Xoffset, 0f, 0f);
         startingPosition  = new Vector3(startingPosition.x, targetNail.nailHead.transform.position.y + cashedPositionBeforeHit, startingPosition.z);
         myTransform.DOMove(startingPosition, 0.3f);
     }
     else
     {
         EventManager.RaiseEventGameOver();
     }
 }
        public void CheckDetailTrashTest()
        {
            IDetail bolt = new Bolt(1, 1, 2);

            for (int i = 0; i < 100; i++)
            {
                if (checkerContainer.CheckDetail(bolt))
                {
                    Assert.IsTrue(checkerContainer.CheckDetail(bolt));
                    break;
                }
            }

            IDetail screw = new Screw(1, 1, 2);

            for (int i = 0; i < 100; i++)
            {
                if (checkerContainer.CheckDetail(bolt))
                {
                    Assert.IsTrue(checkerContainer.CheckDetail(screw));
                    break;
                }
            }

            IDetail nail = new Nail(1, 1, 2);

            for (int i = 0; i < 100; i++)
            {
                if (checkerContainer.CheckDetail(bolt))
                {
                    Assert.IsTrue(checkerContainer.CheckDetail(nail));
                    break;
                }
            }

            IDetail wheel = new Wheel(1, 1, 2);

            for (int i = 0; i < 100; i++)
            {
                if (checkerContainer.CheckDetail(bolt))
                {
                    Assert.IsTrue(checkerContainer.CheckDetail(wheel));
                    break;
                }
            }
        }
        public void GetDetailEqualOfTypesTest()
        {
            Bolt bolt = new Bolt();

            Assert.AreEqual(bolt.GetType(), checkerContainer.CreateDetail(new Bolt()).GetType());

            Screw screw = new Screw();

            Assert.AreEqual(screw.GetType(), checkerContainer.CreateDetail(new Screw()).GetType());

            Nail nail = new Nail();

            Assert.AreEqual(nail.GetType(), checkerContainer.CreateDetail(new Nail()).GetType());

            Wheel wheel = new Wheel();

            Assert.AreEqual(wheel.GetType(), checkerContainer.CreateDetail(new Wheel()).GetType());
        }
        public void CheckDetailTest()
        {
            IDetail bolt = new Bolt(0.5, 0.5, 3);

            Assert.IsTrue(checkerContainer.CheckDetail(bolt));

            IDetail screw = new Screw(0.2, 0.3, 4);

            Assert.IsTrue(checkerContainer.CheckDetail(screw));

            IDetail nail = new Nail(0.2, 0.3, 4);

            Assert.IsTrue(checkerContainer.CheckDetail(nail));

            IDetail wheel = new Wheel(10, 4, 10);

            Assert.IsTrue(checkerContainer.CheckDetail(wheel));
        }
Ejemplo n.º 16
0
    private Nail GetNearbyNail()
    {
        //max assist angle
        float maxAngle = 40f;

        //max distance to check with
        float range = 3.2f;

        //snap to nearest nail lol
        Nail[] nails       = FindObjectsOfType <Nail>();
        float  closest     = float.MaxValue;
        Nail   closestNail = null;

        foreach (Nail nail in nails)
        {
            //get dir and flatten on Y, so that the math is done on the XZ plane
            Vector3 dirToNail = nail.transform.position - transform.position;
            dirToNail.y = 0f;

            //too far by distance
            if (dirToNail.sqrMagnitude > range * range)
            {
                continue;
            }

            //normalize later
            dirToNail.Normalize();

            float angle = Vector3.Angle(transform.forward, dirToNail);
            if (angle < closest && angle < maxAngle)
            {
                closest     = angle;
                closestNail = nail;
            }
        }

        return(closestNail);
    }
Ejemplo n.º 17
0
            public int CompareTo(object obj)
            {
                Nail other = (Nail)obj;

                return(position.CompareTo(other.position));
            }
Ejemplo n.º 18
0
    private void OnCollisionEnter(Collision collision)
    {
        if (ifActive)
        {
            foreach (ContactPoint contact in collision.contacts)
            {
                if (contact.thisCollider.name == "Head")
                {
                    //Debug
                    Debug.Log("Structure Group Target Collider: " + contact.otherCollider.name);
                    Debug.Log("Structure Group This Collider: " + contact.thisCollider.name);
                    //Debug

                    if (contact.otherCollider.tag == "Structure")
                    {
                        GameObject thisNail       = contact.thisCollider.transform.parent.gameObject;
                        Nail       thisScript     = thisNail.GetComponent <Nail>();
                        GameObject otherStructure = contact.otherCollider.gameObject;
                        Structure  otherScript    = otherStructure.GetComponent <Structure>();

                        //Check if target structure is single or not
                        if (!otherScript.trackingManager)
                        {
                            //If target structure is single, add into structure group
                            //Debug
                            Debug.Log("Structure Group add new structure: " + otherStructure);
                            //Debug

                            //Try to remove rigid body
                            if (otherStructure.GetComponent <Rigidbody>())
                            {
                                Destroy(otherStructure.GetComponent <Rigidbody>());
                            }

                            //Try to remove the grabbale
                            if (otherStructure.GetComponent <OVRGrabbable>())
                            {
                                Destroy(otherStructure.GetComponent <OVRGrabbable>());
                            }

                            //Add as child and start tracking
                            otherStructure.transform.parent = transform;
                            //AddChild(otherStructure.transform);

                            //Update the target structure
                            otherScript.trackingManager = gameObject;

                            //Connect nail and structure
                            thisNail.GetComponent <Nail>().addToConnect(otherStructure);
                            otherScript.AddConnect(thisNail);
                        }
                        else
                        {
                            //Get the target manager
                            GameObject targetManager = otherScript.trackingManager;

                            //Disable the target tracking manager
                            targetManager.GetComponent <StructureGroup>().ifActive = false;

                            //Debug
                            Debug.Log("SG Trans: from " + targetManager.name + " to " + gameObject.name);
                            Debug.Log("SG Trans: target child num is: " + targetManager.transform.childCount);
                            //Debug

                            //Transfer all the child to this manager
                            //Use the while loop here in order to correct tracking the child number
                            //The old version with for loop will make the counter change as child moved
                            while (targetManager.transform.childCount > 0)
                            {
                                //Get child
                                GameObject currentObject = targetManager.transform.GetChild(0).gameObject;

                                //Debug
                                //targetList.Add(currentObject);
                                //continue;
                                //Debug.Log("SG Trans: Total child: " + targetManager.transform.childCount);
                                //Debug.Log("SG Trans: target " + i + " child is");
                                //Debug.Log(currentObject.name);
                                //Debug

                                //Start to tracking the child
                                //AddChild(currentObject.transform);

                                //Debug
                                //currentObject.GetComponent<Renderer>().material.color = new Color(255, 0, 0);
                                //Debug

                                //Check if stud or nail
                                if (currentObject.tag == "Tools")
                                {
                                    //Debug
                                    Debug.Log("SG Trans: Find Tool '" + currentObject.name + "' in " + targetManager.name);
                                    //Debug

                                    //Set manager
                                    Nail currentScript = currentObject.GetComponent <Nail>();
                                    currentScript.structureGroup = this.gameObject;
                                }
                                else if (currentObject.tag == "Structure")
                                {
                                    //Set manager
                                    Structure currentScript = currentObject.GetComponent <Structure>();
                                    currentScript.trackingManager = this.gameObject;
                                }

                                //Transfer child
                                currentObject.transform.parent = transform;
                            }

                            //Debug
                            //thisNail.GetComponent<Renderer>().material.color = new Color(255, 0, 0);
                            //otherStructure.GetComponent<Renderer>().material.color = new Color(255, 0, 0);
                            //Debug

                            //Connect nail and structure
                            thisScript.addToConnect(otherStructure);
                            otherScript.AddConnect(thisNail);

                            //Debug.log
                            Debug.Log("SG Trans finish.");
                            //Debug

                            //Destroy target manager
                            Destroy(targetManager);
                        }

                        //Debug
                        //targetList = IterateChild();
                        //Debug
                    }
                }
            }
        }
    }
Ejemplo n.º 19
0
    public void Draw_Line(Nail nail_A, Nail nail_B, float width, Color color)
    {
        Vector2 direction_AB = nail_B.pixel_pos - nail_A.pixel_pos;

        if (direction_AB.x >= direction_AB.y)           // Run >= rise
        {
            // Iterate in x and compute y

            Vector2 start_pos, end_pos;

            if (direction_AB.x > 0)
            {
                start_pos = nail_A.pixel_pos;
                end_pos   = nail_B.pixel_pos;
            }
            else
            {
                // Reverse the vector
                start_pos = nail_B.pixel_pos;
                end_pos   = nail_A.pixel_pos;

                direction_AB *= -1f;
            }

            float slope = direction_AB.y / direction_AB.x;
            float theta = Mathf.Atan2(direction_AB.y, direction_AB.x);

            for (float x = start_pos.x; x <= end_pos.x; x += 1f)
            {
                float dx        = x - start_pos.x;
                float y_central = start_pos.y + slope * dx;

                float y_thickness = width / Mathf.Cos(theta);                                   // Because Trigonometry

                float y_low  = y_central - (y_thickness / 2f);
                float y_high = y_central + (y_thickness / 2f);

                for (float y = y_low; y <= y_high; y += 1f)
                {
                    texture.SetPixel((int)x, (int)y, color);
                }
            }
        }

        else
        {
            // Iterate in y and compute x

            Vector2 start_pos, end_pos;

            if (direction_AB.y > 0)
            {
                start_pos = nail_A.pixel_pos;
                end_pos   = nail_B.pixel_pos;
            }
            else
            {
                // Reverse the vector
                start_pos = nail_B.pixel_pos;
                end_pos   = nail_A.pixel_pos;

                direction_AB *= -1f;
            }

            float slope = direction_AB.x / direction_AB.y;
            float theta = Mathf.Atan2(direction_AB.x, direction_AB.y);

            for (float y = start_pos.y; y <= end_pos.y; y += 1f)
            {
                float dy        = y - start_pos.y;
                float x_central = start_pos.x + slope * dy;

                float x_thickness = width / Mathf.Cos(theta);                                   // Because Trigonometry

                float x_low  = x_central - (x_thickness / 2f);
                float x_high = x_central + (x_thickness / 2f);

                for (float x = x_low; x <= x_high; x += 1f)
                {
                    texture.SetPixel((int)x, (int)y, color);
                }
            }
        }

        Update_Texture();
    }
Ejemplo n.º 20
0
 // Start is called before the first frame update
 void Start()
 {
     parent = null;
     childStructureGroup = null;
     ifNailed            = false;
 }
Ejemplo n.º 21
0
    private IEnumerator SpawnWithDelay()
    {
        yield return(new WaitForEndOfFrame());

        data = LevelsDifficultyContainer.Houses[LevelContainer.CurrentHouseNumber - 1].levelsData[LevelContainer.CurrentLevelIndex];

        numberOfNails = LevelContainer.NumberOfNails;
        int i = 0;

        while (i < numberOfNails)
        {
            yield return(new WaitForEndOfFrame());

            int index = Random.Range(1, 7);

            switch (index)
            {
            case 1:
                if (spawnedDefaultNails < data.numberOfDefaultNails)
                {
                    Nail defNail = Instantiate(defaultNail, defaultNail.transform.position + new Vector3(Xoffset * i, 0f, 0f), Quaternion.identity) as DefaultNail;
                    defNail.gameObject.transform.SetParent(transform);
                    defNail.Xoffset = Xoffset;

                    spawnedDefaultNails++;
                    i++;
                }
                break;

            case 2:
                if (spawnedRedNails < data.numberOfRedNails)
                {
                    Nail rNail = Instantiate(redNail, redNail.transform.position + new Vector3(Xoffset * i, 0f, 0f), Quaternion.identity) as RedNail;
                    rNail.gameObject.transform.SetParent(transform);
                    rNail.Xoffset = Xoffset;

                    spawnedRedNails++;
                    i++;
                }
                break;

            case 3:
                if (spawnedMediumNails < data.numberOfMediumNails)
                {
                    Nail mNail = Instantiate(mediumNail, mediumNail.transform.position + new Vector3(Xoffset * i, 0f, 0f), Quaternion.identity) as MediumNail;
                    mNail.gameObject.transform.SetParent(transform);
                    mNail.Xoffset = Xoffset;

                    spawnedMediumNails++;
                    i++;
                }
                break;

            case 4:
                if (spawnedMovingDefaultNails < data.movingDefaultNails)
                {
                    Nail defNail = Instantiate(defaultNail, defaultNail.transform.position + new Vector3(Xoffset * i, 0f, 0f), Quaternion.identity) as DefaultNail;
                    defNail.gameObject.transform.SetParent(transform);
                    defNail.Xoffset = Xoffset;

                    defNail.transform.position = defNail.DefaultPosition;
                    defNail.isMoving           = true;

                    spawnedMovingDefaultNails++;
                    i++;
                }
                break;

            case 5:
                if (spawnedMovingRedNails < data.movingRedNails)
                {
                    Nail rNail = Instantiate(redNail, redNail.transform.position + new Vector3(Xoffset * i, 0f, 0f), Quaternion.identity) as RedNail;
                    rNail.gameObject.transform.SetParent(transform);
                    rNail.Xoffset = Xoffset;

                    rNail.transform.position = rNail.DefaultPosition;
                    rNail.isMoving           = true;

                    spawnedMovingRedNails++;
                    i++;
                }
                break;

            case 6:
                if (spawnedMovingMediumNails < data.movingMediumNails)
                {
                    Nail mNail = Instantiate(mediumNail, mediumNail.transform.position + new Vector3(Xoffset * i, 0f, 0f), Quaternion.identity) as MediumNail;
                    mNail.gameObject.transform.SetParent(transform);
                    mNail.Xoffset = Xoffset;

                    mNail.transform.position = mNail.DefaultPosition;
                    mNail.isMoving           = true;

                    spawnedMovingMediumNails++;
                    i++;
                }
                break;
            }
        }
    }