Skip to content

Commit

Permalink
Merge remote-tracking branch 'UniversalWindowPlatformSamples/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
TautvydasZilys committed Jan 30, 2021
2 parents 5116461 + 6d30496 commit 9df9907
Show file tree
Hide file tree
Showing 184 changed files with 3,887 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
using UnityEngine;
using System.Collections;

public class AssocationLaunching : MonoBehaviour
{
private string uri = "http://www.unity3d.com";
private string extension = ".txt";
private string relativeFilePath = "Data\\StreamingAssets\\hello.txt";
private string assocationFilePath = "Data\\StreamingAssets\\hello.myunitygame";

// Use this for initialization
void Start () {

}

// Update is called once per frame
void OnGUI ()
{
#if UNITY_WSA
#if UNITY_EDITOR
GUILayout.Label("Build to Windows Store Apps first!");
#endif
GUILayout.Label("Application args: " + UnityEngine.WSA.Application.arguments);
GUILayout.Space(15);
GUILayout.Label("1. Example: shows how to open an URL in a browser");
uri = GUILayout.TextField(uri);
if (GUILayout.Button("Launch via Uri"))
UnityEngine.WSA.Launcher.LaunchUri(uri, true);

GUILayout.Space(15);
// Note: myunitygame tag must match with the one in Package.appxmanifest under Protocol field
// You can also Wnd+R, and type myunitygame:// , this will also launch this application.
GUILayout.Label("2. Example: shows how to open this Windows Store application via protocol, this way you can open this application from another Windows Store application.");
if (GUILayout.Button("Launch via Uri with 'myunitygame'"))
{
// This will invoke OnActivated function in App.xaml.cs
UnityEngine.WSA.Launcher.LaunchUri("myunitygame://", true);
}
GUILayout.Space(15);
// Note: myunitygame extension must match with the one in Package.appxmanifest under File Type Assocations
GUILayout.Label("3. Example: shows how to open this Windows Store application via file association. Try creating a file, for ex., 'test.myunitygame', open it, this WSA application should open.");
if (GUILayout.Button("Launch via File '" + assocationFilePath + "'"))
{
// This will invoke OnFileActivated function in App.xaml.cs
UnityEngine.WSA.Launcher.LaunchFile(UnityEngine.WSA.Folder.Installation, assocationFilePath, true);
}
GUILayout.Space(15);
GUILayout.Label(string.Format("4. Example: open an application associated {0} extension (by default it's notepad.exe)", extension));
extension = GUILayout.TextField(extension);
if (GUILayout.Button("Launch via File Picker"))
UnityEngine.WSA.Launcher.LaunchFileWithPicker(extension);

GUILayout.Space(15);
relativeFilePath = GUILayout.TextField(relativeFilePath);
GUILayout.Label("5. Example: shows how to open a file from application data folder");
if (GUILayout.Button("Launch via File"))
UnityEngine.WSA.Launcher.LaunchFile(UnityEngine.WSA.Folder.Installation, relativeFilePath, true);
#else
GUILayout.Label("Please switch to Windows Store Apps");
#endif
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file not shown.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Hello Unity

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Hello Unity

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file not shown.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
m_EditorVersion: 5.3.4p4
m_StandardAssetsVersion: 0
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
6 changes: 6 additions & 0 deletions UniversalWindowsPlatformSamples/AssocationLaunch/ReadMe.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Windows Store App example showing how to launch an app for file type or a protocol.
More info - https://code.msdn.microsoft.com/windowsapps/Association-Launching-535d2cec

* Open project with Unity 5.3 or higher
* Build to Windows Store (SDK 8.1)
* Click on buttons to see protocol and file type association in action.
16 changes: 16 additions & 0 deletions UniversalWindowsPlatformSamples/LiveTiles/Assets/Spin.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using UnityEngine;
using System.Collections;

public class Spin : MonoBehaviour {

// Use this for initialization
void Start () {

}

// Update is called once per frame
void Update () {
float rotation = 100 * Time.deltaTime;
transform.Rotate(rotation, rotation, rotation);
}
}
8 changes: 8 additions & 0 deletions UniversalWindowsPlatformSamples/LiveTiles/Assets/Spin.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

141 changes: 141 additions & 0 deletions UniversalWindowsPlatformSamples/LiveTiles/Assets/TileSample.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
using UnityEngine;
using UnityEngine.WSA;
#if NETFX_CORE
using System;
using Windows.Storage;
#endif

public class TileSample : MonoBehaviour
{
private bool screenshotToTile = false;
private bool textToTile = false;
private string text = "";
private int counter = 0;
private Tile secondaryTile = null;
private int secondaryTileBadge = 0;

void OnGUI()
{
// secondary tile and toast can pass arguments to application,
//which we can use to determine, if application was activated via secondary tile or toast notification
string activationMode;
if (UnityEngine.WSA.Application.arguments == "--secondary")
activationMode = "Activated via secondary tile";
else if (UnityEngine.WSA.Application.arguments == "--toast")
activationMode = "Activated via toast notification";
else
activationMode = "Activated normally";
GUILayout.Label(activationMode);


text = GUILayout.TextField(text);


// Update main tile with text, screenshot of both
// we can't read screen here, to we just set flags to do so
if (GUILayout.Button("Update tile (image only)"))
{
screenshotToTile = true;
textToTile = false;
}
if (GUILayout.Button("Update Tile (text only)"))
Tile.main.Update("", "", "", text);
if (GUILayout.Button("Update Tile (image and text)"))
{
screenshotToTile = true;
textToTile = true;
}


// Secondary tile first has to be create
// then you can update it just like you would update main tile
if (GUILayout.Button("Secondary tile (text only)"))
{
// first try to find existing secondary tile by it's id
if (secondaryTile == null)
secondaryTile = Tile.GetSecondary("secondary");
// Note that user can destroy tile by unpinning it
// so you should check secondaryTile.exists
if (secondaryTile == null || !secondaryTile.exists)
{
// Create the tile, if it does not exist
// id, arguments and 150x150 logo are required, when creating
SecondaryTileData tileData = new SecondaryTileData("secondary", "Secondary Tile Example");
tileData.arguments = "--secondary"; // these arguments will be passed to application, when secondary tile is clicked
tileData.square150x150Logo = "ms-appx:///Assets/SquareTile.png";
secondaryTile = Tile.CreateOrUpdateSecondary(tileData);
// at this moment user is presented with pop-up to pin secondary tile
// there is no tile yet, so no updates can be performed
}
else if (secondaryTile.exists && secondaryTile.hasUserConsent)
{
// remember to check secondaryTile.hasUserConsent
// if it's false, tile is not yet created
// if user agrees, both exists and hasUserConsent are true
secondaryTile.Update("", "", "", text);
secondaryTile.UpdateBadgeNumber(++secondaryTileBadge);
}
else if (!secondaryTile.exists)
secondaryTile = null;
}


if (GUILayout.Button("Show toast notification"))
{
// Create and show toast notification
// remember to set application "Toast Capable" in appxmanifest
Toast toast = Toast.Create("", "This is toast notification");
toast.arguments = "--toast"; // these arguments will be passed to application, when user clicks on notification
toast.Show();
}
}

void OnPostRender()
{
if (screenshotToTile)
{
screenshotToTile = false;
TakeScreenshotToTile();
}
}

void TakeScreenshotToTile()
{
// 150x150 tile is required, other sizes are optional
Texture2D texture = new Texture2D(150, 150);
texture.ReadPixels(new Rect(Screen.width / 2 - 75, Screen.height / 2 - 75, 150, 150), 0, 0);
texture.Apply();

byte[] png150x150 = texture.EncodeToPNG();
UpdateTile(png150x150);
}

#if NETFX_CORE
async
#endif
void UpdateTile(byte[] png150x150)
{
#if NETFX_CORE
// In order to change tile image, we should change the uri too
// in this example we store images in applications local storage
// we must also take care of cleaning it up
StorageFolder localFolder = ApplicationData.Current.LocalFolder;
StorageFolder tilesFolder = null;
try
{
tilesFolder = await localFolder.GetFolderAsync("tiles");
}
catch (Exception)
{}
if (tilesFolder != null)
await tilesFolder.DeleteAsync();
tilesFolder = await localFolder.CreateFolderAsync("tiles");
string tileFile = "tile" + counter++ + ".png";
StorageFile file = await tilesFolder.CreateFileAsync(tileFile, CreationCollisionOption.ReplaceExisting);
await FileIO.WriteBytesAsync(file, png150x150);

string txt = textToTile ? text : "";
Tile.main.Update("ms-appdata:///local/tiles/" + tileFile, "", "", txt);
#endif
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file not shown.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file not shown.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
m_EditorVersion: 5.3.4p4
m_StandardAssetsVersion: 0
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
7 changes: 7 additions & 0 deletions UniversalWindowsPlatformSamples/LiveTiles/ReadMe.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Windows Store exaple on how to use Unity tiles API.
The application will display a spinning cube and allows capturing screenshot of it and putting on a tile.
The following is showcased in the example:
* Updating main tile with image, text or both (text is taken from entry field at the top). Pin your application in the start screen, click any of top 3 buttons and then look at the tile in start screen, you should see it updated.
* Creating a new secondary tile. The button for creating secondary tile creates only one secondary tile on start screen and later updates it. This sample also shows use of badges: with each update a numeric badge on a tile is updated.
* Showing a toast notification. Mark your application as "Toast Capable" in the Package.appxmanifest and the toast button will display a notification.
* Application activation with arguments. At the very top of of application a text shows whether application was started by clicking main tile, secondary tile or activated via toast notification.
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using UnityEngine;
using System.Collections;

public class SimpleScript : MonoBehaviour
{
// This callback should be set from MainPage.xaml.cs
public delegate void NavigateBack();
public static NavigateBack navigateBack;

private int clickCount = 0;
private float time = 0.0f;
// Use this for initialization
void Start () {

}

// Update is called once per frame
void Update ()
{
time += Time.deltaTime;
transform.Rotate(Vector3.up, Time.deltaTime * 20.0f);
if (Input.GetMouseButtonDown(0))
clickCount++;
}

void OnGUI()
{
#if UNITY_EDITOR
GUILayout.Label("Build to Windows Store Apps (SDK 8.1) on top of Export directory");
#endif
GUILayout.Box("Time: " + time);
GUILayout.Box(string.Format("{0} x {1} - {2} clicks", Input.mousePosition.x, Input.mousePosition.y, clickCount));
if (GUILayout.Button("Navigate Back"))
{
#if UNITY_METRO || UNITY_WSA
UnityEngine.WSA.Application.InvokeOnUIThread(() =>
{
navigateBack();
}, false);
#endif
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file not shown.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file not shown.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 9df9907

Please sign in to comment.