Beispiel #1
0
        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();
        }
Beispiel #2
0
        /// /////////////////////////////////////////////////////////
        /// 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));
            }
        }