Skip to content

Commit

Permalink
Merge pull request #54 from skillz/update-c#-files
Browse files Browse the repository at this point in the history
[#163578260] make cave runner C# files match Unity cross platform rep…
  • Loading branch information
leoleblanc authored Feb 14, 2019
2 parents 735712a + a4ba5ce commit 1b26804
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 45 deletions.
47 changes: 43 additions & 4 deletions CaveRunner/Assets/Skillz/Build/IncludeInXcode/Skillz+Unity.mm
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,15 @@ static void PauseApp()
UnityPause(true);
}

static void PauseAppWithDelay()
{
double delayInSeconds = 1.0;
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC));
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
PauseApp();
});
}

static void ResumeApp()
{
UnityPause(false);
Expand Down Expand Up @@ -566,7 +575,7 @@ - (void)onMatchCompleted
dispatch_async(dispatch_get_main_queue(), ^{
if (!isReportingScore) {
isReportingScore = true;
PauseApp();
PauseAppWithDelay();

[[Skillz skillzInstance] displayTournamentResultsWithScore:@(score)
withCompletion:^{
Expand All @@ -582,7 +591,7 @@ - (void)onMatchCompleted
dispatch_async(dispatch_get_main_queue(), ^{
if (!isReportingScore) {
isReportingScore = true;
PauseApp();
PauseAppWithDelay();

[[Skillz skillzInstance] displayTournamentResultsWithScore:@(score)
withCompletion:^{
Expand All @@ -597,7 +606,7 @@ - (void)onMatchCompleted
dispatch_async(dispatch_get_main_queue(), ^{
if (!isReportingScore) {
isReportingScore = true;
PauseApp();
PauseAppWithDelay();

NSNumberFormatter *f = [[NSNumberFormatter alloc] init];
f.numberStyle = NSNumberFormatterDecimalStyle;
Expand Down Expand Up @@ -641,7 +650,7 @@ - (void)onMatchCompleted
dispatch_async(dispatch_get_main_queue(), ^{
if (!isReportingScore) {
isReportingScore = true;
PauseApp();
PauseAppWithDelay();
[[Skillz skillzInstance] notifyPlayerAbortWithCompletion:^() {
// Send message to Unity object to call C# method
// SkillzDelegate.skillzWithPlayerAbort, implemented by publisher
Expand Down Expand Up @@ -736,6 +745,36 @@ - (void)onMatchCompleted
extern "C" const char *_getMatchInfo() {
return [((UnitySkillzSDKDelegate*)[Skillz skillzInstance].skillzDelegate).matchInfo UTF8String];
}
#pragma mark
#pragma mark Audio Integration
#pragma mark

extern "C" void _setSkillzBackgroundMusic(const char *fileName)
{
NSString* fileNameString = [NSString stringWithUTF8String:fileName];
NSLog(@"SkillzAudio Skillz+Unity.mm _setSkillzBackgroundMusic with file name: %@",fileNameString);
[[Skillz skillzInstance] setBackgroundMusicFile:fileNameString];
}

extern "C" void _setSkillzMusicVolume(float volume)
{
[[Skillz skillzInstance] updateSkillzMusicVolume:volume];
}

extern "C" void _setSFXVolume(float volume)
{
[[Skillz skillzInstance] setSFXVolume:volume];
}

extern "C" float _getSFXVolume()
{
return (float)[[Skillz skillzInstance] getSFXVolume];
}

extern "C" float _getSkillzMusicVolume()
{
return (float)[[Skillz skillzInstance] getBackgroundMusicVolume];
}

#pragma mark
#pragma mark Sync API
Expand Down
54 changes: 27 additions & 27 deletions CaveRunner/Assets/Standard Assets/Api.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public static class Api
public static extern float _getRandomFloat();

[DllImport ("__Internal")]
private static extern void _setSkillzBackgroundMusic(string musicFile);
private static extern void _setSkillzBackgroundMusic(string filePath);

[DllImport ("__Internal")]
private static extern void _setSFXVolume(float volume);
Expand Down Expand Up @@ -185,7 +185,7 @@ private static void _updatePlayersCurrentScore(float score) { }
private static void _updatePlayersCurrentStringScore(string score) { }
private static void _updatePlayersCurrentIntScore(int score) { }
public static float _getRandomFloat() { return 0; }
private static void _setSkillzBackgroundMusic(string musicFile) { }
private static void _setSkillzBackgroundMusic(string filePath) { }
public static float _getSFXVolume() { return 0; }
public static float _getSkillzMusicVolume() { return 0; }
private static void _setSFXVolume(float volume) { }
Expand Down Expand Up @@ -221,29 +221,29 @@ private static void _sendData(IntPtr value, UInt64 length) { }
#endif
delegate void IntPtrIntFP(IntPtr value, UInt64 length); //This "UInt64" may need to be an "int"
#if UNITY_IOS
[DllImport ("__Internal")]
private static extern void _assignOnCurrentPlayerHasReconnectedFunc(IntPtr funcPtr);
[DllImport ("__Internal")]
private static extern void _assignOnCurrentPlayerHasReconnectedFunc(IntPtr funcPtr);

[DllImport ("__Internal")]
private static extern void _assignOnCurrentPlayerHasLostConnectionFunc(IntPtr funcPtr);
[DllImport ("__Internal")]
private static extern void _assignOnCurrentPlayerHasLostConnectionFunc(IntPtr funcPtr);

[DllImport ("__Internal")]
private static extern void _assignOnCurrentPlayerHasLeftMatchFunc(IntPtr funcPtr);
[DllImport ("__Internal")]
private static extern void _assignOnCurrentPlayerHasLeftMatchFunc(IntPtr funcPtr);

[DllImport ("__Internal")]
private static extern void _assignOnOpponentHasReconnectedFunc(IntPtr funcPtr);
[DllImport ("__Internal")]
private static extern void _assignOnOpponentHasReconnectedFunc(IntPtr funcPtr);

[DllImport ("__Internal")]
private static extern void _assignOnOpponentHasLostConnectionFunc(IntPtr funcPtr);
[DllImport ("__Internal")]
private static extern void _assignOnOpponentHasLostConnectionFunc(IntPtr funcPtr);

[DllImport ("__Internal")]
private static extern void _assignOnOpponentHasLeftMatchFunc(IntPtr funcPtr);
[DllImport ("__Internal")]
private static extern void _assignOnOpponentHasLeftMatchFunc(IntPtr funcPtr);

[DllImport ("__Internal")]
private static extern void _assignOnDidReceiveDataFunc(IntPtr funcPtr);
[DllImport ("__Internal")]
private static extern void _assignOnDidReceiveDataFunc(IntPtr funcPtr);

[DllImport ("__Internal")]
private static extern void _assignOnMatchCompletedFunc(IntPtr funcPtr);
[DllImport ("__Internal")]
private static extern void _assignOnMatchCompletedFunc(IntPtr funcPtr);
#else
private static void _assignOnCurrentPlayerHasReconnectedFunc(IntPtr funcPtr) { }
private static void _assignOnCurrentPlayerHasLostConnectionFunc(IntPtr funcPtr) { }
Expand Down Expand Up @@ -281,18 +281,18 @@ public static bool IsTournamentInProgress {
/// </summary>
[Obsolete("Use 'Api.Player.DisplayName' instead")]
public static string CurrentUserDisplayName {
get {
return GetPlayer().DisplayName;
}
get {
return GetPlayer().DisplayName;
}
}

/// <summary>
/// Gets information for the current player.
/// </summary>
public static Player GetPlayer() {
string playerJson = Marshal.PtrToStringAnsi(_player());
Dictionary<string, object> playerDict = DeserializeJSONToDictionary(playerJson);
return new Player(playerDict);
string playerJson = Marshal.PtrToStringAnsi(_player());
Dictionary<string, object> playerDict = DeserializeJSONToDictionary(playerJson);
return new Player(playerDict);
}
#endif
/// <summary>
Expand Down Expand Up @@ -715,10 +715,10 @@ public static void AssignSyncDelegateFunctions() {

#region Audio API

public static void setSkillzBackgroundMusic(string musicFile)
public static void setSkillzBackgroundMusic(string fileName)
{
Debug.Log("SkillzAudio Api.cs setSkillzBackgroundMusic");
_setSkillzBackgroundMusic(musicFile);
Debug.Log("SkillzAudio Api.cs setSkillzBackgroundMusic with file name: " + fileName);
_setSkillzBackgroundMusic(fileName);
}

public static float getSkillzMusicVolume()
Expand Down
6 changes: 3 additions & 3 deletions CaveRunner/Assets/Standard Assets/Skillz.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,10 @@ public static string CurrentUserDisplayName()

#region Audio API

public static void setSkillzBackgroundMusic(String musicFile)
public static void setSkillzBackgroundMusic(String fileName)
{
Debug.Log("SkillzAudio setSkillzBackgroundMusic musicFile: " + musicFile);
GetSkillzAudio().CallStatic("setSkillzBackgroundMusic", musicFile);
Debug.Log("SkillzAudio Skillz.cs setSkillzBackgroundMusic with file name: " + fileName);
GetSkillzAudio().CallStatic("setSkillzBackgroundMusic", fileName);
}

public static float getSkillzMusicVolume()
Expand Down
16 changes: 5 additions & 11 deletions CaveRunner/Assets/Standard Assets/SkillzCrossPlatform.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using UnityEngine;
using UnityEditor;
using System.Collections.Generic;
using System.Collections;
using System.Text;
Expand Down Expand Up @@ -266,20 +265,15 @@ public static void AddMetadataForMatchInProgress(string metadataJson, bool forMa
/// This will be continuously playing throughout a user's time in our SDK.
/// </summary>
///
/// <param name="audioClip">The audio clip to be played.</param>
public static void setSkillzBackgroundMusic(AudioClip audioClip)
/// <param name="fileName">The name of the music file inside of the StreamingAssets folder, e.g. "game_music.mp3" .</param>
public static void setSkillzBackgroundMusic(string fileName)
{
/* absolute path ends in "Assets", relative path starts with "Assets"... remove duplicate */
Debug.Log ("audioClip: " + audioClip);
string absolutePathToAssets = Application.dataPath;
string relativePathFromAssets = AssetDatabase.GetAssetOrScenePath(audioClip).Substring(6);
string filePath = absolutePathToAssets + relativePathFromAssets;
Debug.Log("SkillzAudio setSkillzBackgroundMusic: " + filePath);
Debug.Log ("SkillzAudio SkillzCrossPlatform.cs setSkillzBackgroundMusic with file name: " + fileName);

#if UNITY_ANDROID
Skillz.setSkillzBackgroundMusic (filePath);
Skillz.setSkillzBackgroundMusic (fileName);
#elif UNITY_IOS
SkillzSDK.Api.setSkillzBackgroundMusic (filePath);
SkillzSDK.Api.setSkillzBackgroundMusic (fileName);
#endif
}

Expand Down

0 comments on commit 1b26804

Please sign in to comment.