Ejemplo n.º 1
0
    private void Update()
    {
        if (isTouched == true)
        {
            isTouched = false;

            Collider[] objectsToBeSliced = Physics.OverlapBox(transform.position, new Vector3(1, 0.1f, 0.1f), transform.rotation, sliceMask);

            foreach (Collider objectToBeSliced in objectsToBeSliced)
            {
                SlicedHull slicedObject = SliceObject(objectToBeSliced.gameObject, materialAfterSlice);

                GameObject upperHullGameobject = slicedObject.CreateUpperHull(objectToBeSliced.gameObject, materialAfterSlice);
                GameObject lowerHullGameobject = slicedObject.CreateLowerHull(objectToBeSliced.gameObject, materialAfterSlice);

                upperHullGameobject.transform.position = objectToBeSliced.transform.position;
                lowerHullGameobject.transform.position = objectToBeSliced.transform.position;

                MakeItPhysical(upperHullGameobject);
                MakeItPhysical(lowerHullGameobject);

                MakeItSliceable(upperHullGameobject);
                MakeItSliceable(lowerHullGameobject);

                Destroy(objectToBeSliced.gameObject);
            }
        }
    }
Ejemplo n.º 2
0
    private void slice(GameObject gameObject, Material mat, Vector3 colPoint)
    {
        GameObject child = gameObject.transform.GetChild(0).gameObject;

        SlicedHull slicedObject = EzySlice(gameObject, colPoint, mat);
        SlicedHull slicedChild  = EzySlice(child, colPoint, mat);

        GameObject upper;
        GameObject lower;
        GameObject upperChild;
        GameObject lowerChild;

        try
        {
            upper = slicedObject.CreateUpperHull(gameObject, mat);
            lower = slicedObject.CreateLowerHull(gameObject, mat);

            upperChild = slicedChild.CreateUpperHull(child, mat);
            lowerChild = slicedChild.CreateLowerHull(child, mat);
        }
        catch (System.Exception)
        {
            Destroy(slicedObject.upperHull);
            Destroy(slicedObject.lowerHull);
            return;
        }



        transformSetup(gameObject, child, upper, lower, upperChild, lowerChild);

        Destroy(gameObject);
    }
Ejemplo n.º 3
0
    public void Bite(Vector3 slicePlanePosition, Vector3 slicePlaneDirection)
    {
        bitesLeft--;
        Debug.DrawLine(slicePlanePosition, slicePlanePosition + slicePlaneDirection, Color.blue, 1f);
        SlicedHull slicedHull = meshObject.Slice(slicePlanePosition, slicePlaneDirection, meshObject.GetComponent <Renderer>().material);

        if (slicedHull != null)
        {
            GameObject slicedMesh = slicedHull.CreateUpperHull();
            slicedMesh.GetComponent <Renderer>().material = meshObject.GetComponent <Renderer>().material;
            slicedMesh.transform.parent     = this.transform;
            slicedMesh.transform.position   = meshObject.transform.position;
            slicedMesh.transform.rotation   = meshObject.transform.rotation;
            slicedMesh.transform.localScale = meshObject.transform.localScale;
            slicedMesh.tag = "Food";

            MeshCollider meshCollider = (MeshCollider)slicedMesh.AddComponent(typeof(MeshCollider));
            meshCollider.sharedMesh = slicedMesh.GetComponent <MeshFilter>().mesh;
            meshCollider.convex     = true;

            meshObject.tag = "Untagged";
            Destroy(meshObject);
            meshObject = slicedMesh;
        }

        munchFx.Play();
    }
Ejemplo n.º 4
0
        private void Cut(SlicedHull sliceController)
        {
            if (sliceController == null)
            {
                return;
            }

            objectToSlice.SetActive(false);

            Base left  = sliceController.CreateLowerHull(objectToSlice, material).AddComponent(typeof(Base)) as Base;
            Base right = sliceController.CreateUpperHull(objectToSlice, material).AddComponent(typeof(Base)) as Base;

            left.SetRotationY(objectToSlice.transform.eulerAngles.y);
            right.SetRotationY(objectToSlice.transform.eulerAngles.y);

            slicedObjectLeftPos.SetPositionY(left.GetPositionY());
            slicedObjectRightPos.SetPositionY(right.GetPositionY());

            AnimateSlicedObjectMovement(left, slicedObjectLeftPos.position);
            AnimateSlicedObjectMovement(right, slicedObjectRightPos.position, () => AnimateNextMesh());

            int leftPercentage, rightPercentage;

            CalculateSlicePercentage(left.GetComponent <MeshFilter>().mesh, right.GetComponent <MeshFilter>().mesh, out leftPercentage, out rightPercentage);
            IncreaseGameProgress(leftPercentage, rightPercentage);
            Events.SuccessfulSlice.Call(leftPercentage, rightPercentage);
        }
        public static GameObject[] SliceInstantiate(this GameObject obj, Plane pl, TextureRegion cuttingRegion, Material crossSectionMaterial = null)
        {
            SlicedHull slice = Slicer.Slice(obj, pl, cuttingRegion, crossSectionMaterial);

            if (slice == null)
            {
                return(null);
            }

            GameObject upperHull = slice.CreateUpperHull(obj, crossSectionMaterial);
            GameObject lowerHull = slice.CreateLowerHull(obj, crossSectionMaterial);

            if (upperHull != null && lowerHull != null)
            {
                return(new GameObject[] { upperHull, lowerHull });
            }

            // otherwise return only the upper hull
            if (upperHull != null)
            {
                return(new GameObject[] { upperHull });
            }

            // otherwise return only the lower hull
            if (lowerHull != null)
            {
                return(new GameObject[] { lowerHull });
            }

            // nothing to return, so return nothing!
            return(null);
        }
Ejemplo n.º 6
0
        public void Slice(Transform noteTransform, Vector3 direction, Vector3 rightDirection, int noteType, float hitVelocity)
        {
            baseNote.transform.position = noteTransform.position;
            baseNote.transform.rotation = noteTransform.rotation;

            baseNote.GetComponent <Renderer>().material = noteType == 1 ? RightMatMaterial : LeftMatMaterial;

            Material material = noteType == 1 ? RightCutMaterial : LeftCutMaterial;

            SlicedHull hull         = baseNote.Slice(baseNote.gameObject.transform.position, direction, material);
            var        forwardForce = baseNote.transform.forward;

            if (hitVelocity >= 4)
            {
                hitVelocity = 4;
            }

            if (hull != null)
            {
                GameObject hullObject = hull.CreateLowerHull(baseNote.gameObject, material);
                var        rigidbody  = hullObject.AddComponent <Rigidbody>();
                rigidbody.AddForce((rightDirection + forwardForce) * hitVelocity * forceMultiplier);
                Destroy(hullObject, 10);

                hullObject = hull.CreateUpperHull(baseNote.gameObject, material);
                rigidbody  = hullObject.AddComponent <Rigidbody>();
                rigidbody.AddForce((-rightDirection + forwardForce) * hitVelocity * forceMultiplier);
                Destroy(hullObject, 10);
            }
        }
Ejemplo n.º 7
0
    // Update is called once per frame
    void Update()
    {
        float mx = Input.GetAxis("Mouse X");

        transform.Rotate(0, 0, mx);

        if (Input.GetMouseButtonDown(0))
        {
            Collider[] colliders = Physics.OverlapBox(transform.position, new Vector3(4, 0.005f, 4), transform.rotation, ~LayerMask.GetMask("Solid"));

            foreach (Collider c in colliders)
            {
                Destroy(c.gameObject);
                //GameObject[] objs = c.gameObject.SliceInstantiate(transform.position, transform.up);

                SlicedHull hull = c.gameObject.Slice(transform.position, transform.up);
                if (hull != null)
                {
                    GameObject   lower = hull.CreateLowerHull(c.gameObject, matCross);
                    GameObject   upper = hull.CreateUpperHull(c.gameObject, matCross);
                    GameObject[] objs  = new GameObject[] { lower, upper };

                    foreach (GameObject obj in objs)
                    {
                        Rigidbody rb = obj.AddComponent <Rigidbody>();
                        obj.AddComponent <MeshCollider>().convex = true;
                        rb.AddExplosionForce(100, c.gameObject.transform.position, 20);
                    }
                }
            }
        }
    }
Ejemplo n.º 8
0
    // Update is called once per frame
    void Update()
    {
        float mx = Input.GetAxis("Mouse X"); // 获取鼠标左右方向的移动量  鼠标固定不动时 mx值为0

        transform.Rotate(0, 0, -mx);         // 使鼠标的移动作为切割面的旋转角度

        if (Input.GetMouseButtonDown(0))     // 点击鼠标左键时
        {
            // 碰撞检测,投射一个立方体盒子 中心为刀片的中心 用于检测刀片上存在的物体 并将检测到的这些物体存放于colliders数组中  排除layer的名称为Solid的物体(保证地板和刀片本身不被切割)
            Collider[] colliders = Physics.OverlapBox(transform.position, new Vector3(4, 0.005f, 4), transform.rotation, ~LayerMask.GetMask("Solid"));

            foreach (Collider c in colliders)
            {
                // 遍历刀片上获取到的物体
                Destroy(c.gameObject);
                //GameObject[] objs = c.gameObject.SliceInstantiate(transform.position, transform.up);  // 指定刀片的位置和法线方向,SliceInstantiate将物体c切割成两部分,以数组形式返回
                SlicedHull hull = c.gameObject.Slice(transform.position, transform.up);  // 切口处理,
                if (hull != null)
                {
                    // 物体被切开后切口部分没有材质,显示为紫红色,所以需要给切口上材质球
                    GameObject   lower = hull.CreateLowerHull(c.gameObject, matCross); // 物体被切开后的下部分  matCross指定填充的材质  填充到切口上
                    GameObject   upper = hull.CreateUpperHull(c.gameObject, matCross); // 物体被切开后的下部分
                    GameObject[] objs  = new GameObject[] { lower, upper };

                    foreach (GameObject obj in objs)                                        // 遍历所有被切割后新产生的物体
                    {
                        Rigidbody newObj = obj.AddComponent <Rigidbody>();                  // 为切割后新产生的物体添加刚体属性
                        obj.AddComponent <MeshCollider>().convex = true;                    // 为切割后新产生的物体添加网格碰撞体属性  并勾选convex  否则物体会穿透地板
                        // 注意刀片的碰撞体属性可以删除掉  否则切割完成的物体上半部分会停留在刀片表面掉不下去
                        newObj.AddExplosionForce(100, c.gameObject.transform.position, 20); // 给切割后的两个物体添加爆炸效果  爆炸力度  爆炸位置  爆炸半径
                    }
                }
            }
        }
    }
Ejemplo n.º 9
0
    // Update is called once per frame
    void Update()
    {
        if (Input.GetKeyDown("space"))
        {
            Collider[] objectsToSlice = Physics.OverlapBox(transform.position, new Vector3(1, 0.1f, 0.1f), transform.rotation, sliceMask);
            foreach (Collider objectToSlice in objectsToSlice)
            {
                //Slices the main object
                SlicedHull slicedObject = SliceObject(objectToSlice.gameObject, MaterialAfterSlice);

                //Creates the upper part  of the Slice
                GameObject upperHullGameobject = slicedObject.CreateUpperHull(objectToSlice.GetComponent <Collider>().gameObject, MaterialAfterSlice);

                //Creates the lower part of the Slice
                GameObject lowerHullGameobject = slicedObject.CreateLowerHull(objectToSlice.GetComponent <Collider>().gameObject, MaterialAfterSlice);


                MakeItPhysical(lowerHullGameobject);
                MakeItPhysical(upperHullGameobject);

                //Destroys the main object that was sliced
                Destroy(objectToSlice.gameObject);
            }
        }
    }
Ejemplo n.º 10
0
    public override void OnInspectorGUI()
    {
        PlaneUsageExample plane = (PlaneUsageExample)target;

        source = (GameObject)EditorGUILayout.ObjectField(source, typeof(GameObject), true);

        if (source == null)
        {
            EditorGUILayout.LabelField("Add a GameObject to Slice.");

            return;
        }

        if (!source.activeInHierarchy)
        {
            EditorGUILayout.LabelField("Object is Hidden. Cannot Slice.");

            return;
        }

        if (source.GetComponent <MeshFilter>() == null)
        {
            EditorGUILayout.LabelField("GameObject must have a MeshFilter.");

            return;
        }

        crossMat       = (Material)EditorGUILayout.ObjectField(crossMat, typeof(Material), true);
        recursiveSlice = (bool)EditorGUILayout.Toggle("Recursive Slice", recursiveSlice);

        if (GUILayout.Button("Cut Object"))
        {
            // only slice the parent object
            if (!recursiveSlice)
            {
                SlicedHull hull = plane.SliceObject(source);

                if (hull != null)
                {
                    hull.CreateLowerHull(source, crossMat);
                    hull.CreateUpperHull(source, crossMat);

                    source.SetActive(false);
                }
            }
            else
            {
                // in here we slice both the parent and all child objects
                SliceObjectRecursive(plane, source);

                source.SetActive(false);
            }
        }
    }
Ejemplo n.º 11
0
Archivo: Saw.cs Proyecto: uuzgu/Games
    // Update is called once per frame
    void Update()
    {
        if (isCutting == false)
        {
            transform.Rotate(new Vector3(0f, 1500f * Time.deltaTime, 0f));
        }
        if (Input.GetKey(KeyCode.D) || Input.GetKey(KeyCode.RightArrow))
        {
            transform.position = new Vector3(Mathf.Clamp(transform.position.x + 5f * Time.deltaTime, -1, 1),
                                             transform.position.y, transform.position.z);
        }

        if (Input.GetKey(KeyCode.A) || Input.GetKey(KeyCode.LeftArrow))
        {
            transform.position = new Vector3(Mathf.Clamp(transform.position.x - 5f * Time.deltaTime, -1, 1),
                                             transform.position.y, transform.position.z);
        }

        int x = 1;

        if (Time.time > i)
        {
            i += 2;
            int random  = Random.Range(0, 5); // to spawn random woods
            int random2 = Random.Range(1, 3); // to spawn woods at random locations
            Instantiate(wood[random], new Vector3(-1.5f + random2, 7f, 10f), Quaternion.Euler(0, 0, 90));
        }
        Collider[] cuttingObjects = Physics.OverlapBox(transform.position, new Vector3(0.1f, 0.1f, 0f), transform.rotation, mask);
        foreach (Collider nesne in cuttingObjects) // cutting
        {
            transform.Rotate(new Vector3(0f, 500f * Time.deltaTime, 0f));
            isCutting = true;
            StartCoroutine(isCuttingWood());

            hit.Play();

            x++;
            Debug.Log(x);
            SlicedHull cuttingObject = Cut(nesne.gameObject, mat);
            GameObject kesilmisUst   = cuttingObject.CreateUpperHull(nesne.gameObject, mat);
            GameObject kesilmisAlt   = cuttingObject.CreateLowerHull(nesne.gameObject, mat);
            Instantiate(effect, new Vector3(transform.position.x, transform.position.y - 0.4f, transform.position.z + 3f), Quaternion.Euler(-40f, 180f, 0f));
            CameraShake.Shake(0.4f, 0.3f);

            AddBody(kesilmisUst);
            AddBody(kesilmisAlt);

            Destroy(nesne.gameObject);
        }
    }
Ejemplo n.º 12
0
 private void Update()
 {
     if (Input.GetKeyDown(KeyCode.Alpha1))
     {
         SlicedHull hull   = SliceObject(cube, null);
         GameObject bottom = hull.CreateLowerHull(cube, null);
         GameObject top    = hull.CreateUpperHull(cube, null);
         bottom.gameObject.transform.localScale = new Vector3(1.3f, 1.3f, 1.3f);
         top.gameObject.transform.localScale    = new Vector3(1.3f, 1.3f, 1.3f);
         Destroy(cube);
         AddHullComponents(bottom);
         AddHullComponents(top);
     }
 }
Ejemplo n.º 13
0
    // Update is called once per frame
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.C))
        {
            SlicedHull hull = source.Slice(transform.position, transform.up); // 参数一为切割的位置(刀片的位置),第二个参数为切割面的法向量
            hull.CreateUpperHull(source);                                     // 创建把source切割以后的上半部分物体
            hull.CreateLowerHull(source);                                     // 下半部分物体
            source.SetActive(false);                                          // 销毁原物体

            //SlicedHull hull1 = source1.Slice(transform.position, transform.up);  // 参数一为切割的位置(刀片的位置),第二个参数为切割面的法向量
            //hull1.CreateUpperHull(source1);  // 创建把source1切割以后的上半部分物体
            //hull1.CreateLowerHull(source1);  // 下半部分物体
            //source1.SetActive(false);  // 销毁原物体
        }
    }
Ejemplo n.º 14
0
    public GameObject[] sliceGameObjectConvex(GameObject gameObjectToSlice, Vector3 position, float rotationAngle) {
        GameObject slicerPlane = Instantiate(Resources.Load("SlicerPlanePrefab"), position, Quaternion.identity) as GameObject;
        slicerPlane.transform.eulerAngles = this.transform.eulerAngles + new Vector3(0, 0, slicerAngle.getSlicerAngle());
        slicerPlane.transform.Rotate(new Vector3(rotationAngle, 0, 0), Space.Self);
        SlicedHull slicedHull = slicerPlane.GetComponent<PlaneUsageExample>().SliceObject(gameObjectToSlice);
        if (slicedHull == null)
        {
            return null;
        }
        GameObject upperHull = slicedHull.CreateUpperHull(gameObjectToSlice, gameObjectToSlice.GetComponent<MeshRenderer>().material);
        GameObject lowerHull = slicedHull.CreateLowerHull(gameObjectToSlice, gameObjectToSlice.GetComponent<MeshRenderer>().material);
        Destroy(slicerPlane);

        return new GameObject[] {upperHull, lowerHull};
    }
Ejemplo n.º 15
0
    public void Cut(Vector3 planeWorldPosition, Vector3 planeWorldDirection)
    {
        SlicedHull cut = GetHull(planeWorldPosition, planeWorldDirection, new TextureRegion(0.0f, 0.0f, 1.0f, 1.0f));

        GameObject leftCut  = cut.CreateUpperHull(gameObject);
        GameObject rightCut = cut.CreateLowerHull(gameObject);

        leftCut.tag  = "LeftHull";
        rightCut.tag = "RightHull";

        AddComponents(leftCut, planeWorldDirection);
        AddComponents(rightCut, -planeWorldDirection);

        gameObject.SetActive(false);
        SpawnManager.instance.Enqueue(gameObject);
    }
Ejemplo n.º 16
0
    private void CutterFunc()
    {
        Collider[] cutableObj = Physics.OverlapBox(transform.position, new Vector3(0.1f, 1f, 1f), transform.rotation, layerMask);

        foreach (var item in cutableObj)
        {
            SlicedHull cutedobj    = Cut(item.gameObject, material);
            GameObject Cuttedleft  = cutedobj.CreateUpperHull(item.gameObject, material);
            GameObject Cuttedright = cutedobj.CreateLowerHull(item.gameObject, material);

            AddCompenent(Cuttedleft);
            AddCompenent(Cuttedright);

            Destroy(item.gameObject);
        }
    }
Ejemplo n.º 17
0
    //Check you slice a fruit or not , and slice it!
    public void Slice(GameObject _Fruit, Weapon weapon)
    {
        SlicedHull slicedObject = Sliceed(_Fruit, weapon.slicePanel, sliceMaterial);

        if (slicedObject != null)
        {
            if (_Fruit.CompareTag("fruit"))
            {
                _Fruit.SetActive(false);
                Fruit fruit = _Fruit.GetComponent <Fruit>();
                pooler.ReycleFruit(fruit);
                if (fruit.particleTyp == particleType.Explosion)
                {
                    soundManager.BombSound();
                    weapon.Vibrate(0.5f);
                }
                else if (fruit.particleTyp == particleType.Ice)
                {
                    soundManager.FrozenSound();
                    uIManager.IncreaseScore(4);
                    weapon.Vibrate(0.2f);
                }
                else
                {
                    soundManager.SplashFruit();
                    uIManager.IncreaseScore(1);
                    weapon.Vibrate(0.1f);
                }
            }
            else if (_Fruit.CompareTag("button"))
            {
                weapon.Vibrate(0.1f);
                uIManager.BeforeSelectButton();
                soundManager.SplashFruit();
                StartCoroutine(Countdown(_Fruit));
            }
            pooler.GetParticle(_Fruit.GetComponent <Fruit>().particleTyp, _Fruit.transform.position, _Fruit.transform.rotation);
            GameObject upperPart = slicedObject.CreateUpperHull(_Fruit);
            GameObject lowPart   = slicedObject.CreateLowerHull(_Fruit);
            AddComponents(upperPart);
            AddComponents(lowPart);
        }
        else
        {
            Debug.Log("null");
        }
    }
        private void Slice(GameObject objectToSlice, Material material)
        {
            Transform  slicePoint = ((MeshSliceShowcase)target).transform;
            SlicedHull hull       = objectToSlice.Slice(slicePoint.position, slicePoint.up, material);

            if (hull != null)
            {
                ((MeshSliceShowcase)target).objectToSlice = null;
                objectToSlice.SetActive(false);

                GameObject lower = hull.CreateLowerHull(objectToSlice, material);
                lower.AddComponent <MeshCollider>().convex = true;
                lower.AddComponent <Rigidbody>();

                GameObject upper = hull.CreateUpperHull(objectToSlice, material);
                upper.AddComponent <MeshCollider>().convex = true;
                upper.AddComponent <Rigidbody>();
            }
        }
Ejemplo n.º 19
0
    public void SliceObject(GameObject target)
    {
        SlicedHull hull = SliceObject(target, null);

        if (hull != null)
        {
            GameObject lowerObj = hull.CreateLowerHull(target, null);
            GameObject upperObj = hull.CreateUpperHull(target, null);

            Rigidbody lowerrd = lowerObj.AddComponent <Rigidbody>();
            Rigidbody uprd    = upperObj.AddComponent <Rigidbody>();

            lowerObj.AddComponent <MeshCollider>().convex = true;
            upperObj.AddComponent <MeshCollider>().convex = true;

            lowerrd.AddExplosionForce(500f, -transform.right, 5f);
            uprd.AddExplosionForce(500f, transform.right, 5f);

            target.SetActive(false);
        }
    }
Ejemplo n.º 20
0
    void Slice(GameObject target, Vector3 planePosition, Vector3 slicerVelocity, BrokenOre ore)
    {
        Debug.Log("WE SLICE THE OBJECT");
        Vector3 slicingDirection = endSlicingPoint.position - startSlicingPoint.position;
        Vector3 planeNormal      = Vector3.Cross(slicerVelocity, slicingDirection);

        SlicedHull hull = target.Slice(planePosition, planeNormal, slicedMaterial);

        print(hull);
        if (hull != null)
        {
            ore.BrokenObject();
            GameObject upperHull = hull.CreateUpperHull(target, slicedMaterial);
            GameObject lowerHull = hull.CreateLowerHull(target, slicedMaterial);

            CreateSlicedComponent(upperHull);
            CreateSlicedComponent(lowerHull);

            Destroy(target);
        }
    }
Ejemplo n.º 21
0
    void Slice(Transform tr)
    {
        Collider[] hits = Physics.OverlapBox(tr.position, new Vector3(1f, 0.1f, 3f), tr.rotation, layerMask);
        if (hits.Length <= 0)
        {
            return;
        }

        for (int i = 0; i < hits.Length; i++)
        {
            SlicedHull hull = SliceObject(hits[i].gameObject, tr, sliceMaterial);
            if (hull != null)
            {
                GameObject lower = hull.CreateLowerHull(hits[i].gameObject, sliceMaterial);
                GameObject upper = hull.CreateUpperHull(hits[i].gameObject, sliceMaterial);
                AddHullCompents(lower);
                AddHullCompents(upper);
                Destroy(hits[i].gameObject);
            }
        }
    }
Ejemplo n.º 22
0
    // Update is called once per frame
    void Update()
    {
        if (Input.GetButton("Fire1"))
        {
            bladeRota = new Vector3(Input.GetAxis("Mouse Y"), Input.GetAxis("Mouse X"), 0);
            transform.Rotate(bladeRota, Space.World);
        }
        //注意 因ezySlice所限,被切割物体不得有缩放。
        if (Input.GetKeyDown(KeyCode.Space))
        {
            //BSlice(planeObject.transform.position, planeObject.transform.up);
            //Instantiate(gm[0]);
            //anim.SetTrigger("cut");

            Collider[] targets = Physics.OverlapBox(BladeObject.transform.position, new Vector3(7f, 0.1f, 10f), BladeObject.transform.rotation, layer);
            if (targets.Length <= 0)
            {
                return;
            }
            foreach (Collider target in targets)
            {
                SlicedHull result = target.gameObject.Slice(BladeObject.transform.position, BladeObject.transform.up);
                if (result != null)
                {
                    GameObject up   = result.CreateUpperHull(target.gameObject, mat);
                    GameObject down = result.CreateLowerHull(target.gameObject, mat);
                    up.layer   = 8;
                    down.layer = 8;
                    up.AddComponent <MeshCollider>().convex   = true;
                    down.AddComponent <MeshCollider>().convex = true;
                    Rigidbody rigU = up.AddComponent <Rigidbody>();
                    Rigidbody rigD = down.AddComponent <Rigidbody>();
                    rigU.AddExplosionForce(100, down.transform.position, 10);
                    rigD.AddExplosionForce(100, down.transform.position, 10);
                    Destroy(target.gameObject);
                }
            }
        }
    }
        public void Slice()
        {
            Collider[] hits = Physics.OverlapBox(cutPlane.position, new Vector3(5, 0.1f, 5f), cutPlane.rotation, layerMask);

            if (hits.Length <= 0)
            {
                return;
            }

            for (int i = 0; i < hits.Length; i++)
            {
                SlicedHull hull = SliceObject(hits[i].gameObject, crossMaterial);
                if (hull != null)
                {
                    GameObject bottom = hull.CreateLowerHull(hits[i].gameObject, crossMaterial);
                    GameObject top    = hull.CreateUpperHull(hits[i].gameObject, crossMaterial);
                    AddHullComponents(bottom);
                    AddHullComponents(top);
                    Destroy(hits[i].gameObject);
                }
            }
        }
Ejemplo n.º 24
0
    void Update()
    {
        if (Input.GetMouseButton(0))
        {
            //kesilebilen objeleri layer ile ayırıp bir dizi yaptık
            Collider[] slicedObjects = Physics.OverlapBox(knifeBlade.transform.position, new Vector3(knifeBlade.transform.localScale.x * 5, knifeBlade.transform.localScale.y, knifeBlade.transform.localScale.z), knifeBlade.transform.rotation, layerMask);

            foreach (Collider obj in slicedObjects)
            {
                SlicedHull slicedObj = Slice(obj.gameObject, material);
                if (slicedObj != null)
                {
                    GameObject slicedUpper = slicedObj.CreateUpperHull(obj.gameObject, material); //oluşan üst nesne
                    GameObject slicesLower = slicedObj.CreateLowerHull(obj.gameObject, material); //oluşan alt nesne

                    addComponents(slicedUpper, slicesLower);                                      // nesnelerin componentlerini ayalar

                    Destroy(obj.gameObject);                                                      // orjinal nesneyi siler
                }
            }
        }
    }
Ejemplo n.º 25
0
    private void OnCollisionEnter(Collision collision)
    {
        GameObject go = collision.GetContact(0).otherCollider.gameObject;

        Debug.Log(go);
        if (limit < 2 && go.layer == 2)
        {
            //Debug.Log(collision.gameObject);
            //go.GetComponentInParent<HandPresence>().RequestHaptic(0, 1, 0.2f);
            //move = !move;
            SlicedHull hull = SliceObject(go, null);
            gameObject.GetComponent <MeshRenderer>().enabled = false;
            if (hull != null)
            {
                GameObject bottom = hull.CreateLowerHull(gameObject, null);
                GameObject top    = hull.CreateUpperHull(gameObject, null);
                AddHullComponents(bottom);
                AddHullComponents(top);
            }
            //gameObject.transform.parent = collision.gameObject.transform;
            limit++;
        }
    }
    public bool Slice(GameObject objectToSlice, Material material, Transform slicePoint)
    {
        //Transform slicePoint = ((MeshSliceShowcase)target).transform;
        SlicedHull hull = objectToSlice.Slice(slicePoint.position, slicePoint.forward, material);

        if (hull != null)
        {
            objectToSlice.SetActive(false);

            GameObject lower = hull.CreateLowerHull(objectToSlice, material);
            lower.AddComponent <MeshCollider>().convex = true;
            lower.AddComponent <Rigidbody>();

            GameObject upper = hull.CreateUpperHull(objectToSlice, material);
            upper.AddComponent <MeshCollider>().convex = true;
            upper.AddComponent <Rigidbody>();

            AudioManager.Instance.PlaySlice();
            return(true);
        }

        return(false);
    }
Ejemplo n.º 27
0
 // Cut the gameobjects and add the required components to them
 public void Cut()
 {
     //Get all the colliders that can be used to created slicedhulls into an array
     Collider[] toBeCut = Physics.OverlapBox(transform.position, new Vector3(1f, 0.1f, .1f), transform.rotation, _mask);
     //Iterate through the array
     foreach (Collider col in toBeCut)
     {
         //Skip the iteration if our collider is a trigger this is done to avoid duplicate cuts
         //since the sliceable object has one trigger and one normal collider
         if (col.isTrigger)
         {
             continue;
         }
         //Create a sliced hull!
         SlicedHull CutObject = Slice(col.GetComponent <Collider>().gameObject, _mat);
         //If our cut object isn't null i.e. we made a valid cut
         if (CutObject != null)
         {
             //Create a cut up and down portion from the object
             GameObject cutup   = CutObject.CreateUpperHull(col.gameObject, _mat);
             GameObject cutdown = CutObject.CreateLowerHull(col.gameObject, _mat);
             //Add the required components (colliders etc) to the objects depending on if they're staying or flying away
             //The cut up gameobject will be the slice so it will fly away
             AddComponent(cutup, false);
             //The cut down will stay and will be sliceable
             AddComponent(cutdown, true);
             //Destroy the current game object that was just sliced
             Destroy(col.gameObject);
         }
         else
         {
             //Not a valid slice
             Debug.Log("Cutobject is null, continuing");
             break;
         }
     }
 }
Ejemplo n.º 28
0
    // Update is called once per frame
    void Update()
    {
        float mx = Input.GetAxis("Mouse X");

        transform.Rotate(0, 0, -mx);
        // cutting operation
        if (Input.GetMouseButtonDown(0))
        {
            // get the colliders
            Collider[] colliders = Physics.OverlapBox(transform.position, new Vector3(transform.localScale.x / 2, transform.localScale.y / 2, transform.localScale.z / 2), transform.rotation, maskLayer);

            foreach (Collider c in colliders)
            {
                Destroy(c.gameObject);

                // GameObject[] objs = c.gameObject.SliceInstantiate(transform.position, transform.up); // Justice, the direction to top
                SlicedHull hull = c.gameObject.Slice(transform.position, transform.up);
                if (hull != null)
                {
                    GameObject   lower = hull.CreateLowerHull(c.gameObject, matCross);
                    GameObject   upper = hull.CreateUpperHull(c.gameObject, matCross);
                    GameObject[] objs  = new GameObject[] { lower, upper };

                    foreach (GameObject obj in objs)
                    {
                        Rigidbody rg = obj.AddComponent <Rigidbody>();
                        obj.AddComponent <MeshCollider>().convex = true; // only convex can be rigid

                        // add explosion force
                        rg.AddExplosionForce(100, obj.gameObject.transform.position, 50);

                        obj.layer = maskLayerNumber;
                    }
                }
            }
        }
    }
Ejemplo n.º 29
0
    private void OnCollisionEnter(Collision collision)
    {
        // only cut with cloned scissor object that follows the original but isn't attached to the hand
        if (collision.gameObject.tag.Equals("Scissors") && collision.gameObject.name.Contains("Clone"))
        {
            Destroy(this.gameObject.GetComponent <ResetDroppedObject>());

            GameObject        cutPlane     = collision.gameObject.transform.Find(CUT_PLANE).gameObject;
            PlaneUsageExample planeExample = cutPlane.GetComponent <PlaneUsageExample>();
            Mesh objectMesh = this.gameObject.GetComponent <MeshFilter>().sharedMesh;

            Material originalMaterial = this.gameObject.GetComponent <SetCoralPieceOriginalMaterial>().originalMaterial;

            // only cut the object if it has enough triangles
            if (objectMesh.triangles.Length > numTriangles)
            {
                SlicedHull hull = planeExample.SliceObject(this.gameObject, null);
                if (hull != null)
                {
                    // only create the cut pieces if they have enough triangles
                    if (hull.upperHull.triangles.Length > numTriangles && hull.lowerHull.triangles.Length > numTriangles)
                    {
                        GameObject piece = hull.CreateUpperHull(this.gameObject, originalMaterial);

                        // remove 2nd and 3rd hover event from coral piece
                        this.gameObject.GetComponent <InteractableHoverEvents>().onAttachedToHand.RemoveAllListeners();
                        this.gameObject.GetComponent <InteractableHoverEvents>().onDetachedFromHand.RemoveAllListeners();

                        // create clone for the piece no longer attached to the hand
                        GameObject coralClone = Instantiate(this.gameObject);
                        coralClone.transform.position = this.gameObject.transform.position;

                        // set that clones mesh to the upper hull mesh
                        coralClone.GetComponent <MeshFilter>().sharedMesh  = piece.GetComponent <MeshFilter>().sharedMesh;
                        coralClone.GetComponent <MeshFilter>().mesh        = piece.GetComponent <MeshFilter>().mesh;
                        coralClone.GetComponent <MeshRenderer>().materials = piece.GetComponent <MeshRenderer>().materials;
                        // destroy object made by ezy slice
                        Destroy(piece);

                        Destroy(coralClone.GetComponent <BoxCollider>());
                        // add collider and rigid body to new cut piece not attached to hand
                        coralClone.AddComponent <BoxCollider>();
                        coralClone.GetComponent <Rigidbody>().isKinematic = false;
                        coralClone.GetComponent <Rigidbody>().useGravity  = true;

                        GameObject piece2 = hull.CreateLowerHull(this.gameObject, originalMaterial);

                        // set original game object mesh to the lowerhull
                        this.gameObject.GetComponent <MeshFilter>().sharedMesh  = piece2.GetComponent <MeshFilter>().sharedMesh;
                        this.gameObject.GetComponent <MeshFilter>().mesh        = piece2.GetComponent <MeshFilter>().mesh;
                        this.gameObject.GetComponent <MeshRenderer>().materials = piece2.GetComponent <MeshRenderer>().materials;
                        // destroy object made by ezy slice
                        Destroy(piece2);

                        // recreate box collider to fit new mesh
                        Destroy(this.gameObject.GetComponent <BoxCollider>());
                        this.gameObject.AddComponent <BoxCollider>();
                    }
                }
            }
            Destroy(collision.gameObject);
        }
    }
Ejemplo n.º 30
0
    /**
     * This function will recursively slice the provided object and all it's children.
     * Returns a list of SlicedHull objects which represents the cuts for the object
     * and all its children (if any)
     */
    public GameObject[] SliceObjectRecursive(PlaneUsageExample plane, GameObject obj)
    {
        // finally slice the requested object and return
        SlicedHull finalHull = plane.SliceObject(obj);

        if (finalHull != null)
        {
            GameObject lowerParent = finalHull.CreateLowerHull(obj, crossMat);
            GameObject upperParent = finalHull.CreateUpperHull(obj, crossMat);

            if (obj.transform.childCount > 0)
            {
                foreach (Transform child in obj.transform)
                {
                    if (child != null && child.gameObject != null)
                    {
                        // if the child has chilren, we need to recurse deeper
                        if (child.childCount > 0)
                        {
                            GameObject[] children = SliceObjectRecursive(plane, child.gameObject);

                            if (children != null)
                            {
                                // add the lower hull of the child if available
                                if (children[0] != null && lowerParent != null)
                                {
                                    children[0].transform.SetParent(lowerParent.transform, false);
                                }

                                // add the upper hull of this child if available
                                if (children[1] != null && upperParent != null)
                                {
                                    children[1].transform.SetParent(upperParent.transform, false);
                                }
                            }
                        }
                        else
                        {
                            // otherwise, just slice the child object
                            SlicedHull hull = plane.SliceObject(child.gameObject);

                            if (hull != null)
                            {
                                GameObject childLowerHull = hull.CreateLowerHull(child.gameObject, crossMat);
                                GameObject childUpperHull = hull.CreateUpperHull(child.gameObject, crossMat);

                                // add the lower hull of the child if available
                                if (childLowerHull != null && lowerParent != null)
                                {
                                    childLowerHull.transform.SetParent(lowerParent.transform, false);
                                }

                                // add the upper hull of the child if available
                                if (childUpperHull != null && upperParent != null)
                                {
                                    childUpperHull.transform.SetParent(upperParent.transform, false);
                                }
                            }
                        }
                    }
                }
            }

            return(new GameObject[] { lowerParent, upperParent });
        }

        return(null);
    }