public void OnCollisionEnter(Collision collision)
    {
        if (timeSinceInstantiated >= cooldownTime)
        {
            if (collision.impactForceSum.magnitude >= requiredForce)
            {
                // Find the new contact point
                foreach (ContactPoint contact in collision.contacts)
                {
                    if (contact.otherCollider == collision.collider)
                    {
                        // Shatter at this contact point
                        if (scheduler != null)
                        {
                            scheduler.AddTask(new ShatterTask(contact.thisCollider.gameObject, contact.point));
                        }
                        else
                        {
                            contact.thisCollider.SendMessage("Shatter", contact.point, SendMessageOptions.DontRequireReceiver);
                        }

                        break;
                    }
                }
            }
        }
    }
Exemple #2
0
    public void Update()
    {
        if (Input.GetMouseButtonDown(0))
        {
            start = Input.mousePosition;

            started = true;
        }

        if (Input.GetMouseButtonUp(0) && started)
        {
            end = Input.mousePosition;

            // Calculate the world-space line
            Camera mainCamera = Camera.main;

            float near = mainCamera.nearClipPlane;

            Vector3 line = mainCamera.ScreenToWorldPoint(new Vector3(end.x, end.y, near)) - mainCamera.ScreenToWorldPoint(new Vector3(start.x, start.y, near));

            // Find game objects to split by raycasting at points along the line
            for (int i = 0; i < raycastCount; i++)
            {
                Ray ray = mainCamera.ScreenPointToRay(Vector3.Lerp(start, end, (float)i / raycastCount));

                RaycastHit hit;

                if (Physics.Raycast(ray, out hit))
                {
                    if (!hit.transform.tag.Equals("Split"))
                    {
                        continue;
                    }
                    Plane splitPlane = new Plane(Vector3.Normalize(Vector3.Cross(line, ray.direction)), hit.point);

                    if (scheduler != null)
                    {
                        scheduler.AddTask(new SplitTask(hit.collider.gameObject, new Plane[] { splitPlane }));
                    }
                    else
                    {
                        GameObject[] objs = hit.transform.GetComponent <ShatterTool>().Split(new Plane[] { splitPlane });
                        if (objs.Length == 2)
                        {
                            MoveAway(objs[0], objs[1], end - start);
                        }
                        //hit.collider.SendMessage("Split", new Plane[] { splitPlane }, SendMessageOptions.DontRequireReceiver);
                    }
                }
            }

            started = false;
        }
    }
Exemple #3
0
    public void Update()
    {
        if (Input.GetMouseButtonDown(1))
        {
            start = Input.mousePosition;

            started = true;
        }

        if (Input.GetMouseButtonUp(1) && started)
        {
            end = Input.mousePosition;

            // Calculate the world-space line
            Camera mainCamera = Camera.main;

            float near = mainCamera.near;

            Vector3 line = mainCamera.ScreenToWorldPoint(new Vector3(end.x, end.y, near)) - mainCamera.ScreenToWorldPoint(new Vector3(start.x, start.y, near));

            // Find game objects to split by raycasting at points along the line
            for (int i = 0; i < raycastCount; i++)
            {
                Ray ray = mainCamera.ScreenPointToRay(Vector3.Lerp(start, end, (float)i / raycastCount));

                RaycastHit hit;

                if (Physics.Raycast(ray, out hit))
                {
                    Plane splitPlane = new Plane(Vector3.Normalize(Vector3.Cross(line, ray.direction)), hit.point);

                    if (scheduler != null)
                    {
                        scheduler.AddTask(new SplitTask(hit.collider.gameObject, new Plane[] { splitPlane }));
                    }
                    else
                    {
                        hit.collider.SendMessage("Split", new Plane[] { splitPlane }, SendMessageOptions.DontRequireReceiver);
                    }
                }
            }

            started = false;
        }
    }
Exemple #4
0
    public void Update()
    {
        if (Input.GetMouseButtonDown(0))
        {
            RaycastHit hit;

            if (Physics.Raycast(Camera.mainCamera.ScreenPointToRay(Input.mousePosition), out hit))
            {
                if (scheduler != null)
                {
                    scheduler.AddTask(new ShatterTask(hit.collider.gameObject, hit.point));
                }
                else
                {
                    hit.collider.SendMessage("Shatter", hit.point, SendMessageOptions.DontRequireReceiver);
                }
            }
        }
    }
Exemple #5
0
    IEnumerator model_slice()
    {
        string name;
        bool   finish = false;

        for (int i = 0; i < 4; i++)
        {
            for (int j = 0; j < slice_model[i].Count; j++)
            {
                name = slice_model[i][j].ToString();

                if (!_3ds.Contains(name))
                {
                    _3ds.Add(name);
                }
                if (i > 0)
                {
                    if (GameObject.Find(name + "_C") != null)
                    {
                        name = name + "_C";
                    }
                }
                if (scheduler != null)
                {
                    scheduler.AddTask(new SplitTask(GameObject.Find(name), new Plane[] { (Plane)splitPlane[i] }));
                }
                if (i == 3)
                {
                    finish = true;
                }
            }
            yield return(new WaitForSeconds(0.1f));
        }
        if (finish)
        {
            Invoke("model_show", 0.1f);
        }
    }