public override void OnInspectorGUI() { // Get target sound = target as RayfireSound; if (sound == null) { return; } // Initialize if (Application.isPlaying == true) { GUILayout.Space(8); if (GUILayout.Button("Initialization Sound", GUILayout.Height(25))) { foreach (var targ in targets) { if (targ as RayfireSound != null) { RFSound.InitializationSound(targ as RayfireSound, 0f); } } } if (GUILayout.Button("Activation Sound", GUILayout.Height(25))) { foreach (var targ in targets) { if (targ as RayfireSound != null) { RFSound.ActivationSound(targ as RayfireSound, 0f); } } } if (GUILayout.Button("Demolition Sound", GUILayout.Height(25))) { foreach (var targ in targets) { if (targ as RayfireSound != null) { RFSound.DemolitionSound(targ as RayfireSound, 0f); } } } // Info GUILayout.Label("Info", EditorStyles.boldLabel); // Get volume GUILayout.Label(" Volume: " + RFSound.GeVolume(sound, 0f)); GUILayout.Space(5); } // Draw script UI DrawDefaultInspector(); }
// 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); // 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(); }