-
Notifications
You must be signed in to change notification settings - Fork 371
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implemented horn sound base functionality #73
Open
AdamLacko
wants to merge
6
commits into
in0finite:dev
Choose a base branch
from
AdamLacko:dev
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+314
−17
Open
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
abec819
Implemented horn sound base functionality
AdamLacko 2484a29
-Fixed various issues with vehicle horn implementation
AdamLacko f0ebe1a
Merge branch 'dev' into dev
AdamLacko 8b56073
Resolved conflict in Vehicle
AdamLacko fd52bd6
Merge branch 'dev' of https://github.com/AdamLacko/SanAndreasUnity in…
AdamLacko a5fb38a
Update Vehicle_Radio.cs
AdamLacko File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -159,7 +159,13 @@ public bool IsNightToggled | |
} | ||
} | ||
|
||
private VehicleController _controller; | ||
public bool IsHornOn | ||
{ | ||
get; set; | ||
} | ||
|
||
private AudioSource horn; | ||
private VehicleController _controller; | ||
|
||
bool m_isServer => Net.NetStatus.IsServer; | ||
public bool IsControlledByLocalPlayer => Ped.Instance != null && Ped.Instance.CurrentVehicle == this && Ped.Instance.CurrentVehicleSeat.IsDriver; | ||
|
@@ -173,7 +179,8 @@ private void Awake() | |
this.NetTransform = this.GetComponent<Mirror.NetworkTransform>(); | ||
_props = new MaterialPropertyBlock(); | ||
radio = GetComponent<AudioSource>(); | ||
} | ||
horn = this.gameObject.AddComponent<AudioSource>(); | ||
} | ||
|
||
void OnEnable() | ||
{ | ||
|
@@ -191,7 +198,7 @@ void Start() | |
|
||
currentRadioStationIndex = Random.Range(0, RadioStation.stations.Length); | ||
|
||
Debug.LogFormat("Created vehicle - id {0}, name {1}, time: {2}", this.Definition.Id, | ||
Debug.LogFormat("Created vehicle - id {0}, name {1}, time: {2}", this.Definition.Id, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. don't do style changes |
||
this.Definition.GameName, F.CurrentDateForLogging); | ||
} | ||
|
||
|
@@ -295,7 +302,29 @@ private void SetLight(int index, float brightness) | |
_colorsChanged = true; | ||
} | ||
|
||
public VehicleDef Definition { get; private set; } | ||
public virtual void PlayHornSound() | ||
{ | ||
if (!IsHornOn) return; | ||
if (horn.clip == null) | ||
{ | ||
//TODO add vehicle dependent horn sound | ||
var audioClip = Audio.AudioManager.CreateAudioClipFromSfx("GENRL", 67, 3); | ||
horn.playOnAwake = false; | ||
horn.spatialBlend = 1; | ||
horn.maxDistance = 15; | ||
horn.clip = MakeSubclip(audioClip, audioClip.length / 1.75f, (audioClip.length / 1.75f) + 0.05f); | ||
} | ||
if (horn && horn.clip) | ||
{ | ||
if (!horn.isPlaying) | ||
{ | ||
horn.loop = true; | ||
horn.Play(); | ||
} | ||
} | ||
} | ||
|
||
public VehicleDef Definition { get; private set; } | ||
|
||
public Transform DriverTransform { get; private set; } | ||
|
||
|
@@ -435,7 +464,11 @@ private void Update() | |
radio.Stop(); | ||
} | ||
} | ||
} | ||
|
||
if (IsHornOn) { PlayHornSound(); } | ||
else { horn.loop = false; } | ||
IsHornOn = false; | ||
} | ||
|
||
private void FixedUpdate() | ||
{ | ||
|
@@ -461,5 +494,17 @@ public void ApplySyncRate(float syncRate) | |
this.NetTransform.syncInterval = 1.0f / syncRate; | ||
} | ||
|
||
} | ||
private AudioClip MakeSubclip(AudioClip clip, float start, float stop) | ||
{ | ||
int frequency = clip.frequency; | ||
float timeLength = stop - start; | ||
int samplesLength = (int)(frequency * timeLength); | ||
AudioClip newClip = AudioClip.Create(clip.name + "-sub", samplesLength, 1, frequency, false); | ||
float[] data = new float[samplesLength]; | ||
clip.GetData(data, (int)(frequency * start)); | ||
newClip.SetData(data, 0); | ||
return newClip; | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unnecessary using