void StartPlay(GunSoundSource gunSoundSource)
 {
     gunSoundSource.Play();
     if (!gunSoundSource.setting.isOneShot)
     {
         lastPlaying = gunSoundSource;
         EditorApplication.update += OnUpdateAudio;
     }
 }
Esempio n. 2
0
 void Update()
 {
     if (!playing && Input.GetKey(KeyCode.Space) && Time.time > nextAvailableTime)
     {
         playing = true;
         if (gunSoundSource.shot > 0)
         {
             nextAvailableTime = gunSoundSource.setting.shotLoopInterval * gunSoundSource.shot + Time.time;
         }
         gunSoundSource.Play();
     }
     if (playing && !Input.GetKey(KeyCode.Space))
     {
         playing = false;
         gunSoundSource.Stop();
     }
 }
Esempio n. 3
0
    void UpdateStates()
    {
        if (states.onGround)
        {
            if (sprint > 0 && !states.reloading)
            {
                states.sprint = true;
            }
            else if (sprint <= 0)
            {
                states.sprint = false;
            }

            if (sprint <= 0)
            {
                if (aim > 0)
                {
                    states.aiming = true;
                }
                else if (aim <= 0)
                {
                    states.aiming = false;
                }
            }
            else if (sprint > 0 || states.reloading)
            {
                states.aiming = false;
            }
        }
        else
        {
            states.aiming = false;
            states.sprint = false;
        }

        states.canRun = !states.aiming;

        states.horizontal = horizontal;
        states.vertical   = vertical;

        if (FreeCameraLook.Instance.state == FreeCameraLook.CameraState.MultiTarget)
        {
            if (!states.aiming && !states.sprint && !states.reloading)
            {
                //update target z position of cam
                targetZ   = cameraNormalZ;
                targetFov = normalFov;
                if (fire > 0.5)
                {
                    states.handleAnim.Punch();
                }
            }
            else if (states.aiming && !states.sprint && !states.reloading)
            {
                targetZ   = cameraAimingZ; //update target z position of cam
                targetFov = aimingFov;
            }
            else if (!states.aiming && states.sprint && !states.reloading)
            {
                if (horizontal > 0 || vertical > 0)
                {
                    targetFov = sprintFov;
                    targetZ   = cameraAimingZ;
                }
                else if (horizontal <= 0 || vertical <= 0)
                {
                    targetFov = normalFov;
                    targetZ   = cameraNormalZ;
                }
            }
            else
            {
                targetZ   = cameraNormalZ;
                targetFov = normalFov;
            }
        }
        else // for third person and everything else
        {
            if (!states.aiming && !states.sprint && !states.reloading)
            {
                //update target z position of cam
                targetZ   = cameraNormalZ;
                targetFov = normalFov;

                if (fire > 0.5 && !states.reloading)
                {
                    states.shoot = true;
                    if (gunSoundSource != null)
                    {
                        gunSoundSource.Play();
                    }
                }
                else
                {
                    states.shoot = false;
                    if (gunSoundSource != null)
                    {
                        gunSoundSource.Stop();
                    }
                }
            }
            else if (states.aiming && !states.sprint && !states.reloading)
            {
                targetZ   = cameraAimingZ; //update target z position of cam
                targetFov = aimingFov;

                if (fire > 0.5 && !states.reloading)
                {
                    states.shoot = true;
                    if (gunSoundSource != null)
                    {
                        gunSoundSource.Play();
                    }
                }
                else
                {
                    states.shoot = false;
                    if (gunSoundSource != null)
                    {
                        gunSoundSource.Stop();
                    }
                }
            }
            else if (!states.aiming && states.sprint && !states.reloading)
            {
                if (horizontal > 0 || vertical > 0)
                {
                    targetFov = sprintFov;
                    targetZ   = cameraAimingZ;
                }
                else if (horizontal <= 0 || vertical <= 0)
                {
                    targetFov = normalFov;
                    targetZ   = cameraNormalZ;
                }
            }
            else
            {
                states.shoot = false;
                if (gunSoundSource != null)
                {
                    gunSoundSource.Stop();
                }
                targetZ   = cameraNormalZ;
                targetFov = normalFov;
            }
        }
    }
Esempio n. 4
0
        public override void OnInspectorGUI()
        {
            if (targets.Length == 1)
            {
                var gunSoundSetting          = (GunSoundSetting)target;
                var gunSoundSourceWindowType = System.Type.GetType("AimSound.GunSoundSourceWindow");
                if (gunSoundSourceWindowType != null)
                {
                    if (GUILayout.Button("Open Editor Windows"))
                    {
                        gunSoundSourceWindowType.GetMethod("Init").Invoke(null, new object[] { target });
                        // GunSoundSourceWindow.Init().gunSoundSetting = (GunSoundSetting)target;
                    }
                    GUILayout.Space(20);
                }
                if (GUILayout.Button("Create gun sound source"))
                {
                    CreateGunSoundGameObject(gunSoundSetting, Vector3.zero);
                }
                if (gunSoundSetting.isOneShot)
                {
                    GUILayout.Label("single shot");
                }
                else
                {
                    GUILayout.Label("every minute " + (60f / gunSoundSetting.shotLoopInterval) + " shots");
                }
                GUILayout.Space(10);

                var newEnvironmentType = (EnvironmentType)EditorGUILayout.Popup("Environment", (int)previewSoundSource.environmentType, environmentType);
                if (newEnvironmentType != previewSoundSource.environmentType)
                {
                    previewSoundSource.environmentType = newEnvironmentType;
                }
                var newPlay   = GUILayout.RepeatButton("Play");
                var eventType = Event.current.type;

                if (newPlay != lastPlayDown && eventType == EventType.Repaint)
                {
                    if (((GunSoundSetting)target).isOneShot)
                    {
                        if (newPlay)
                        {
                            previewSoundSource._Clear();
                            previewSoundSource.Play();
                        }
                    }
                    else
                    {
                        if (newPlay)
                        {
                            previewSoundSource._Clear();
                            previewSoundSource.Play();
                            playing = true;
                        }
                        else
                        {
                            previewSoundSource.Stop();
                            playing = false;
                        }
                    }
                    lastPlayDown = newPlay;
                }
                // if(playing)
                // {
                //     if(GUILayout.Button("Stop"))
                //     {
                //         SwitchPlay();
                //     }
                // }
                // else
                // {
                //     if(GUILayout.Button("Play"))
                //     {
                //         SwitchPlay();
                //     }
                // }

                var radius         = (EditorGUIUtility.currentViewWidth - 20) / 2f;
                var lastRect       = GUILayoutUtility.GetLastRect();
                var coordinateRect = new Rect(10, lastRect.yMax + 10, radius * 2, radius * 2);
                EditorGUILayout.BeginVertical();
                DrawCoordinate(coordinateRect);
                GUILayout.Space(radius * 2 + 20);
                EditorGUILayout.EndVertical();
            }
        }