Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 22 additions & 22 deletions Assets/AirConsole/examples/AirConsole.Examples.asmdef
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
{
"name": "AirConsole.Examples",
"rootNamespace": "NDream.AirConsole.Examples",
"references": [
"AirConsole.Runtime"
],
"includePlatforms": [
"Android",
"Editor",
"WebGL"
],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": true,
"precompiledReferences": [
"Newtonsoft.Json.dll"
],
"autoReferenced": true,
"defineConstraints": [
"UNITY_2022_3_OR_NEWER"
],
"versionDefines": [],
"noEngineReferences": false
"name": "AirConsole.Examples",
"rootNamespace": "NDream.AirConsole.Examples",
"references": [
"AirConsole.Runtime"
],
"includePlatforms": [
"Android",
"Editor",
"WebGL"
],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": true,
"precompiledReferences": [
"Newtonsoft.Json.dll"
],
"autoReferenced": true,
"defineConstraints": [
"UNITY_2022_3_OR_NEWER"
],
"versionDefines": [],
"noEngineReferences": false
}
31 changes: 22 additions & 9 deletions Assets/AirConsole/examples/basic/ExampleBasicLogic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,12 @@ private void Awake() {

private void OnReady(string code) {
AirConsoleLogger.Log(() => "OnReady: " + code);

//Log to on-screen Console
logWindow.text = "ExampleBasic: AirConsole is ready! \n \n";

Time.timeScale = 1.0f;

//Mark Buttons as Interactable as soon as AirConsole is ready
Button[] allButtons = (Button[])FindObjectsOfType(typeof(Button));
foreach (Button button in allButtons) {
Expand All @@ -53,7 +54,8 @@ private void OnReady(string code) {

private void OnMessage(int from, JToken data) {
//Log to on-screen Console
logWindow.text = logWindow.text.Insert(0, "Incoming message from device: " + from + ": " + data.ToString() + " \n \n");
logWindow.text = logWindow.text.Insert(0,
"Incoming message from device: " + from + ": " + data.ToString() + " \n \n");

// Rotate the AirConsole Logo to the right
if ((string)data == "left") {
Expand Down Expand Up @@ -92,7 +94,8 @@ private void OnDisconnect(int device_id) {

private void OnDeviceStateChange(int device_id, JToken data) {
//Log to on-screen Console
logWindow.text = logWindow.text.Insert(0, "Device State Change on device: " + device_id + ", data: " + data + "\n \n");
logWindow.text = logWindow.text.Insert(0,
"Device State Change on device: " + device_id + ", data: " + data + "\n \n");
}

private void OnCustomDeviceStateChange(int device_id, JToken custom_data) {
Expand Down Expand Up @@ -124,6 +127,7 @@ private void OnGameEnd() {
private void OnHighScores(JToken highscores) {
//Log to on-screen Console
logWindow.text = logWindow.text.Insert(0, "On High Scores " + highscores + " \n \n");

//logWindow.text = logWindow.text.Insert (0, "Converted Highscores: " + HighScoreHelper.ConvertHighScoresToTables(highscores).ToString() + " \n \n");
}

Expand Down Expand Up @@ -197,7 +201,8 @@ public void DisplayNicknameOfFirstController() {
string nicknameOfFirstController = AirConsole.instance.GetNickname(idOfFirstController);

//Log to on-screen Console
logWindow.text = logWindow.text.Insert(0, "The first controller's nickname is: " + nicknameOfFirstController + "\n \n");
logWindow.text = logWindow.text.Insert(0,
"The first controller's nickname is: " + nicknameOfFirstController + "\n \n");
}

private IEnumerator DisplayUrlPicture(string uri) {
Expand Down Expand Up @@ -227,7 +232,8 @@ public void DisplayProfilePictureOfFirstController() {
string urlOfProfilePic = AirConsole.instance.GetProfilePicture(idOfFirstController, 512);

//Log url to on-screen Console
logWindow.text = logWindow.text.Insert(0, "URL of Profile Picture of first Controller: " + urlOfProfilePic + "\n \n");
logWindow.text = logWindow.text.Insert(0,
"URL of Profile Picture of first Controller: " + urlOfProfilePic + "\n \n");
StartCoroutine(DisplayUrlPicture(urlOfProfilePic));
}

Expand All @@ -246,7 +252,11 @@ public void DisplayAllCustomDataOfFirstController() {
// go through all properties
foreach (JProperty prop in ((JObject)data).Properties()) {
logWindow.text = logWindow.text.Insert(0,
"Custom Data on first Controller - Key: " + prop.Name + " / Value:" + prop.Value + "\n \n");
"Custom Data on first Controller - Key: "
+ prop.Name
+ " / Value:"
+ prop.Value
+ "\n \n");
}
} else {
//If there's only one property, log it to on-screen Console
Expand Down Expand Up @@ -310,7 +320,8 @@ public void DisplayNumberOfConnectedControllers() {
//This does not count devices that have been connected and then left,
//only devices that are still active
int numberOfActiveControllers = AirConsole.instance.GetControllerDeviceIds().Count;
logWindow.text = logWindow.text.Insert(0, "Number of Active Controllers: " + numberOfActiveControllers + "\n \n");
logWindow.text
= logWindow.text.Insert(0, "Number of Active Controllers: " + numberOfActiveControllers + "\n \n");
}

public void SetActivePlayers() {
Expand All @@ -333,7 +344,8 @@ public void DisplayDeviceIDOfPlayerOne() {
if (device_id != -1) {
logWindow.text = logWindow.text.Insert(0, "Player #1 has device ID: " + device_id + " \n \n");
} else {
logWindow.text = logWindow.text.Insert(0, "There is no active player # 1 - Set Active Players first!\n \n");
logWindow.text
= logWindow.text.Insert(0, "There is no active player # 1 - Set Active Players first!\n \n");
}
}

Expand Down Expand Up @@ -371,6 +383,7 @@ public void NavigateToPong() {
public void ShowAd() {
//Display an Advertisement
AirConsole.instance.ShowAd();

//Log to on-screen Console
logWindow.text = logWindow.text.Insert(0, "Called ShowAd" + "\n \n");
}
Expand Down Expand Up @@ -470,4 +483,4 @@ private void OnDestroy() {
}
#endif
}
}
}
13 changes: 10 additions & 3 deletions Assets/AirConsole/examples/game-states/GameStatesExampleLogic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ private static class ControllerEvents {
public const string ResumeGame = "resume-game";
}

private readonly string[] colorNames = new string[] { "red", "blue", "green", "yellow", "orange", "purple", "pink" };
private readonly string[] colorNames = new string[]
{ "red", "blue", "green", "yellow", "orange", "purple", "pink" };

private int colorIndex;

// This field should overwrite any game state
Expand Down Expand Up @@ -158,6 +160,7 @@ public void AssignPlayerColors() {
// updates get delayed because of rate limiting the more devices are connected, the more this becomes a problem
AirConsole.instance.SetCustomDeviceStateProperty("playerColors",
UpdatePlayerColorData(AirConsole.instance.GetCustomDeviceState(0), i, colorNames[colorIndex]));

// The controller listens for the onCustomDeviceStateChanged event.
// See the controller-game-states.html file for how this is handled there.

Expand All @@ -171,6 +174,7 @@ public void AssignPlayerColors() {

private void SetGameState(string state) {
gameStateText.text = state;

// Set a custom device state property to inform all connected devices
// of the current game state
AirConsole.instance.SetCustomDeviceStateProperty("state", state);
Expand Down Expand Up @@ -199,10 +203,13 @@ private static JToken UpdatePlayerColorData(JToken oldGameState, int deviceId, s
}

// Logging and returning the updated playerColorData
Debug.Log("AssignPlayerColor for device " + deviceId + " returning new playerColorData: " + playerColorData);
Debug.Log("AssignPlayerColor for device "
+ deviceId
+ " returning new playerColorData: "
+ playerColorData);

return playerColorData;
}
#endif
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,4 @@ private void OnDestroy() {
}
#endif
}
}
}
2 changes: 1 addition & 1 deletion Assets/AirConsole/examples/platformer/Player_Platformer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,4 @@ private void OnTriggerExit(Collider trigger) {
}
#endif
}
}
}
8 changes: 6 additions & 2 deletions Assets/AirConsole/examples/pong/ExamplePongLogic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ private void OnConnect(int device_id) {
private void OnDisconnect(int device_id) {
int player = AirConsole.instance.ConvertDeviceIdToPlayerNumber(device_id);
if (player >= 0)

// Player that was in the game left the game.
// Setting active players to length 0
{
Expand Down Expand Up @@ -82,6 +83,7 @@ private void OnMessage(int device_id, JToken data) {

private void OnPause() {
Time.timeScale = 0;

// If we were playing any sounds we must mute them when the game gets paused
AudioListener.pause = true;
}
Expand All @@ -96,6 +98,7 @@ private void OnResume() {
/// </summary>
private void OnAdShow() {
Time.timeScale = 0;

// If we were playing any sounds we must mute them when an ad is shown
AudioListener.pause = true;
}
Expand Down Expand Up @@ -137,7 +140,8 @@ private void CheckTwoPlayers() {
/// </summary>
/// <param name="player"></param>
private void Vibrate(int player) {
AirConsole.instance.Message(AirConsole.instance.ConvertPlayerNumberToDeviceId(player), new { vibrate = 1000 });
AirConsole.instance.Message(AirConsole.instance.ConvertPlayerNumberToDeviceId(player),
new { vibrate = 1000 });
}

/// <summary>
Expand Down Expand Up @@ -224,4 +228,4 @@ private void OnDestroy() {
}
#endif
}
}
}
11 changes: 4 additions & 7 deletions Assets/AirConsole/examples/pong/Racket.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,15 @@

namespace NDream.AirConsole.Examples {
public class Racket : MonoBehaviour {

public ExamplePongLogic logic;

// Use this for initialization
void Start() { }

void OnCollisionEnter2D(Collision2D col) {
private void Start() { }

private void OnCollisionEnter2D(Collision2D col) {
if (col.gameObject.GetComponent<Rigidbody2D>() != null) {

float hitPos = (col.transform.position.y - transform.position.y) / (GetComponent<Collider2D>().bounds.size.y / 2);
float hitPos = (col.transform.position.y - transform.position.y)
/ (GetComponent<Collider2D>().bounds.size.y / 2);
float hitDir = 1f;

if (col.relativeVelocity.x > 0) {
Expand All @@ -21,7 +19,6 @@ void OnCollisionEnter2D(Collision2D col) {

Vector2 dir = new Vector2(hitDir, hitPos).normalized;
col.gameObject.GetComponent<Rigidbody2D>().velocity = dir * logic.ballSpeed;

}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ namespace NDream.AirConsole.Examples {
/// </summary>
[RequireComponent(typeof(Camera))]
public class FullscreenSafeAreaHandler : MonoBehaviour {
[Tooltip("Reference to the camera that should be adjusted to the safe area. Will use the attached camera if not assigned.")]
[Tooltip(
"Reference to the camera that should be adjusted to the safe area. Will use the attached camera if not assigned.")]
[SerializeField]
private Camera targetCamera;

Expand Down Expand Up @@ -61,4 +62,4 @@ private void OnDisable() {
}
#endif
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ private void HandleSafeAreaChanged(Rect newSafeArea) {
}

#region Split Screen Configuration Methods

/// <summary>
/// Sets up two player cameras in a horizontal split (side by side)
/// </summary>
Expand Down Expand Up @@ -234,7 +233,6 @@ private void SetupFourPlayers(Rect safeArea) {
);
playerCameras[3].pixelRect = bottomRightRect;
}

#endregion

private void OnEnable() {
Expand All @@ -251,4 +249,4 @@ private void OnDisable() {
}
#endif
}
}
}
5 changes: 2 additions & 3 deletions Assets/AirConsole/examples/safe-area/UISafeAreaHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,7 @@ private void AdjustCanvasScaler(Rect safeArea) {

if (Mathf.Approximately(canvasScaler.matchWidthOrHeight, 1)) {
newReferenceResolution.x = originalReferenceResolution.y * safeAreaAspect;
} else if (canvasScaler.matchWidthOrHeight == 0)
{
} else if (canvasScaler.matchWidthOrHeight == 0) {
newReferenceResolution.y = originalReferenceResolution.x / safeAreaAspect;
} else {
float matchValue = canvasScaler.matchWidthOrHeight;
Expand Down Expand Up @@ -145,4 +144,4 @@ private void OnDisable() {
}
#endif
}
}
}
8 changes: 4 additions & 4 deletions Assets/AirConsole/examples/swipe/Player_Swipe.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@

namespace NDream.AirConsole.Examples {
namespace NDream.AirConsole.Examples {
using System.Collections;
using UnityEngine;
using Newtonsoft.Json.Linq;
Expand Down Expand Up @@ -31,7 +30,8 @@ private void OnMessage(int from, JToken message) {

//we convert the x and y values we received to float values and make a new direction vector to pass to our movement function
movementCoroutine =
StartCoroutine(MoveSphere(new Vector3((float)message["vector"]["x"], -(float)message["vector"]["y"], 0)));
StartCoroutine(MoveSphere(new Vector3((float)message["vector"]["x"],
-(float)message["vector"]["y"], 0)));
}
}
}
Expand All @@ -56,4 +56,4 @@ private void OnDestroy() {
}
#endif
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@ private void InitializeTranslations() {
//in this case, we are translating a greeting message that includes the master controller's nickname
//'welcome_nickname' has an English language value of "Welcome %nickname%, glad you're here!"
translationExample.text = AirConsole.instance.GetTranslation("welcome_nickname",
new Dictionary<string, string>
{ { "nickname", AirConsole.instance.GetNickname(AirConsole.instance.GetMasterControllerDeviceId()) } });
new Dictionary<string, string> {
{ "nickname", AirConsole.instance.GetNickname(AirConsole.instance.GetMasterControllerDeviceId()) }
});

/* Note: to really understand how translations work, we recommend creating your own project in the AirConsole Developer Console.
* in this example, we show how to retrieve translations, but you will not be able to view or edit translatable phrases for the
Expand All @@ -48,4 +49,4 @@ private void OnDestroy() {
}
}
}
#endif
#endif
2 changes: 1 addition & 1 deletion Assets/AirConsole/scripts/Editor/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@

namespace NDream.AirConsole.Editor {
public class AssemblyInfo { }
}
}
Loading