public override void OnInspectorGUI()
        {
            FootstepSounds _target = (FootstepSounds)target;

            EditorGUILayout.Space();
            _target.footstepSounds = ShowClipsGUI(_target.footstepSounds, "Walking sounds");
            EditorGUILayout.Space();
            _target.runSounds = ShowClipsGUI(_target.runSounds, "Running sounds (optional)");
            EditorGUILayout.Space();

            EditorGUILayout.BeginVertical("Button");
            _target.character = (Char)CustomGUILayout.ObjectField <Char> ("Character:", _target.character, true, "", "The Player or NPC that this component is for");
            if (_target.doGroundedCheck)
            {
                _target.doGroundedCheck = CustomGUILayout.ToggleLeft("Only play when grounded?", _target.doGroundedCheck, "", "If True, sounds will only play when the character is grounded");
            }
            _target.soundToPlayFrom = (Sound)CustomGUILayout.ObjectField <Sound> ("Sound to play from:", _target.soundToPlayFrom, true, "", "The Sound object to play from");

            _target.footstepPlayMethod = (FootstepSounds.FootstepPlayMethod)CustomGUILayout.EnumPopup("Play sounds:", _target.footstepPlayMethod, "", "How the sounds are played");
            if (_target.footstepPlayMethod == FootstepSounds.FootstepPlayMethod.Automatically)
            {
                _target.walkSeparationTime = CustomGUILayout.FloatField("Walking separation time (s):", _target.walkSeparationTime, "", "The separation time between sounds when walking");
                _target.runSeparationTime  = CustomGUILayout.FloatField("Running separation time (s):", _target.runSeparationTime, "", "The separation time between sounds when running");
            }
            else if (_target.footstepPlayMethod == FootstepSounds.FootstepPlayMethod.ViaAnimationEvents)
            {
                EditorGUILayout.HelpBox("A sound will be played whenever this component's PlayFootstep function is run. This component should be placed on the same GameObject as the Animator.", MessageType.Info);
            }
            EditorGUILayout.EndVertical();

            UnityVersionHandler.CustomSetDirty(_target);
        }
        override public void ShowGUI(List <ActionParameter> parameters)
        {
            isPlayer = EditorGUILayout.Toggle("Change Player's?", isPlayer);
            if (!isPlayer)
            {
                parameterID = Action.ChooseParameterGUI("FootstepSounds:", parameters, parameterID, ParameterType.GameObject);
                if (parameterID >= 0)
                {
                    constantID     = 0;
                    footstepSounds = null;
                }
                else
                {
                    footstepSounds = (FootstepSounds)EditorGUILayout.ObjectField("FootstepSounds:", footstepSounds, typeof(FootstepSounds), true);

                    constantID     = FieldToID <FootstepSounds> (footstepSounds, constantID);
                    footstepSounds = IDToField <FootstepSounds> (footstepSounds, constantID, false);
                }
            }

            footstepSoundType = (FootstepSoundType)EditorGUILayout.EnumPopup("Clips to change:", footstepSoundType);
            newSounds         = ShowClipsGUI(newSounds, (footstepSoundType == FootstepSoundType.Walk) ? "New walk sounds:" : "New run sounds:");

            AfterRunningOption();
        }
        /**
         * <summary>Deserialises a string of data, and restores the GameObject to its previous state.</summary>
         * <param name = "stringData">The data, serialised as a string</param>
         */
        public override void LoadData(string stringData)
        {
            FootstepSoundData data = Serializer.LoadScriptData <FootstepSoundData> (stringData);

            if (data == null)
            {
                return;
            }
            SavePrevented = data.savePrevented; if (savePrevented)
            {
                return;
            }

            if (GetComponent <FootstepSounds>())
            {
                FootstepSounds footstepSounds = GetComponent <FootstepSounds>();

                AudioClip[] walkSounds = StringToSounds(data.walkSounds);
                if (walkSounds != null && walkSounds.Length > 0)
                {
                    footstepSounds.footstepSounds = walkSounds;
                }

                AudioClip[] runSounds = StringToSounds(data.runSounds);
                if (runSounds != null && runSounds.Length > 0)
                {
                    footstepSounds.runSounds = runSounds;
                }
            }
        }
        public override void OnInspectorGUI()
        {
            FootstepSounds _target = (FootstepSounds)target;

            EditorGUILayout.Space();
            _target.footstepSounds = ShowClipsGUI(_target.footstepSounds, "Walking sounds");
            EditorGUILayout.Space();
            _target.runSounds = ShowClipsGUI(_target.runSounds, "Running sounds (optional)");
            EditorGUILayout.Space();

            EditorGUILayout.BeginVertical("Button");
            _target.character       = (Char)EditorGUILayout.ObjectField("Character:", _target.character, typeof(Char), true);
            _target.doGroundedCheck = EditorGUILayout.ToggleLeft("Only play when grounded?", _target.doGroundedCheck);
            if (_target.doGroundedCheck && _target.character == null)
            {
                EditorGUILayout.HelpBox("A Character must be assigned for the 'grounded' check to work.", MessageType.Warning);
            }
            _target.soundToPlayFrom = (Sound)EditorGUILayout.ObjectField("Sound to play from:", _target.soundToPlayFrom, typeof(Sound), true);

            _target.footstepPlayMethod = (FootstepSounds.FootstepPlayMethod)EditorGUILayout.EnumPopup("Play sounds:", _target.footstepPlayMethod);
            if (_target.footstepPlayMethod == FootstepSounds.FootstepPlayMethod.Automatically)
            {
                _target.walkSeparationTime = EditorGUILayout.FloatField("Walking separation time (s):", _target.walkSeparationTime);
                _target.runSeparationTime  = EditorGUILayout.FloatField("Running separation time (s):", _target.runSeparationTime);
            }
            else if (_target.footstepPlayMethod == FootstepSounds.FootstepPlayMethod.ViaAnimationEvents)
            {
                EditorGUILayout.HelpBox("A sound will be played whenever this component's PlayFootstep function is run.", MessageType.Info);
            }
            EditorGUILayout.EndVertical();

            UnityVersionHandler.CustomSetDirty(_target);
        }
        /**
         * <summary>Creates a new instance of the 'Sound: Change footsteps' Action</summary>
         * <param name = "footstepSoundsToModify">The FootstepSounds component to affect</param>
         * <param name = "footstepSoundType">The type of footsteps (Walk / Run) to change</param>
         * <param name = "newSounds">An array of sounds to set as the new sounds</param>
         * <returns>The generated Action</returns>
         */
        public static ActionFootstepSounds CreateNew(FootstepSounds footstepSoundsToModify, FootstepSoundType footstepSoundType, AudioClip[] newSounds)
        {
            ActionFootstepSounds newAction = (ActionFootstepSounds)CreateInstance <ActionFootstepSounds>();

            newAction.footstepSounds    = footstepSoundsToModify;
            newAction.footstepSoundType = footstepSoundType;
            newAction.newSounds         = newSounds;
            return(newAction);
        }
 override public void AssignValues(List <ActionParameter> parameters)
 {
     if (isPlayer)
     {
         if (KickStarter.player != null)
         {
             footstepSounds = KickStarter.player.GetComponentInChildren <FootstepSounds>();
         }
     }
     else
     {
         footstepSounds = AssignFile <FootstepSounds> (parameters, parameterID, constantID, footstepSounds);
     }
 }
 public override void AssignValues(List <ActionParameter> parameters)
 {
     if (isPlayer)
     {
         Player player = AssignPlayer(playerID, parameters, parameterID);
         if (player != null)
         {
             runtimeFootstepSounds = player.GetComponentInChildren <FootstepSounds>();
         }
     }
     else
     {
         runtimeFootstepSounds = AssignFile <FootstepSounds> (parameters, parameterID, constantID, footstepSounds);
     }
 }
        /**
         * <summary>Serialises appropriate GameObject values into a string.</summary>
         * <returns>The data, serialised as a string</returns>
         */
        public override string SaveData()
        {
            FootstepSoundData footstepSoundData = new FootstepSoundData();

            footstepSoundData.objectID      = constantID;
            footstepSoundData.savePrevented = savePrevented;

            if (GetComponent <FootstepSounds>())
            {
                FootstepSounds footstepSounds = GetComponent <FootstepSounds>();
                footstepSoundData.walkSounds = SoundsToString(footstepSounds.footstepSounds);
                footstepSoundData.runSounds  = SoundsToString(footstepSounds.runSounds);
            }

            return(Serializer.SaveScriptData <FootstepSoundData> (footstepSoundData));
        }
Exemple #9
0
        public override void OnInspectorGUI()
        {
            FootstepSounds _target = (FootstepSounds)target;

            EditorGUILayout.Space();
            _target.footstepSounds = ShowClipsGUI(_target.footstepSounds, "Walking sounds");
            EditorGUILayout.Space();
            _target.runSounds = ShowClipsGUI(_target.runSounds, "Running sounds (optional)");
            EditorGUILayout.Space();

            CustomGUILayout.BeginVertical();
            _target.character = (Char)CustomGUILayout.ObjectField <Char> ("Character:", _target.character, true, string.Empty, "The Player or NPC that this component is for");
            if (_target.character != null || _target.GetComponent <Char>())
            {
                _target.doGroundedCheck = CustomGUILayout.ToggleLeft("Only play when grounded?", _target.doGroundedCheck, string.Empty, "If True, sounds will only play when the character is grounded");

                if (_target.footstepPlayMethod == FootstepSounds.FootstepPlayMethod.ViaAnimationEvents)
                {
                    _target.doMovementCheck = CustomGUILayout.ToggleLeft("Only play when moving?", _target.doMovementCheck, string.Empty, "If True, sounds will only play when the character is walking or running");
                }
            }
            _target.soundToPlayFrom = (Sound)CustomGUILayout.ObjectField <Sound> ("Sound to play from:", _target.soundToPlayFrom, true, "", "The Sound object to play from");

            _target.footstepPlayMethod = (FootstepSounds.FootstepPlayMethod)CustomGUILayout.EnumPopup("Play sounds:", _target.footstepPlayMethod, "", "How the sounds are played");
            if (_target.footstepPlayMethod == FootstepSounds.FootstepPlayMethod.Automatically)
            {
                _target.walkSeparationTime = CustomGUILayout.Slider("Walk separation (s):", _target.walkSeparationTime, 0f, 3f, string.Empty, "The separation time between sounds when walking");
                _target.runSeparationTime  = CustomGUILayout.Slider("Run separation (s):", _target.runSeparationTime, 0f, 3f, string.Empty, "The separation time between sounds when running");
            }
            else if (_target.footstepPlayMethod == FootstepSounds.FootstepPlayMethod.ViaAnimationEvents)
            {
                EditorGUILayout.HelpBox("A sound will be played whenever this component's PlayFootstep function is run. This component should be placed on the same GameObject as the Animator.", MessageType.Info);
            }
            _target.pitchVariance  = CustomGUILayout.Slider("Pitch variance:", _target.pitchVariance, 0f, 0.8f, string.Empty, "How much the audio pitch can randomly vary by.");
            _target.volumeVariance = CustomGUILayout.Slider("Volume variance:", _target.volumeVariance, 0f, 0.8f, string.Empty, "How much the audio volume can randomly vary by.");
            CustomGUILayout.EndVertical();

            if (_target.soundToPlayFrom == null && _target.GetComponent <AudioSource>() == null)
            {
                EditorGUILayout.HelpBox("To play sounds, the 'Sound to play from' must be assigned, or an AudioSource must be attached.", MessageType.Warning);
            }

            UnityVersionHandler.CustomSetDirty(_target);
        }
        public override void AssignConstantIDs(bool saveScriptsToo, bool fromAssetFile)
        {
            FootstepSounds obToUpdate = footstepSounds;

            if (isPlayer)
            {
                if (!fromAssetFile && GameObject.FindObjectOfType <Player>() != null)
                {
                    obToUpdate = GameObject.FindObjectOfType <Player>().GetComponentInChildren <FootstepSounds>();
                }

                if (obToUpdate == null && AdvGame.GetReferences().settingsManager != null)
                {
                    Player player = AdvGame.GetReferences().settingsManager.GetDefaultPlayer();
                    obToUpdate = player.GetComponentInChildren <FootstepSounds>();
                }
            }

            if (saveScriptsToo)
            {
                AddSaveScript <RememberFootstepSounds> (obToUpdate);
            }
            AssignConstantID <FootstepSounds> (obToUpdate, constantID, parameterID);
        }
        public override void ShowGUI(List <ActionParameter> parameters)
        {
            isPlayer = EditorGUILayout.Toggle("Change Player's?", isPlayer);
            if (isPlayer)
            {
                if (KickStarter.settingsManager != null && KickStarter.settingsManager.playerSwitching == PlayerSwitching.Allow)
                {
                    parameterID = ChooseParameterGUI("Player ID:", parameters, parameterID, ParameterType.Integer);
                    if (parameterID < 0)
                    {
                        playerID = ChoosePlayerGUI(playerID, true);
                    }
                }
            }
            else
            {
                parameterID = Action.ChooseParameterGUI("FootstepSounds:", parameters, parameterID, ParameterType.GameObject);
                if (parameterID >= 0)
                {
                    constantID     = 0;
                    footstepSounds = null;
                }
                else
                {
                    footstepSounds = (FootstepSounds)EditorGUILayout.ObjectField("FootstepSounds:", footstepSounds, typeof(FootstepSounds), true);

                    constantID     = FieldToID <FootstepSounds> (footstepSounds, constantID);
                    footstepSounds = IDToField <FootstepSounds> (footstepSounds, constantID, false);
                }
            }

            footstepSoundType = (FootstepSoundType)EditorGUILayout.EnumPopup("Clips to change:", footstepSoundType);
            newSounds         = ShowClipsGUI(newSounds, (footstepSoundType == FootstepSoundType.Walk) ? "New walk sounds:" : "New run sounds:");

            AfterRunningOption();
        }