bool Inspect(PhysicalContact contact)
        {
            var soundCue        = (SoundCue)EditorGUILayout.ObjectField("Sound Cue", contact.soundCue, typeof(SoundCue), false);
            var fxPrefabChanged = WeakAssetRefDrawer.WeakRefField("Fx Prefab", contact.fxPrefab);
            var rate            = Mathf.Max(0f, EditorGUILayout.FloatField("Max Contact Rate", contact.maxContactRate));
            var max             = Mathf.Max(0, EditorGUILayout.IntField("Max Living Contacts", contact.maxLivingContacts));
            var splatterRadius  = GUILayoutHelpers.MinMaxSlider("Blood Splatter Radius", contact.bloodSplatterRadius, 0, 8);
            var splatterSize    = GUILayoutHelpers.MinMaxSlider("Blood Splatter Size", contact.bloodSplatterSize, 0, 8);
            var splatterCount   = GUILayoutHelpers.MinMaxSlider("Blood Splatter Count", contact.bloodSplatterCount, 0, 64);

            if (fxPrefabChanged ||
                !ReferenceEquals(soundCue, contact.soundCue) ||
                (rate != contact.maxContactRate) ||
                (max != contact.maxLivingContacts) ||
                (splatterRadius != contact.bloodSplatterRadius) ||
                (splatterSize != contact.bloodSplatterSize) ||
                (splatterCount != contact.bloodSplatterCount))
            {
                contact.soundCue            = soundCue;
                contact.maxContactRate      = rate;
                contact.maxLivingContacts   = max;
                contact.bloodSplatterRadius = splatterRadius;
                contact.bloodSplatterSize   = splatterSize;
                contact.bloodSplatterCount  = splatterCount;
                return(true);
            }

            return(false);
        }
示例#2
0
    public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
    {
        var attr = (MinMaxSlider)attribute;

        if (fieldInfo.FieldType == typeof(Vector2))
        {
            property.vector2Value = GUILayoutHelpers.MinMaxSlider(position, label.text, property.vector2Value, attr.min, attr.max);
        }
        else
        {
            var boxed = property.GetValue();
            if (boxed != null)
            {
                var v    = (IntMath.Vector2i)property.GetValue();
                var newV = GUILayoutHelpers.MinMaxSlider(position, label.text, v, Mathf.FloorToInt(attr.min), Mathf.FloorToInt(attr.max));

                if (newV != v)
                {
                    property.SetValue(newV);
                    EditorUtility.SetDirty(property.serializedObject.targetObject);
                }
            }
        }
    }
    public override void OnInspectorGUI()
    {
        serializedObject.Update();

        EditorGUILayout.PropertyField(_playChance);

        _volume.vector2Value = GUILayoutHelpers.MinMaxSlider("Volume", _volume.vector2Value, 0, 1);
        _pitch.vector2Value  = GUILayoutHelpers.MinMaxSlider("Pitch", _pitch.vector2Value, -3, 3);
        _reverb.vector2Value = GUILayoutHelpers.MinMaxSlider("Reverb", _reverb.vector2Value, 0, 1.1f);

        EditorGUILayout.PropertyField(_loop);
        EditorGUILayout.PropertyField(_clipRef);

        var newClip = _clip.Load();

        if (newClip != _loaded)
        {
            _loaded = newClip;
            StopPlaying();
        }

        var oldPrefab = _audioSourcePrefab.objectReferenceValue;

        EditorGUILayout.PropertyField(_audioSourcePrefab, true);
        if (!ReferenceEquals(oldPrefab, _audioSourcePrefab.objectReferenceValue))
        {
            StopPlaying();
        }

        SoundCue self = (SoundCue)target;

        var wasEnabled = GUI.enabled;

        if (_source == null)
        {
            GUI.enabled = (_loaded != null) && (self.audioSourcePrefab != null);
            if (GUILayout.Button("Play"))
            {
                string unused;
                var    clipToPlay = _loaded.RandomClip(Random.value, out unused);
                if (clipToPlay != null)
                {
                    var go = (GameObject)GameObject.Instantiate(self.audioSourcePrefab.gameObject, Vector3.zero, Quaternion.identity);
                    go.hideFlags = HideFlags.HideAndDontSave;

                    _source = go.GetComponent <AudioSource>();
                    go.AddComponent <AudioSourceGC>();

                    _source.spatialBlend  = 0f;
                    _source.clip          = clipToPlay;
                    _source.volume        = self.RandomVolume(Random.value);
                    _source.pitch         = self.RandomPitch(Random.value);
                    _source.reverbZoneMix = self.RandomReverb(Random.value);
                    _source.loop          = _loop.boolValue;
                    _source.Play();

                    EditorApplication.update += Update;
                }
            }
        }
        else
        {
            GUI.enabled = true;
            if (GUILayout.Button("Stop"))
            {
                StopPlaying();
            }
        }
        GUI.enabled = wasEnabled;

        serializedObject.ApplyModifiedProperties();
    }