/// <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); }