Skip to content

Commit

Permalink
upgrade to package v0.8.6 (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
aranlunzer authored Aug 29, 2023
1 parent 04e47a4 commit 68ca184
Show file tree
Hide file tree
Showing 20 changed files with 43 additions and 275 deletions.
77 changes: 22 additions & 55 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ This repository contains a Croquet for Unity (C4U) view of David A. Smith's "Gua

The most important directories are the following:
* `unity/` - the Unity project directory, from which you can run the game in the Unity editor or create builds for any platform Unity supports except WebGL.
* `unity/Assets/Scenes/` - the main Guardians scene, and a SessionChooser scene (automatically included in builds) that allows a group of players to agree on a session number to join together.
* `unity/Assets/Scenes/` - the main `Guardians` scene, and a `SessionChooser` scene (automatically included in builds) that allows a group of players to agree on a session number to join together.
* `unity/Assets/CroquetJS/guardians/` - JavaScript source for building the Croquet side of the game. You can edit the code under this directory to change the game's behaviour.

# Questions
Expand Down Expand Up @@ -36,13 +36,10 @@ https://unity.com/download

> **NOTE:** For now, we **strongly recommend** using _exactly_ Unity Editor Version `2021.3.19f1` for C4U projects
2021.3.19f1 can be downloaded by pasting the following in your browser: `unityhub://2021.3.19f1/c9714fde33b6` . This deeplink to the Unity Hub should open an installation dialog for the correct version.
2021.3.19f1 can be downloaded by pasting the following in your browser: `unityhub://2021.3.19f1/c9714fde33b6` This deeplink to the Unity Hub should open an installation dialog for the correct version.

In the `Unity Hub` app, select `Open => Add project from disk`, then navigate to the `croquet-for-unity-guardians/unity` folder and hit `Add Project`.

> **Note:** During this first loading, Unity might warn that there appear to be script errors. It's fine to hit `Ignore` and continue. It appears to be related to the project's dependencies, and is determined to be harmless.

## 4.0 Set up your Croquet Developer Credentials

In the Project Navigator (typically at bottom left), go to `Assets/Settings` and click `CroquetSettings.asset`. The main field that you need to set up is the **Api Key**.
Expand All @@ -61,29 +58,37 @@ On the `CroquetSettings` asset, fill in the **Path to Node** field with the path
## 5.0 Run the Game
In the Project Navigator, go to `Assets/Scenes` and double-click `Guardians.unity`. If a "TMP importer" dialog comes up at this point, hit the top button ("Import TMP Essentials") then close the dialog. This is just part of the standard setup for Text Mesh Pro (which is used for all the UI).

In the editor's top menu, go to the `Croquet` drop-down and select `Build JS on Play` so that it has a check-mark next to it.
In the editor's top menu, go to the `Croquet` drop-down and ensure that the `Build JS on Play` item has a check-mark next to it. If not, invoke the item to toggle the mark.

**IMPORTANT: During the next step the editor may appear to have frozen, possibly for some minutes. This is not a sign of failure; please be patient.**

Press the Play button. The first time you do so after installation, C4U will notice that you have not yet installed the JavaScript build tools from the package. It will copy them across, and also run an `npm install` that fetches all Croquet and other dependencies that are needed. *Depending on network conditions, this could take a minute or more - during which, because of Unity's scheduling mechanisms, nothing will appear in the console.*

In addition to the tools installation, because `Build JS on Play` is set C4U will run a full webpack build of the JavaScript code - eventually adding webpack's output to the console, each line prefixed with "JS builder". The first build of the game will take the longest; on subsequent runs the build process will be faster.

Press the play button. The first time you do so after installation, C4U will notice that you have not yet installed the JavaScript build tools from the package. It will copy them across, and also run an `npm install` that fetches all Croquet and other dependencies that are needed. Depending on network conditions, this could take some tens of seconds - during which, because of Unity's scheduling mechanisms, you won't see anything in the console. Please wait for it to complete.
Eventually you should see the console output for startup of the game - ending with "Croquet view for scene Guardians running", at which point the game's objects will appear.

### 6.1 Specifying a Croquet Session Name
### 5.1 Specifying a Croquet Session Name

_This is an optional configurability feature, not required for you to start playing with Guardians._

Croquet sessions are inherently multi-user, and this applies fully to the sessions that drive a C4U application. If you start the same application on multiple devices, you can expect that all those devices will be in the application together - for example, all cooperating in the Guardians game.

That said, the definition of what counts as "the same application" hinges on the application instances agreeing on _all_ the following factors:

1. **Application ID**. As mentioned in Section 5.0 above, this is a dot-separated name that in C4U is a concatenation of the **App Prefix** in the `CroquetSettings` asset and the **App Name** specified on the scene's `Croquet Bridge`. For example, `io.croquet.worldcore.guardians`.
2. **API Key**. Also mentioned in Section 5.0, this is a developer-specific key for using the Croquet infrastructure. In C4U this is specified in `CroquetSettings`. Note: strictly, the API keys do not have to be identical; as long as they were issued _for the same developer_ they will count as being in agreement.
1. **Application ID**. As mentioned in Section 4.0 above, this is a dot-separated name that in C4U is a concatenation of the **App Prefix** in the `CroquetSettings` asset and the **App Name** specified on the scene's `Croquet Bridge`. For example, `io.croquet.worldcore.guardians`.
2. **API Key**. Also mentioned in Section 4.0, this is a developer-specific key for using the Croquet infrastructure. In C4U this is specified in `CroquetSettings`. Note: strictly, the API keys do not have to be identical; as long as they were issued _for the same developer_ they will count as being in agreement.
3. **Session Name**. All Croquet sessions are launched with a Session Name, which in general can be any alphanumeric token - such as `helloworld`, or `123`. Given that the Application ID and API Key for a given app are unlikely to change frequently, Session Name is the most flexible way to control whether application instances will join the same session or not.

Our initial C4U applications - including Guardians - come with two alternative ways to specify the Session Name:
Our initial C4U applications come with two alternative ways to specify the Session Name:

* **The Session Chooser scene**. Loading the scene `SessionChooser.unity` into the editor and pressing play will bring up a simple UI that allows you to select an integer (0 to 100) to act as the session's "name". Hitting the Start button in that UI then loads the Guardians scene, supplying the selected name. _Note: for this scene hand-off to work, the Guardians scene must have the index `1`. This can be confirmed in the `Build Settings` dialog._
* **Through a menu scene**. Loading the `SessionChooser` scene into the editor and pressing Play will bring up a simple UI that allows you to select an integer (0 to 100) to act as the session's "name". Hitting the "Start" button in that UI then loads the Guardians scene, supplying the selected name.

The Session Chooser can optionally be included in a build (see "Making Sharable Builds" below).
> > The `SessionChooser` scene was configured to work this way by setting the **Launch Via Menu Into Scene** property on the scene's `Croquet Bridge` object. This means that C4U will wait for a Session Name to be supplied by a menu-driven script, and will then launch the specified next scene (here, `Guardians`) using that name.
* **"Default Session Name" property**. If the Guardians scene is _not_ started by way of the Session Chooser, C4U will use whatever value is found in the **Default Session Name** property of the scene's `Croquet Bridge`.
> > The Session Chooser can optionally be included in a build (see "Making Sharable Builds" below).
* **"Default Session Name" property**. If the **Launch Via Menu Into Scene** property is left blank, pressing Play will cause C4U to take as its Session Name the value found in the `Croquet Bridge`'s **Default Session Name** property (or, if that is also blank, the Session Name will simply be "unnamed").


# Gameplay Details
Expand All @@ -105,9 +110,9 @@ Guardians is an instantly-joinable multiplayer game where you and your friends a
# Debugging Techniques
## Using a Web Browser to Debug the JavaScript Code

On both MacOS and Windows, you can choose to use an external browser such as Chrome to run the JavaScript code. For debugging, this is more convenient than letting the C4U bridge start up an invisible WebView.
On both MacOS and Windows, you can choose to use an external browser such as Chrome to run the JavaScript code. For debugging, this is more convenient than letting the C4U bridge start up an invisible WebView or Node JS process.

In the Guardians scene (while play is stopped), select the `Croquet` object in the scene hierarchy, then in that object's `Croquet Runner` component select the **Wait For User Launch** checkbox.
In the Guardians scene (while play is stopped), select the `Croquet` object in the scene hierarchy, then in that object's `Croquet Runner` component select the **Debug Using External Session** checkbox.

Now whenever you press play, the console output will include a line of the form "ready for browser to load from http://localhost:...". Copy that address (if you click on the line, it will appear as selectable text in the view below the console) then use it to launch a new browser tab. This should complete the startup of the app. All the JS developer tools (console, breakpoints etc) offered by the browser are available for working with the code.

Expand All @@ -116,50 +121,12 @@ When you stop play in the Unity editor, the browser tab will automatically leave
## Viewing JS Log Output in Unity
The `Croquet Bridge` component's **JS Log Forwarding** property has checkboxes that let you select which categories of console output in the JavaScript session will be transferred across the bridge and appear in the Unity console. By default, the "warn" and "error" categories are sent.

[July 2023] In the near future we plan to provide a configuration setting on the Unity Croquet object, to let the developer select which log categories are transferred.

# Making Sharable Builds

Before building the app to deploy for a chosen platform (e.g., Windows or MacOS standalone, or iOS or Android), there are some settings that you need to pay attention to:

* of course, there must be an **Api Key** present in `CroquetSettings.asset`
* the Build Settings dialog's **Scenes In Build** list can either include just the Guardians scene, or in addition the Session Chooser (which, if present, must be numbered scene 0). In the latter case, on startup the user will be forced to choose which session name to use.
* if the Session Chooser scene is not being included, ensure that the **Default Session Name** in the `Croquet Bridge` contains the alphanumeric token that you would like to use. For example, you might decide to build one version with the ID "playtest", that you distribute among your team during testing, and another with ID "presentation" that you use in presentations and distribute to the audience. Having the separate IDs means that people starting up one version cannot accidentally intrude on another.
* the `Croquet Bridge` **Use Node JS** checkbox _must be cleared_ for anything other than a Windows build
* all checkboxes under **Debug Logging Flags** should be cleared, so there is no wasteful logging happening behind the scenes
* the **Wait For User Launch** checkbox must be cleared

To ensure that the build will include your latest JavaScript code, you may wish to invoke `Build JS Now` on the `Croquet` drop-down (and confirm that the console messages show that the build succeeded).

Hit **Build**!

## Supplementary information for sharing MacOS builds

We have found that distributing a standalone MacOS build (`.app` file) requires some care to ensure that recipients can open it without being blocked by MacOS's security checks. One approach that we have found to work - there are doubtless others - is as follows:

1. Make the build - arriving at, say, a file `build.app`
2. In a terminal, execute the following command to replace the app's code signature
`codesign --deep -s - -f /path/to/build.app`
3. Also use a terminal command (rather than the Finder) to zip the file, to ensure that the full directory structure is captured
`tar -czf build.tgz /path/to/build.app`
4. Distribute the resulting `.tgz` file, **along with the following instructions to recipients**

a. download this `.tgz` file

b. double-click the `.tgz` to unpack the `.app` file

c. **IMPORTANT: right-click (_not_ double-click)** the `.app` file and choose "Open"

d. in the security dialog that appears, again choose "Open"

e. if prompted to give permission for the app to access the network, agree.

# Making Sharable Builds
Before building the app to deploy for a chosen platform (e.g., Windows or MacOS standalone, or iOS or Android), there are some settings that you need to pay attention to:

* there must be an **Api Key** present in `CroquetSettings.asset`
* on `Croquet Bridge` the **Debug Force Scene Rebuild** checkbox _must_ be cleared
* on `Croquet Runner` the **Wait For User Launch** checkbox _must_ be cleared
* on `Croquet Runner` the **Debug Using External Session** checkbox _must_ be cleared
* on `Croquet Runner` the **Force To Use Node JS** checkbox _must_ be cleared for anything other than a Windows build
* on `Croquet Runner` the **Run Offline** checkbox _must_ be cleared
* ensuring that all checkboxes are cleared under **Debug Logging Flags** and **JS Log Forwarding** will reduce possibly resource-hungry logging
Expand Down
15 changes: 0 additions & 15 deletions unity/Assets/NuGet.config

This file was deleted.

32 changes: 0 additions & 32 deletions unity/Assets/NuGet.config.meta

This file was deleted.

9 changes: 0 additions & 9 deletions unity/Assets/NuGet.meta

This file was deleted.

9 changes: 0 additions & 9 deletions unity/Assets/NuGet/Editor.meta

This file was deleted.

Binary file removed unity/Assets/NuGet/Editor/NugetForUnity.dll
Binary file not shown.
8 changes: 0 additions & 8 deletions unity/Assets/NuGet/LICENSE.meta

This file was deleted.

Binary file removed unity/Assets/NuGet/README.pdf
Binary file not shown.
8 changes: 0 additions & 8 deletions unity/Assets/NuGet/README.pdf.meta

This file was deleted.

Binary file removed unity/Assets/NuGet/Resources/defaultIcon.png
Binary file not shown.
88 changes: 0 additions & 88 deletions unity/Assets/NuGet/Resources/defaultIcon.png.meta

This file was deleted.

5 changes: 2 additions & 3 deletions unity/Assets/NuGet/Resources.meta → unity/Assets/Plugins.meta
100755 → 100644

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

12 changes: 6 additions & 6 deletions unity/Assets/NuGet/LICENSE → ...ssets/Plugins/websocket-sharp-LICENSE.txt
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License
The MIT License (MIT)

Copyright (c) 2018 Patrick McCarthy
Copyright (c) 2010-2023 sta.blockhead

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand All @@ -9,13 +9,13 @@ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
7 changes: 7 additions & 0 deletions unity/Assets/Plugins/websocket-sharp-LICENSE.txt.meta

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

Binary file added unity/Assets/Plugins/websocket-sharp.dll
Binary file not shown.
Loading

0 comments on commit 68ca184

Please sign in to comment.