/// ///////////////////////////////////////////////////////// /// Manual methods /// ///////////////////////////////////////////////////////// // Predefine fragments void Prefragment() { // Delete existing DeleteFragments(); // Create fragments from cache fragments = RFDemolitionMesh.CreateFragments(this); // Stop if (HasFragments == false) { demolitionType = DemolitionType.None; return; } // Set physics properties for (int i = 0; i < fragments.Count; i++) { fragments[i].SetComponentsBasic(); //fragments[i].SetParticleComponents(); fragments[i].SetComponentsPhysics(); fragments[i].SetObjectType(); } // Deactivate fragments root if (rootChild != null) { rootChild.gameObject.SetActive(false); } }
/// ///////////////////////////////////////////////////////// /// Awake ops /// ///////////////////////////////////////////////////////// // Init mesh root. Copy Rigid component for children with mesh bool SetRootMesh() { if (objectType == ObjectType.MeshRoot) { // Stop if already initiated if (limitations.demolished == true || physics.exclude == true) { return(true); } // Get children List <Transform> children = new List <Transform>(); for (int i = 0; i < transform.childCount; i++) { children.Add(transform.GetChild(i)); } // Add Rigid to child with mesh fragments = new List <RayfireRigid>(); for (int i = 0; i < children.Count; i++) { if (children[i].GetComponent <MeshFilter>() != null) { // Get rigid // TODO check if fragment already has Rigid, Reinit in this case. RayfireRigid childRigid = children[i].gameObject.GetComponent <RayfireRigid>(); if (childRigid == null) { childRigid = children[i].gameObject.AddComponent <RayfireRigid>(); } fragments.Add(childRigid); // Copy parent properties CopyPropertiesTo(childRigid); // Init childRigid.Initialize(); } } // Copy initialized particles RFParticles.CopyRootMeshParticles(this, fragments); // TODO Setup as clusters root children with transform only // Check for Unyielding component RayfireUnyielding[] unyArray = transform.GetComponents <RayfireUnyielding>(); for (int i = 0; i < unyArray.Length; i++) { unyArray[i].SetUnyByOverlap(this); } // Turn off demolition and physics demolitionType = DemolitionType.None; physics.exclude = true; return(true); } return(false); }
// Demolish object public void Demolish() { // Profiler.BeginSample ("Demolition"); // Debug.Log (limitations.demolitionShould); // Initialize if not if (initialized == false) { Initialize(); } // Timestamp float t1 = Time.realtimeSinceStartup; // Restore position and rotation to prevent high collision offset transForm.position = physics.position; transForm.rotation = physics.rotation; // Demolish mesh or cluster to reference if (RFReferenceDemolition.DemolishReference(this) == false) { return; } // Demolish mesh and create fragments. Stop if runtime caching or no meshes/fragments were created if (RFDemolitionMesh.DemolishMesh(this) == false) { return; } /* EXPERIMENTAL * // TODO Clusterize * bool clusterize = true; * if (clusterize == true && objectType == ObjectType.Mesh && demolitionType == DemolitionType.Runtime) * { * * foreach (var frag in fragments) * { * Destroy (frag.physics.rigidBody); * Destroy (frag); * } * * RayfireRigid scr = this.rootChild.gameObject.AddComponent<RayfireRigid>(); * this.CopyPropertiesTo (scr); * scr.demolitionType = DemolitionType.Runtime; * scr.objectType = ObjectType.ConnectedCluster; * * scr.limitations.contactPoint = this.limitations.contactPoint; * scr.limitations.contactNormal = this.limitations.contactNormal; * scr.limitations.contactVector3 = this.limitations.contactVector3; * * scr.physics.velocity = this.physics.velocity; * * scr.clusterDemolition.cluster = new RFCluster(); * scr.Initialize(); * * scr.physics.rigidBody.velocity = this.physics.velocity; * scr.limitations.demolitionShould = true; * //scr.Demolish(); * RayfireMan.DestroyFragment (this, rootParent); * return; * } */ // Demolish cluster to children nodes if (RFDemolitionCluster.DemolishCluster(this) == true) { return; } // Check fragments and proceed TODO separate flow for connected cls demolition if (limitations.demolished == false) { limitations.demolitionShould = false; demolitionType = DemolitionType.None; return; } // Connectivity check activation.CheckConnectivity(); // Fragments initialisation InitMeshFragments(); // Sum total demolition time RayfireMan.inst.maxTimeThisFrame += Time.realtimeSinceStartup - t1; // Init particles RFParticles.InitDemolitionParticles(this); // Init sound RFSound.DemolitionSound(sound, limitations.bboxSize); // Event demolitionEvent.InvokeLocalEvent(this); RFDemolitionEvent.InvokeGlobalEvent(this); // Destroy demolished object RayfireMan.DestroyFragment(this, rootParent); // Timestamp // float t2 = Time.realtimeSinceStartup; // Debug.Log (t2 - t1); // Profiler.EndSample(); }
// Demolish object public void Demolish() { // Profiler.BeginSample ("Demolition"); // Debug.Log (limitations.demolitionShould); // Initialize if not if (initialized == false) { Initialize(); } // Timestamp float t1 = Time.realtimeSinceStartup; // Restore position and rotation to prevent high collision offset transForm.position = physics.position; transForm.rotation = physics.rotation; // Demolish mesh or cluster to reference if (RFReferenceDemolition.DemolishReference(this) == false) { return; } // Demolish mesh and create fragments. Stop if runtime caching or no meshes/fragments were created if (RFDemolitionMesh.DemolishMesh(this) == false) { return; } // Demolish cluster to children nodes if (RFDemolitionCluster.DemolishCluster(this) == true) { return; } // Check fragments and proceed TODO separate flow for connected cls demolition if (limitations.demolished == false) { limitations.demolitionShould = false; demolitionType = DemolitionType.None; return; } // Connectivity check activation.CheckConnectivity(); // Fragments initialisation InitMeshFragments(); // Sum total demolition time RayfireMan.inst.maxTimeThisFrame += Time.realtimeSinceStartup - t1; // Init particles RFParticles.InitDemolitionParticles(this); // Event demolitionEvent.InvokeLocalEvent(this); RFDemolitionEvent.InvokeGlobalEvent(this); // Destroy demolished object RayfireMan.DestroyFragment(this, rootParent); // Timestamp // float t2 = Time.realtimeSinceStartup; // Debug.Log (t2 - t1); // Profiler.EndSample(); }