Exemple #1
0
 /// <summary>
 /// Remove destroyed victime.
 /// </summary>
 /// <param name="victim">Remove target.</param>
 public void Remove(Slicer victim)
 {
     if (_slicerList.Contains(victim))
     {
         _slicerList.Remove(victim);
     }
 }
Exemple #2
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);
        }
Exemple #3
0
        /// <summary>
        /// 切断できる対象かをチェックする
        /// </summary>
        /// <param name="slicer">対象オブジェクト</param>
        /// <returns>カットできる場合はtrue</returns>
        private bool CanCutTarget(Slicer slicer)
        {
            if (slicer == null)
            {
                return(false);
            }

            if (!slicer.CanCut)
            {
                return(false);
            }

            if (slicer.Iscutting)
            {
                return(false);
            }

            if (!CanCut)
            {
                return(false);
            }

            if (slicer.CutTarget == null)
            {
                return(false);
            }

            if (!slicer.gameObject.activeInHierarchy)
            {
                return(false);
            }

            return(true);
        }
Exemple #4
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);
        }
Exemple #5
0
        /// <summary>
        /// 切断を試す
        ///
        /// Victimeを持っていなかったり、速度が足りてない場合などはカットできないケースがある
        /// </summary>
        /// <param name="target"></param>
        private void TryCut(GameObject target, Vector3 position)
        {
            Slicer slicer = target.GetComponentInParent <Slicer>();

            if (!CanCutTarget(slicer))
            {
                return;
            }

            slicer.Iscutting = true;

            _cutter.Cut(slicer.CutTarget, position, CutNormal, OnCuttedHandler, slicer);

            if (OnCutted != null)
            {
                OnCutted.Invoke(target);
            }
        }
Exemple #6
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);
        }
Exemple #7
0
 /// <summary>
 /// 切断時の演出速度を子に伝播させる
 /// </summary>
 /// <param name="child"></param>
 public void Inherit(Slicer child, Vector3 normal)
 {
     child._velocity = _velocity + normal;
 }