Example #1
0
        void Update()
        {
            if (Input.GetMouseButtonDown(0))
            {
                // if left mouse clicked, try slice this object

                Ray          ray  = Camera.main.ScreenPointToRay(Input.mousePosition);
                RaycastHit[] hits = Physics.RaycastAll(ray, 100f);

                ++_sliceId;

                for (int i = 0; i < hits.Length; i++)
                {
                    IBzSliceable      sliceable  = hits[i].transform.GetComponentInParent <IBzSliceable>();
                    IBzSliceableAsync sliceableA = hits[i].transform.GetComponentInParent <IBzSliceableAsync>();

                    Vector3 direction = Vector3.Cross(ray.direction, Camera.main.transform.right);
                    Plane   plane     = new Plane(direction, ray.origin);

                    if (sliceable != null)
                    {
                        sliceable.Slice(plane);
                    }

                    if (sliceableA != null)
                    {
                        sliceableA.Slice(plane, _sliceId, null);
                    }
                }
            }
        }
Example #2
0
        private IEnumerator Slice(BzKnife knife)
        {
            // The call from OnTriggerEnter, so some object positions are wrong.
            // We have to wait for next frame to work with correct values
            yield return(null);

            Vector3 point  = GetCollisionPoint(knife);
            Vector3 normal = Vector3.Cross(knife.MoveDirection, knife.BladeDirection);
            Plane   plane  = new Plane(normal, point);

            if (_sliceableAsync != null)
            {
                _sliceableAsync.Slice(plane, knife.SliceID, null);
            }
        }
Example #3
0
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.A))
        {
            ++_sliceId;

            foreach (Transform target in gameObject.transform)
            {
                IBzSliceable      sliceable  = target.GetComponentInParent <IBzSliceable>();
                IBzSliceableAsync sliceableA = target.GetComponentInParent <IBzSliceableAsync>();

                Plane plane = new Plane(target.right, target.position);
                if (sliceable != null)
                {
                    sliceable.Slice(plane);
                }
                if (sliceableA != null)
                {
                    sliceableA.Slice(plane, 0, null);
                }
            }
        }
    }
 public void CreateSlice(GameObject slicer)
 {
     SpawnSeveralCutPieces(slicer);
     _sliceableAsync.Slice(plane, 0, OnSliceFinished);
 }