Beispiel #1
0
        /// <summary>
        /// Update sequencer.
        /// </summary>
        /// <param name="slicer">Target slicer.</param>
        /// <param name="cuttedObjects">Separated objects.</param>
        /// <param name="plane">Separating plane.</param>
        private void UpdateSequencer(Slicer slicer, GameObject[] cuttedObjects, MeshCutter.CutterPlane plane)
        {
            if (slicer.Sequencer == null)
            {
                SlicerCutSequenceArgs args = new SlicerCutSequenceArgs
                {
                    LifeTime         = 1.58f,
                    Speed            = 0.1f,
                    OverrideMaterial = _overrideMaterial,
                    EffectPrefab     = _effectPrefab,
                };

                SlicerCutSequencer sequencer = new SlicerCutSequencer(args);
                sequencer.Add(cuttedObjects, plane, slicer);
                sequencer.OnEnded += OnEndedHandler;
                _slicerSequencerList.Add(sequencer);
            }
            else
            {
                SlicerCutSequencer sequencer = slicer.Sequencer;
                sequencer.Add(cuttedObjects, plane, slicer);
                sequencer.Remove(slicer);
            }

            Destroy(slicer.Root.gameObject);
        }
Beispiel #2
0
        /// <summary>
        /// Add Victime component to sub objects.
        /// </summary>
        public void Add(GameObject[] cuttedObjects, MeshCutter.CutterPlane blade, Slicer parent)
        {
            // カット後の移動方向を調べるために平面を作成する
            Vector3 position = cuttedObjects[0].transform.TransformPoint(blade.Position);
            Vector3 normal   = cuttedObjects[0].transform.TransformDirection(blade.Normal);
            Plane   plane    = new Plane(normal, position);

            Vector3 center = Vector3.zero;

            for (int i = 0; i < cuttedObjects.Length; i++)
            {
                GameObject cutObj = cuttedObjects[i];

                CutterTarget cutterTarget = cutObj.AddComponent <CutterTarget>();
                cutterTarget.Mesh = cutObj.transform;

                Slicer victim = cutObj.AddComponent <Slicer>();
                cutObj.AddComponent <BoxCollider>();
                victim.Sequencer = this;
                victim.CutTarget = cutterTarget;
                victim.Root      = cutObj.transform.parent;
                _slicerList.Add(victim);

                Renderer renderer = cutObj.GetComponent <Renderer>();
                Vector3  checkPos = renderer.bounds.center;
                center += checkPos;
                bool side = plane.GetSide(checkPos);
                if (side)
                {
                    parent.Inherit(victim, plane.normal * _speed);
                }
                else
                {
                    parent.Inherit(victim, -plane.normal * _speed);
                }
            }

            // オブジェクトの中心にエフェクトを表示
            center /= cuttedObjects.Length;

            GameObject effect = GameObject.Instantiate(_effectPrefab, center, Quaternion.identity);

            effect.transform.forward = normal;
            _effectList.Add(effect);
        }
Beispiel #3
0
        /// <summary>
        /// 切断完了時のハンドラ
        /// </summary>
        /// <param name="cuttedObjects">2つに分割されたオブジェクト</param>
        /// <param name="plane">カット平面</param>
        /// <param name="userdata">ユーザデータ(Victimを想定)</param>
        private void OnCuttedHandler(bool success, GameObject[] cuttedObjects, MeshCutter.CutterPlane plane, object userdata)
        {
            Slicer slicer = userdata as Slicer;

            if (slicer == null)
            {
                return;
            }

            // If cutting don't succes, continue to be able to cut.
            if (!success)
            {
                slicer.Iscutting = false;
                return;
            }

            slicer.Cutted();

            UpdateSequencer(slicer, cuttedObjects, plane);
        }