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(); }
// Copy from public void CopyFrom(RayfireSound source) { baseVolume = source.baseVolume; sizeVolume = source.sizeVolume; initialization = new RFSound(source.initialization); activation = new RFSound(source.activation); demolition = new RFSound(source.demolition); minimumSize = source.minimumSize; cameraDistance = source.cameraDistance; }
// Copy from public RFSound(RFSound source) { enable = source.enable; multiplier = source.multiplier; clip = source.clip; if (source.HasClips == true) { clips = new List <AudioClip>(); for (int i = 0; i < source.clips.Count; i++) { clips.Add(source.clips[i]); } } }
// Initialize public void Initialize() { if (initialized == false) { AwakeMethods(); StartMethods(); // Init sound RFSound.InitializationSound(sound, limitations.bboxSize); } // TODO add reinit for already initialized objects in case of property change else { } }
// 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(); }
/// ///////////////////////////////////////////////////////// /// 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 components RayfireShatter.CopyRootMeshShatter(this, fragments); RFParticles.CopyRootMeshParticles(this, fragments); RFSound.CopyRootMeshSound(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; } // 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(); }
/// ///////////////////////////////////////////////////////// /// Static /// ///////////////////////////////////////////////////////// // Activate inactive object public static void Activate(RayfireRigid scr) { // Stop if excluded if (scr.physics.exclude == true) { return; } // Skip not activatable unyielding objects if (scr.activation.activatable == false && scr.activation.unyielding == true) { return; } // Initialize if not if (scr.initialized == false) { scr.Initialize(); } // Turn convex if kinematik activation if (scr.simulationType == SimType.Kinematic) { MeshCollider meshCollider = scr.physics.meshCollider as MeshCollider; if (meshCollider != null) { meshCollider.convex = true; } // Swap with animated object if (scr.physics.rec == true) { // Set dynamic before copy scr.simulationType = SimType.Dynamic; scr.physics.rigidBody.isKinematic = false; scr.physics.rigidBody.useGravity = scr.physics.useGravity; // Create copy GameObject inst = UnityEngine.Object.Instantiate(scr.gameObject); inst.transform.position = scr.transForm.position; inst.transform.rotation = scr.transForm.rotation; // Save velocity Rigidbody rBody = inst.GetComponent <Rigidbody>(); if (rBody != null) { rBody.velocity = scr.physics.rigidBody.velocity; rBody.angularVelocity = scr.physics.rigidBody.angularVelocity; } // Activate and init rigid scr.gameObject.SetActive(false); } } // Connectivity check scr.activation.CheckConnectivity(); // Set state scr.activation.activated = true; // Set props scr.simulationType = SimType.Dynamic; scr.physics.rigidBody.isKinematic = false; scr.physics.rigidBody.useGravity = scr.physics.useGravity; // Fade on activation if (scr.fading.onActivation == true) { // Size check if (scr.fading.sizeFilter > 0 && scr.fading.sizeFilter > scr.limitations.bboxSize) { scr.Fade(); } else { scr.Fade(); } } // Init particles on activation RFParticles.InitActivationParticles(scr); // Init sound RFSound.ActivationSound(scr.sound, scr.limitations.bboxSize); // Event scr.activationEvent.InvokeLocalEvent(scr); RFActivationEvent.InvokeGlobalEvent(scr); // Add initial rotation if still TODO put in ui if (scr.physics.rigidBody.angularVelocity == Vector3.zero) { float val = 1.0f; scr.physics.rigidBody.angularVelocity = new Vector3( Random.Range(-val, val), Random.Range(-val, val), Random.Range(-val, val)); } }