| | | 1 | | /* |
| | | 2 | | * |
| | | 3 | | * Code modified by: |
| | | 4 | | * Dimitrios Vlachos |
| | | 5 | | * djv1@student.london.ac.uk |
| | | 6 | | * dimitri.j.vlachos@gmail.com |
| | | 7 | | * |
| | | 8 | | */ |
| | | 9 | | |
| | | 10 | | using UnityEngine; |
| | | 11 | | using UnityEngine.XR.Interaction.Toolkit; |
| | | 12 | | |
| | | 13 | | namespace DynamicMeshCutter |
| | | 14 | | { |
| | | 15 | | public class KnifePlaneBehaviour : CutterBehaviour |
| | | 16 | | { |
| | 2 | 17 | | public float DebugPlaneLength = 2; |
| | | 18 | | public void Cut() |
| | 0 | 19 | | { |
| | 0 | 20 | | var roots = UnityEngine.SceneManagement.SceneManager.GetActiveScene().GetRootGameObjects(); |
| | 0 | 21 | | foreach (var root in roots) |
| | 0 | 22 | | { |
| | 0 | 23 | | if (!root.activeInHierarchy) |
| | 0 | 24 | | continue; |
| | 0 | 25 | | var targets = root.GetComponentsInChildren<MeshTarget>(); |
| | 0 | 26 | | foreach (var target in targets) |
| | 0 | 27 | | { |
| | 0 | 28 | | Cut(target, transform.position, transform.forward, null, OnCreated); |
| | 0 | 29 | | } |
| | 0 | 30 | | } |
| | 0 | 31 | | } |
| | | 32 | | |
| | | 33 | | void OnCreated(Info info, MeshCreationData cData) |
| | 0 | 34 | | { |
| | 0 | 35 | | MeshCreation.TranslateCreatedObjects(info, cData.CreatedObjects, cData.CreatedTargets, Separation); |
| | | 36 | | |
| | | 37 | | // Add scripts to game object |
| | 0 | 38 | | GameObject[] gameObjects = cData.CreatedObjects; |
| | | 39 | | |
| | 0 | 40 | | foreach (var gameObject in gameObjects) { |
| | 0 | 41 | | gameObject.AddComponent<OffsetInteractable>(); |
| | 0 | 42 | | gameObject.AddComponent<FoodItem>(); |
| | 0 | 43 | | gameObject.GetComponent<FoodItem>().hasBeenCut = true; |
| | 0 | 44 | | gameObject.layer = 6; |
| | 0 | 45 | | } |
| | 0 | 46 | | } |
| | | 47 | | } |
| | | 48 | | } |