private void Awake() { rigidBody = GetComponent <Rigidbody>(); interactionBehaviour = GetComponent <InteractionBehaviour>(); interactionSound = GetComponent <InteractionSound>(); trailRenderer = GetComponent <TrailRenderer>(); }
void ChangeSelection(GameObject newSelection) { interaction = newSelection.GetComponent <InteractionBehaviour>(); // get our interaction sound interactionSound = newSelection.GetComponent <InteractionSound>(); if (interactionSound) { GetInteractionSoundObjectAndProperties(); } else { // clear interaction sound and object properties! interactionSoundObject = null; throwSourceProperty = null; impactSourceProperty = null; grabSourceProperty = null; slideSourceProperty = null; enableImpactSfxProperty = null; enableImpactVfxProperty = null; } // get trail renderer currentTrailRenderer = newSelection.GetComponent <TrailRenderer>(); if (currentTrailRenderer) { GetTrailObjectAndProperties(); } else { // clear trail renderer properties trailRendererObject = null; trailTimeProperty = null; trailMaterialsProperty = null; trailMinVertexDistProperty = null; trailWidthDistProperty = null; trailGradientProperty = null; } // get our sliding effect slideEffect = newSelection.GetComponent <SlideEffect>(); if (slideEffect) { GetSlideEffectObjectAndProperties(); } else { // clear slide effect stuff slideEffectObject = null; slideMaxMagnitudeProperty = null; slideMaxSoundMagnitudeProperty = null; slideMaxEmissionRateProperty = null; slideSoundVolumeProperty = null; slideParticleProperty = null; enableSlideSfx = null; enableAirTrailProperty = null; } selectedObject = newSelection; }
void CreateInteractionSound() { interactionSound = selectedObject.AddComponent <InteractionSound>(); // init our serialized object and properties GetInteractionSoundObjectAndProperties(); // create our audio source components. Not sure how we should handle if they exist already // for now assume they don't. AudioSource impactSource = interactionSound.gameObject.AddComponent <AudioSource>(); impactSourceProperties = GetAudioSourceProperties(impactSource); AudioSource throwSource = interactionSound.gameObject.AddComponent <AudioSource>(); throwSourceProperties = GetAudioSourceProperties(throwSource); AudioSource slideSource = interactionSound.gameObject.AddComponent <AudioSource>(); slideSourceProperties = GetAudioSourceProperties(slideSource); AudioSource grabSource = interactionSound.gameObject.AddComponent <AudioSource>(); grabSourceProperties = GetAudioSourceProperties(grabSource); interactionSoundObject.Update(); impactSourceProperty.objectReferenceValue = impactSource; throwSourceProperty.objectReferenceValue = throwSource; slideSourceProperty.objectReferenceValue = slideSource; grabSourceProperty.objectReferenceValue = grabSource; interactionSoundObject.ApplyModifiedProperties(); // set our default values // impact impactSourceProperties.AudioSourceObject.Update(); impactSourceProperties.ClipProperty.objectReferenceValue = defaultImpactClip; impactSourceProperties.MixerGroupProperty.objectReferenceValue = mixerGroup; //impactSource.clip = defaultImpactClip; impactSourceProperties.LoopProperty.boolValue = false; impactSourceProperties.MinDistanceProperty.floatValue = 0.03f; impactSourceProperties.MaxDistanceProperty.floatValue = 0.75f; impactSourceProperties.PlayOnAwakeProperty.boolValue = false; impactSourceProperties.RolloffProperty.enumValueIndex = (int)AudioRolloffMode.Linear; impactSourceProperties.AudioSourceObject.ApplyModifiedProperties(); impactSource.spatialBlend = 1; // throw throwSourceProperties.AudioSourceObject.Update(); throwSourceProperties.ClipProperty.objectReferenceValue = defaultThrowClip; throwSourceProperties.MixerGroupProperty.objectReferenceValue = mixerGroup; throwSourceProperties.LoopProperty.boolValue = false; throwSourceProperties.MinDistanceProperty.floatValue = 0.03f; throwSourceProperties.MaxDistanceProperty.floatValue = 0.75f; throwSourceProperties.PlayOnAwakeProperty.boolValue = false; throwSourceProperties.RolloffProperty.enumValueIndex = (int)AudioRolloffMode.Linear; throwSourceProperties.AudioSourceObject.ApplyModifiedProperties(); throwSource.spatialBlend = 0.16f; // slide slideSourceProperties.AudioSourceObject.Update(); slideSourceProperties.ClipProperty.objectReferenceValue = defaultSlideClip; slideSourceProperties.MixerGroupProperty.objectReferenceValue = mixerGroup; slideSourceProperties.LoopProperty.boolValue = true; slideSourceProperties.MaxDistanceProperty.floatValue = 2.41f; slideSourceProperties.PlayOnAwakeProperty.boolValue = true; // do our custom curve keyframe slideSourceProperties.RolloffProperty.enumValueIndex = (int)AudioRolloffMode.Custom; Keyframe[] curveKeyframes = new Keyframe[2]; curveKeyframes[0] = new Keyframe(0.0041493773f, 1, -2.6437113f, -2.6437113f); curveKeyframes[1] = new Keyframe(1, 0, 0.021675404f, 0.021675404f); AnimationCurve rolloffCurve = new AnimationCurve(); rolloffCurve.AddKey(curveKeyframes[0]); rolloffCurve.AddKey(curveKeyframes[1]); slideSourceProperties.RolloffCurveProperty.animationCurveValue = rolloffCurve; slideSourceProperties.AudioSourceObject.ApplyModifiedProperties(); slideSource.spatialBlend = 1; // grab grabSourceProperties.AudioSourceObject.Update(); grabSourceProperties.ClipProperty.objectReferenceValue = defaultGrabClip; grabSourceProperties.MixerGroupProperty.objectReferenceValue = mixerGroup; grabSourceProperties.LoopProperty.boolValue = false; grabSourceProperties.MinDistanceProperty.floatValue = 0.03f; grabSourceProperties.MaxDistanceProperty.floatValue = 0.75f; grabSourceProperties.PlayOnAwakeProperty.boolValue = false; grabSourceProperties.RolloffProperty.enumValueIndex = (int)AudioRolloffMode.Linear; grabSourceProperties.AudioSourceObject.ApplyModifiedProperties(); grabSource.spatialBlend = 0.354f; }