private void Awake()
 {
     rb              = GetComponent <Rigidbody2D>();
     gun             = GetComponent <Gun>();
     footsteps       = GetComponentInChildren <FootstepSounds>();
     animationPlayer = new AnimationPlayer(GetComponentInChildren <Animator>());
     animationPlayer.EnsurePlaying("IdleDown");
 }
示例#2
0
    // Start is called before the first frame update
    void Awake()
    {
        playerMovement      = GetComponent <PlayerMovement>();
        characterController = GetComponent <CharacterController>();
        footstepSounds      = GetComponentInChildren <FootstepSounds>();

        lookRoot = transform.GetChild(0);
    }
        public override byte[] Serialize()
        {
            List <byte> s = new List <byte>();

            // serialize Id
            s.Add((byte)((Id == null) ? 0 : 1));
            if (Id != null)
            {
                s.AddRange(BitConverter.GetBytes((int)Id));
            }

            // serialize Position
            s.Add((byte)((Position == null) ? 0 : 1));
            if (Position != null)
            {
                s.AddRange(Position.Serialize());
            }

            // serialize PlantingRemainingTime
            s.Add((byte)((PlantingRemainingTime == null) ? 0 : 1));
            if (PlantingRemainingTime != null)
            {
                s.AddRange(BitConverter.GetBytes((int)PlantingRemainingTime));
            }

            // serialize FootstepSounds
            s.Add((byte)((FootstepSounds == null) ? 0 : 1));
            if (FootstepSounds != null)
            {
                List <byte> tmp33 = new List <byte>();
                tmp33.AddRange(BitConverter.GetBytes((uint)FootstepSounds.Count()));
                while (tmp33.Count > 0 && tmp33.Last() == 0)
                {
                    tmp33.RemoveAt(tmp33.Count - 1);
                }
                s.Add((byte)tmp33.Count);
                s.AddRange(tmp33);

                foreach (var tmp34 in FootstepSounds)
                {
                    s.Add((byte)((tmp34 == null) ? 0 : 1));
                    if (tmp34 != null)
                    {
                        s.Add((byte)((sbyte)tmp34));
                    }
                }
            }

            // serialize Status
            s.Add((byte)((Status == null) ? 0 : 1));
            if (Status != null)
            {
                s.Add((byte)((sbyte)Status));
            }

            return(s.ToArray());
        }
    // ReSharper disable once FunctionComplexityOverflow
    public override void OnInspectorGUI()
    {
        MasterAudio.Instance = null;

        var ma        = MasterAudio.Instance;
        var maInScene = ma != null;

        if (maInScene)
        {
            DTGUIHelper.ShowHeaderTexture(MasterAudioInspectorResources.LogoTexture);
            _groupNames = ma.GroupNames;
        }
        else
        {
            _groupNames = new List <string>();
        }
        PopulateGroupNames(_groupNames);

        DTGUIHelper.HelpHeader("http://www.dtdevtools.com/docs/masteraudio/FootstepSounds.htm");

        _isDirty = false;

        _sounds = (FootstepSounds)target;

        var newSpawnMode = (MasterAudio.SoundSpawnLocationMode)EditorGUILayout.EnumPopup("Sound Spawn Mode", _sounds.soundSpawnMode);

        if (newSpawnMode != _sounds.soundSpawnMode)
        {
            AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "change Sound Spawn Mode");
            _sounds.soundSpawnMode = newSpawnMode;
        }

        var newEvent = (FootstepSounds.FootstepTriggerMode)EditorGUILayout.EnumPopup("Event Used", _sounds.footstepEvent);

        if (newEvent != _sounds.footstepEvent)
        {
            AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "change Event Used");
            _sounds.footstepEvent = newEvent;
        }

        if (_sounds.footstepEvent == FootstepSounds.FootstepTriggerMode.None)
        {
            DTGUIHelper.ShowRedError("No sound will be made when Event Used is set to None.");
            return;
        }

        DTGUIHelper.VerticalSpace(3);

        EditorGUILayout.BeginHorizontal();
        GUI.contentColor = DTGUIHelper.BrightButtonColor;
        GUILayout.Space(10);
        if (GUILayout.Button("Add Footstep Sound", EditorStyles.toolbarButton, GUILayout.Width(125)))
        {
            AddFootstepSound();
        }

        if (_sounds.footstepGroups.Count > 0)
        {
            GUILayout.Space(10);
            if (GUILayout.Button(new GUIContent("Delete Footstep Sound", "Delete the bottom Footstep Sound"), EditorStyles.toolbarButton, GUILayout.Width(125)))
            {
                DeleteFootstepSound();
            }
            var buttonText   = "Collapse All";
            var allCollapsed = true;

            foreach (var t in _sounds.footstepGroups)
            {
                if (!t.isExpanded)
                {
                    continue;
                }

                allCollapsed = false;
                break;
            }

            if (allCollapsed)
            {
                buttonText = "Expand All";
            }

            GUILayout.Space(10);
            if (GUILayout.Button(new GUIContent(buttonText), EditorStyles.toolbarButton, GUILayout.Width(80)))
            {
                _isDirty = true;
                ExpandCollapseAll(allCollapsed);
            }
        }

        GUI.contentColor = Color.white;
        EditorGUILayout.EndHorizontal();
        DTGUIHelper.VerticalSpace(3);

        DTGUIHelper.StartGroupHeader();
        var newRetrigger = (EventSounds.RetriggerLimMode)EditorGUILayout.EnumPopup("Retrigger Limit Mode", _sounds.retriggerLimitMode);

        if (newRetrigger != _sounds.retriggerLimitMode)
        {
            AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "change Retrigger Limit Mode");
            _sounds.retriggerLimitMode = newRetrigger;
        }
        EditorGUILayout.EndVertical();

        EditorGUI.indentLevel = 0;
        switch (_sounds.retriggerLimitMode)
        {
        case EventSounds.RetriggerLimMode.FrameBased:
            var newFrm = EditorGUILayout.IntSlider("Min Frames Between", _sounds.limitPerXFrm, 0, 10000);
            if (newFrm != _sounds.limitPerXFrm)
            {
                AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "change Min Frames Between");
                _sounds.limitPerXFrm = newFrm;
            }
            break;

        case EventSounds.RetriggerLimMode.TimeBased:
            var newSec = EditorGUILayout.Slider("Min Seconds Between", _sounds.limitPerXSec, 0f, 10000f);
            if (newSec != _sounds.limitPerXSec)
            {
                AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "change Min Seconds Between");
                _sounds.limitPerXSec = newSec;
            }
            break;
        }
        EditorGUILayout.EndVertical();

        EditorGUI.indentLevel = 0;
        if (_sounds.footstepGroups.Count == 0)
        {
            DTGUIHelper.ShowRedError("You have no Footstep Sounds configured.");
        }
        for (var f = 0; f < _sounds.footstepGroups.Count; f++)
        {
            EditorGUI.indentLevel = 1;
            var step = _sounds.footstepGroups[f];


            var state = step.isExpanded;
            var text  = "Footstep Sound #" + (f + 1);

            DTGUIHelper.ShowCollapsibleSection(ref state, text);

            GUI.backgroundColor = Color.white;
            GUILayout.Space(3f);

            if (state != step.isExpanded)
            {
                AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "toggle Expand Variation");
                step.isExpanded = state;
            }

            DTGUIHelper.AddHelpIconNoStyle("http://www.dtdevtools.com/docs/masteraudio/FootstepSounds.htm#FootstepSound");

            EditorGUILayout.EndHorizontal();

            if (!step.isExpanded)
            {
                DTGUIHelper.VerticalSpace(3);
                continue;
            }

            EditorGUI.indentLevel = 0;
            DTGUIHelper.BeginGroupedControls();

            DTGUIHelper.StartGroupHeader();

            var newUseLayers = EditorGUILayout.BeginToggleGroup("Layer filters", step.useLayerFilter);
            if (newUseLayers != step.useLayerFilter)
            {
                AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "toggle Layer filters");
                step.useLayerFilter = newUseLayers;
            }
            DTGUIHelper.EndGroupHeader();

            if (step.useLayerFilter)
            {
                for (var i = 0; i < step.matchingLayers.Count; i++)
                {
                    var newLayer = EditorGUILayout.LayerField("Layer Match " + (i + 1), step.matchingLayers[i]);
                    if (newLayer == step.matchingLayers[i])
                    {
                        continue;
                    }

                    AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "change Layer filter");
                    step.matchingLayers[i] = newLayer;
                }
                EditorGUILayout.BeginHorizontal();
                GUILayout.Space(10);

                GUI.contentColor = DTGUIHelper.BrightButtonColor;
                if (GUILayout.Button(new GUIContent("Add", "Click to add a layer match at the end"), EditorStyles.toolbarButton, GUILayout.Width(60)))
                {
                    AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "add Layer filter");
                    step.matchingLayers.Add(0);
                }
                if (step.matchingLayers.Count > 1)
                {
                    GUILayout.Space(10);
                    if (GUILayout.Button(new GUIContent("Remove", "Click to remove the last layer match"), EditorStyles.toolbarButton, GUILayout.Width(60)))
                    {
                        AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "remove Layer filter");
                        step.matchingLayers.RemoveAt(step.matchingLayers.Count - 1);
                    }
                }
                GUI.contentColor = Color.white;
                EditorGUILayout.EndHorizontal();
            }
            EditorGUILayout.EndToggleGroup();

            DTGUIHelper.StartGroupHeader();
            var newTagFilter = EditorGUILayout.BeginToggleGroup("Tag filter", step.useTagFilter);
            if (newTagFilter != step.useTagFilter)
            {
                AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "toggle Tag filter");
                step.useTagFilter = newTagFilter;
            }
            DTGUIHelper.EndGroupHeader();

            if (step.useTagFilter)
            {
                for (var i = 0; i < step.matchingTags.Count; i++)
                {
                    var newTag = EditorGUILayout.TagField("Tag Match " + (i + 1), step.matchingTags[i]);
                    if (newTag == step.matchingTags[i])
                    {
                        continue;
                    }

                    AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "change Tag filter");
                    step.matchingTags[i] = newTag;
                }
                EditorGUILayout.BeginHorizontal();
                GUILayout.Space(10);
                GUI.contentColor = DTGUIHelper.BrightButtonColor;
                if (GUILayout.Button(new GUIContent("Add", "Click to add a tag match at the end"), EditorStyles.toolbarButton, GUILayout.Width(60)))
                {
                    AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "Add Tag filter");
                    step.matchingTags.Add("Untagged");
                }
                if (step.matchingTags.Count > 1)
                {
                    GUILayout.Space(10);
                    if (GUILayout.Button(new GUIContent("Remove", "Click to remove the last tag match"), EditorStyles.toolbarButton, GUILayout.Width(60)))
                    {
                        AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "remove Tag filter");
                        step.matchingTags.RemoveAt(step.matchingLayers.Count - 1);
                    }
                }
                GUI.contentColor = Color.white;
                EditorGUILayout.EndHorizontal();
            }
            EditorGUILayout.EndToggleGroup();

            EditorGUI.indentLevel = 0;

            if (maInScene)
            {
                var existingIndex = _groupNames.IndexOf(step.soundType);

                int?groupIndex = null;

                var noGroup = false;
                var noMatch = false;

                if (existingIndex >= 1)
                {
                    EditorGUILayout.BeginHorizontal();
                    groupIndex = EditorGUILayout.Popup("Sound Group", existingIndex, _groupNames.ToArray());
                    if (existingIndex == 1)
                    {
                        noGroup = true;
                    }

                    var button = DTGUIHelper.AddSettingsButton("Sound Group");
                    switch (button)
                    {
                    case DTGUIHelper.DTFunctionButtons.Go:
                        var grp = _groupNames[existingIndex];
                        var trs = MasterAudio.FindGroupTransform(grp);
                        if (trs != null)
                        {
                            Selection.activeObject = trs;
                        }
                        break;
                    }

                    EditorGUILayout.EndHorizontal();
                }
                else if (existingIndex == -1 && step.soundType == MasterAudio.NoGroupName)
                {
                    groupIndex = EditorGUILayout.Popup("Sound Group", existingIndex, _groupNames.ToArray());
                }
                else     // non-match
                {
                    noMatch = true;
                    var newSound = EditorGUILayout.TextField("Sound Group", step.soundType);
                    if (newSound != step.soundType)
                    {
                        AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "change Sound Group");
                        step.soundType = newSound;
                    }

                    var newIndex = EditorGUILayout.Popup("All Sound Groups", -1, _groupNames.ToArray());
                    if (newIndex >= 0)
                    {
                        groupIndex = newIndex;
                    }
                }

                if (noGroup)
                {
                    DTGUIHelper.ShowRedError("No Sound Group specified. Footstep will not sound.");
                }
                else if (noMatch)
                {
                    DTGUIHelper.ShowRedError("Sound Group found no match. Type in or choose one.");
                }

                if (groupIndex.HasValue)
                {
                    if (existingIndex != groupIndex.Value)
                    {
                        AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "change Sound Group");
                    }
                    // ReSharper disable once ConvertIfStatementToConditionalTernaryExpression
                    if (groupIndex.Value == -1)
                    {
                        step.soundType = MasterAudio.NoGroupName;
                    }
                    else
                    {
                        step.soundType = _groupNames[groupIndex.Value];
                    }
                }
            }
            else
            {
                var newSType = EditorGUILayout.TextField("Sound Group", step.soundType);
                if (newSType != step.soundType)
                {
                    AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "change Sound Group");
                    step.soundType = newSType;
                }
            }

            var newVarType = (EventSounds.VariationType)EditorGUILayout.EnumPopup("Variation Mode", step.variationType);
            if (newVarType != step.variationType)
            {
                AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "change Variation Mode");
                step.variationType = newVarType;
            }

            if (step.variationType == EventSounds.VariationType.PlaySpecific)
            {
                var newVarName = EditorGUILayout.TextField("Variation Name", step.variationName);
                if (newVarName != step.variationName)
                {
                    AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "change Variation Name");
                    step.variationName = newVarName;
                }

                if (string.IsNullOrEmpty(step.variationName))
                {
                    DTGUIHelper.ShowRedError("Variation Name is empty. No sound will play.");
                }
            }

            var newVol = DTGUIHelper.DisplayVolumeField(step.volume, DTGUIHelper.VolumeFieldType.None, MasterAudio.MixerWidthMode.Normal, 0f, true);
            // ReSharper disable once CompareOfFloatsByEqualityOperator
            if (newVol != step.volume)
            {
                AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "change Volume");
                step.volume = newVol;
            }

            var newFixedPitch = EditorGUILayout.Toggle("Override pitch?", step.useFixedPitch);
            if (newFixedPitch != step.useFixedPitch)
            {
                AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "toggle Override pitch");
                step.useFixedPitch = newFixedPitch;
            }
            if (step.useFixedPitch)
            {
                var newPitch = DTGUIHelper.DisplayPitchField(step.pitch);
                if (newPitch != step.pitch)
                {
                    AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "change Pitch");
                    step.pitch = newPitch;
                }
            }

            var newDelay = EditorGUILayout.Slider("Delay Sound (sec)", step.delaySound, 0f, 10f);
            if (newDelay == step.delaySound)
            {
                DTGUIHelper.EndGroupedControls();
                continue;
            }

            DTGUIHelper.EndGroupedControls();

            AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "change Delay Sound");
            step.delaySound = newDelay;
        }

        if (GUI.changed || _isDirty)
        {
            EditorUtility.SetDirty(target);
        }

        //DrawDefaultInspector();
    }
示例#5
0
    void playStepTwo()
    {
        FootstepSounds fts = fullFootstepArray[(int)currentGround];

        fts.sources[1].Play();
    }
    // ReSharper disable once FunctionComplexityOverflow
    public override void OnInspectorGUI() {
        EditorGUIUtility.LookLikeControls();

        MasterAudio.Instance = null;

        var ma = MasterAudio.Instance;
        var maInScene = ma != null;

        if (maInScene) {
            DTGUIHelper.ShowHeaderTexture(MasterAudioInspectorResources.LogoTexture);
            _groupNames = ma.GroupNames;
        }
		PopulateGroupNames(_groupNames);

        _isDirty = false;

        _sounds = (FootstepSounds)target;

        var newEvent = (FootstepSounds.FootstepTriggerMode)EditorGUILayout.EnumPopup("Event Used", _sounds.footstepEvent);
        if (newEvent != _sounds.footstepEvent) {
            AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "change Event Used");
            _sounds.footstepEvent = newEvent;
        }

        if (_sounds.footstepEvent == FootstepSounds.FootstepTriggerMode.None) {
            DTGUIHelper.ShowRedError("No sound will be made when Event Used is set to None.");
            return;
        }

        DTGUIHelper.VerticalSpace(3);

        EditorGUILayout.BeginHorizontal();
        GUI.contentColor = DTGUIHelper.BrightButtonColor;
        GUILayout.Space(10);
        if (GUILayout.Button("Add Footstep Sound", EditorStyles.toolbarButton, GUILayout.Width(125))) {
            AddFootstepSound();
        }

        if (_sounds.footstepGroups.Count > 0) {
            GUILayout.Space(10);
            if (GUILayout.Button(new GUIContent("Delete Footstep Sound", "Delete the bottom Footstep Sound"), EditorStyles.toolbarButton, GUILayout.Width(125))) {
                DeleteFootstepSound();
            }
            var buttonText = "Collapse All";
            var allCollapsed = true;

            foreach (var t in _sounds.footstepGroups) {
                if (!t.isExpanded) {
                    continue;
                }

                allCollapsed = false;
                break;
            }

            if (allCollapsed) {
                buttonText = "Expand All";
            }

            GUILayout.Space(10);
            if (GUILayout.Button(new GUIContent(buttonText), EditorStyles.toolbarButton, GUILayout.Width(80))) {
                _isDirty = true;
                ExpandCollapseAll(allCollapsed);
            }
        }

        GUI.contentColor = Color.white;
        EditorGUILayout.EndHorizontal();
        DTGUIHelper.VerticalSpace(3);

        DTGUIHelper.StartGroupHeader();
        var newRetrigger = (EventSounds.RetriggerLimMode)EditorGUILayout.EnumPopup("Retrigger Limit Mode", _sounds.retriggerLimitMode);
        if (newRetrigger != _sounds.retriggerLimitMode) {
            AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "change Retrigger Limit Mode");
            _sounds.retriggerLimitMode = newRetrigger;
        }
        EditorGUILayout.EndVertical();

        EditorGUI.indentLevel = 0;
        switch (_sounds.retriggerLimitMode) {
            case EventSounds.RetriggerLimMode.FrameBased:
                var newFrm = EditorGUILayout.IntSlider("Min Frames Between", _sounds.limitPerXFrm, 0, 10000);
                if (newFrm != _sounds.limitPerXFrm) {
                    AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "change Min Frames Between");
                    _sounds.limitPerXFrm = newFrm;
                }
                break;
            case EventSounds.RetriggerLimMode.TimeBased:
                var newSec = EditorGUILayout.Slider("Min Seconds Between", _sounds.limitPerXSec, 0f, 10000f);
                if (newSec != _sounds.limitPerXSec) {
                    AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "change Min Seconds Between");
                    _sounds.limitPerXSec = newSec;
                }
                break;
        }
        EditorGUILayout.EndVertical();

        EditorGUI.indentLevel = 0;
        if (_sounds.footstepGroups.Count == 0) {
            DTGUIHelper.ShowRedError("You have no Footstep Sounds configured.");
        }
        for (var f = 0; f < _sounds.footstepGroups.Count; f++) {
            EditorGUI.indentLevel = 1;
            var step = _sounds.footstepGroups[f];


            var state = step.isExpanded;
            var text = "Footstep Sound #" + (f + 1);

            // ReSharper disable once ConvertIfStatementToConditionalTernaryExpression
            if (!state) {
                GUI.backgroundColor = DTGUIHelper.InactiveHeaderColor;
            } else {
                GUI.backgroundColor = DTGUIHelper.ActiveHeaderColor;
            }

            GUILayout.BeginHorizontal();

#if UNITY_3_5_7
				if (!state) {
					text += " (Click to expand)";
				}
#else
            text = "<b><size=11>" + text + "</size></b>";
#endif
            if (state) {
                text = "\u25BC " + text;
            } else {
                text = "\u25BA " + text;
            }
            if (!GUILayout.Toggle(true, text, "dragtab", GUILayout.MinWidth(20f))) {
                state = !state;
            }

            GUI.backgroundColor = Color.white;
            if (!state) {
                GUILayout.Space(3f);
            }

            if (state != step.isExpanded) {
                AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "toggle Expand Variation");
                step.isExpanded = state;
            }

            EditorGUILayout.EndHorizontal();

            if (!step.isExpanded) {
                DTGUIHelper.VerticalSpace(3);
                continue;
            }

            EditorGUI.indentLevel = 0;
            DTGUIHelper.BeginGroupedControls();

            DTGUIHelper.StartGroupHeader();

            var newUseLayers = EditorGUILayout.BeginToggleGroup("Layer filters", step.useLayerFilter);
            if (newUseLayers != step.useLayerFilter) {
                AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "toggle Layer filters");
                step.useLayerFilter = newUseLayers;
            }
            DTGUIHelper.EndGroupHeader();

            if (step.useLayerFilter) {
                for (var i = 0; i < step.matchingLayers.Count; i++) {
                    var newLayer = EditorGUILayout.LayerField("Layer Match " + (i + 1), step.matchingLayers[i]);
                    if (newLayer == step.matchingLayers[i]) {
                        continue;
                    }

                    AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "change Layer filter");
                    step.matchingLayers[i] = newLayer;
                }
                EditorGUILayout.BeginHorizontal();
                GUILayout.Space(10);

                GUI.contentColor = DTGUIHelper.BrightButtonColor;
                if (GUILayout.Button(new GUIContent("Add", "Click to add a layer match at the end"), EditorStyles.toolbarButton, GUILayout.Width(60))) {
                    AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "add Layer filter");
                    step.matchingLayers.Add(0);
                }
                if (step.matchingLayers.Count > 1) {
                    GUILayout.Space(10);
                    if (GUILayout.Button(new GUIContent("Remove", "Click to remove the last layer match"), EditorStyles.toolbarButton, GUILayout.Width(60))) {
                        AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "remove Layer filter");
                        step.matchingLayers.RemoveAt(step.matchingLayers.Count - 1);
                    }
                }
                GUI.contentColor = Color.white;
                EditorGUILayout.EndHorizontal();
            }
            EditorGUILayout.EndToggleGroup();

            DTGUIHelper.AddSpaceForNonU5(2);
            DTGUIHelper.StartGroupHeader();
            var newTagFilter = EditorGUILayout.BeginToggleGroup("Tag filter", step.useTagFilter);
            if (newTagFilter != step.useTagFilter) {
                AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "toggle Tag filter");
                step.useTagFilter = newTagFilter;
            }
            DTGUIHelper.EndGroupHeader();

            if (step.useTagFilter) {
                for (var i = 0; i < step.matchingTags.Count; i++) {
                    var newTag = EditorGUILayout.TagField("Tag Match " + (i + 1), step.matchingTags[i]);
                    if (newTag == step.matchingTags[i]) {
                        continue;
                    }

                    AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "change Tag filter");
                    step.matchingTags[i] = newTag;
                }
                EditorGUILayout.BeginHorizontal();
                GUILayout.Space(10);
                GUI.contentColor = DTGUIHelper.BrightButtonColor;
                if (GUILayout.Button(new GUIContent("Add", "Click to add a tag match at the end"), EditorStyles.toolbarButton, GUILayout.Width(60))) {
                    AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "Add Tag filter");
                    step.matchingTags.Add("Untagged");
                }
                if (step.matchingTags.Count > 1) {
                    GUILayout.Space(10);
                    if (GUILayout.Button(new GUIContent("Remove", "Click to remove the last tag match"), EditorStyles.toolbarButton, GUILayout.Width(60))) {
                        AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "remove Tag filter");
                        step.matchingTags.RemoveAt(step.matchingLayers.Count - 1);
                    }
                }
                GUI.contentColor = Color.white;
                EditorGUILayout.EndHorizontal();
            }
            EditorGUILayout.EndToggleGroup();

            EditorGUI.indentLevel = 0;

            if (maInScene) {
                var existingIndex = _groupNames.IndexOf(step.soundType);

                int? groupIndex = null;

                var noGroup = false;
                var noMatch = false;

                if (existingIndex >= 1) {
                    groupIndex = EditorGUILayout.Popup("Sound Group", existingIndex, _groupNames.ToArray());
                    if (existingIndex == 1) {
                        noGroup = true;
                    }
                } else if (existingIndex == -1 && step.soundType == MasterAudio.NoGroupName) {
                    groupIndex = EditorGUILayout.Popup("Sound Group", existingIndex, _groupNames.ToArray());
                } else { // non-match
                    noMatch = true;
                    var newSound = EditorGUILayout.TextField("Sound Group", step.soundType);
                    if (newSound != step.soundType) {
                        AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "change Sound Group");
                        step.soundType = newSound;
                    }

                    var newIndex = EditorGUILayout.Popup("All Sound Groups", -1, _groupNames.ToArray());
                    if (newIndex >= 0) {
                        groupIndex = newIndex;
                    }
                }

                if (noGroup) {
                    DTGUIHelper.ShowRedError("No Sound Group specified. Footstep will not sound.");
                } else if (noMatch) {
                    DTGUIHelper.ShowRedError("Sound Group found no match. Type in or choose one.");
                }

                if (groupIndex.HasValue) {
                    if (existingIndex != groupIndex.Value) {
                        AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "change Sound Group");
                    }
                    // ReSharper disable once ConvertIfStatementToConditionalTernaryExpression
                    if (groupIndex.Value == -1) {
                        step.soundType = MasterAudio.NoGroupName;
                    } else {
                        step.soundType = _groupNames[groupIndex.Value];
                    }
                }
            } else {
                var newSType = EditorGUILayout.TextField("Sound Group", step.soundType);
                if (newSType != step.soundType) {
                    AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "change Sound Group");
                    step.soundType = newSType;
                }
            }

            var newVarType = (EventSounds.VariationType)EditorGUILayout.EnumPopup("Variation Mode", step.variationType);
            if (newVarType != step.variationType) {
                AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "change Variation Mode");
                step.variationType = newVarType;
            }

            if (step.variationType == EventSounds.VariationType.PlaySpecific) {
                var newVarName = EditorGUILayout.TextField("Variation Name", step.variationName);
                if (newVarName != step.variationName) {
                    AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "change Variation Name");
                    step.variationName = newVarName;
                }

                if (string.IsNullOrEmpty(step.variationName)) {
                    DTGUIHelper.ShowRedError("Variation Name is empty. No sound will play.");
                }
            }

            var newVol = DTGUIHelper.DisplayVolumeField(step.volume, DTGUIHelper.VolumeFieldType.None, MasterAudio.MixerWidthMode.Normal, 0f, true);
            // ReSharper disable once CompareOfFloatsByEqualityOperator
            if (newVol != step.volume) {
                AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "change Volume");
                step.volume = newVol;
            }

            var newFixedPitch = EditorGUILayout.Toggle("Override pitch?", step.useFixedPitch);
            if (newFixedPitch != step.useFixedPitch) {
                AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "toggle Override pitch");
                step.useFixedPitch = newFixedPitch;
            }
            if (step.useFixedPitch) {
                var newPitch = DTGUIHelper.DisplayPitchField(step.pitch);
                if (newPitch != step.pitch) {
                    AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "change Pitch");
                    step.pitch = newPitch;
                }
            }

            var newDelay = EditorGUILayout.Slider("Delay Sound (sec)", step.delaySound, 0f, 10f);
            if (newDelay == step.delaySound) {
                DTGUIHelper.EndGroupedControls();
                continue;
            }

            DTGUIHelper.EndGroupedControls();

            AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "change Delay Sound");
            step.delaySound = newDelay;

        }

        if (GUI.changed || _isDirty) {
            EditorUtility.SetDirty(target);
        }

        //DrawDefaultInspector();
    }
示例#7
0
 public void Awake()
 {
     Instant = this;
 }
示例#8
0
 void Start()
 {
     rigidBody           = GetComponent <Rigidbody>();
     capsule             = GetComponent <CapsuleCollider>();
     footstepSoundPlayer = GetComponent <FootstepSounds>();
 }
 // Use this for initialization
 void Start()
 {
     rb             = GetComponent <Rigidbody2D>();
     playerManager  = FindObjectOfType <PlayerManager>();
     footstepSounds = GetComponentInChildren <FootstepSounds>();
 }
示例#10
0
        public override byte[] Serialize()
        {
            List <byte> s = new List <byte>();

            // serialize Id
            s.Add((byte)((Id == null) ? 0 : 1));
            if (Id != null)
            {
                s.AddRange(BitConverter.GetBytes((int)Id));
            }

            // serialize Position
            s.Add((byte)((Position == null) ? 0 : 1));
            if (Position != null)
            {
                s.AddRange(Position.Serialize());
            }

            // serialize DefusionRemainingTime
            s.Add((byte)((DefusionRemainingTime == null) ? 0 : 1));
            if (DefusionRemainingTime != null)
            {
                s.AddRange(BitConverter.GetBytes((int)DefusionRemainingTime));
            }

            // serialize FootstepSounds
            s.Add((byte)((FootstepSounds == null) ? 0 : 1));
            if (FootstepSounds != null)
            {
                List <byte> tmp48 = new List <byte>();
                tmp48.AddRange(BitConverter.GetBytes((uint)FootstepSounds.Count()));
                while (tmp48.Count > 0 && tmp48.Last() == 0)
                {
                    tmp48.RemoveAt(tmp48.Count - 1);
                }
                s.Add((byte)tmp48.Count);
                s.AddRange(tmp48);

                foreach (var tmp49 in FootstepSounds)
                {
                    s.Add((byte)((tmp49 == null) ? 0 : 1));
                    if (tmp49 != null)
                    {
                        s.Add((byte)((sbyte)tmp49));
                    }
                }
            }

            // serialize BombSounds
            s.Add((byte)((BombSounds == null) ? 0 : 1));
            if (BombSounds != null)
            {
                List <byte> tmp50 = new List <byte>();
                tmp50.AddRange(BitConverter.GetBytes((uint)BombSounds.Count()));
                while (tmp50.Count > 0 && tmp50.Last() == 0)
                {
                    tmp50.RemoveAt(tmp50.Count - 1);
                }
                s.Add((byte)tmp50.Count);
                s.AddRange(tmp50);

                foreach (var tmp51 in BombSounds)
                {
                    s.Add((byte)((tmp51 == null) ? 0 : 1));
                    if (tmp51 != null)
                    {
                        s.Add((byte)((sbyte)tmp51));
                    }
                }
            }

            // serialize Status
            s.Add((byte)((Status == null) ? 0 : 1));
            if (Status != null)
            {
                s.Add((byte)((sbyte)Status));
            }

            return(s.ToArray());
        }