Skip to content

Commit dc61864

Browse files
authored
Documentation: Add guide on how to add scripts via Unity client build #47 (#48)
* Documentation: Add guide on how to add scripts via Unity client build * Documentation: Remove redundant files
1 parent 25e4788 commit dc61864

10 files changed

Lines changed: 57 additions & 1 deletion

File tree

content/docs/world/meta.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"title": "World",
33
"icon": "Globe",
4-
"pages": ["index", "setup", "building", "testing", "props", "ui-canvas"]
4+
"pages": ["index", "setup", "building", "testing", "props", "ui-canvas", "scripting"]
55
}

content/docs/world/scripting.mdx

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
---
2+
title: Scripting
3+
---
4+
5+
import { Callout } from 'fumadocs-ui/components/callout';
6+
7+
For reasons, custom code must either be generated by rebuilding the client (i.e., the Unity project) or via Cilbox (a sandbox CIL).
8+
9+
## How to Add Scripts Via Unity Client Build
10+
11+
- Create a canvas object with a button inside it.
12+
13+
- Add a script to the button object. As a simple example, we'll create a script that updates a TMP text object called TestButton.
14+
15+
- Create and assign a TMP text object to the Button Text field in the inspector.
16+
17+
![Inspector Window showing Test Button component](/img/scripting/1.png)
18+
19+
``` cs title="TestButton.cs"
20+
public class TestButton : MonoBehaviour
21+
{
22+
[SerializeField] private TextMeshPro buttonText;
23+
24+
public void OnButtonClick()
25+
{
26+
buttonText.text = "Clicked!";
27+
}
28+
}
29+
```
30+
31+
32+
- Select the button and add an onClick() event to it. Assign your Test Button Gameobject to it, making sure to select TestButton.OnButtonClick as the method which your button will call on when clicked.
33+
34+
![Inspector Window showing button event handler and TMP text assigned](/img/scripting/2.png)
35+
36+
- Add a Basis Prop component to the canvas Gameobject, enter an Asset Bundle Name and press the 'Create Prop Bee File' button. Use the Loadable Config Editor to generate an XML file.
37+
38+
![Inspector Window showing button using Basis Prop](/img/scripting/3.png)
39+
40+
- Open the BasisFramework prefab. In the Bundled Content Folder component's, add the generated .bee password and url.
41+
42+
![Inspector Window showing BasisFramework prefab](/img/scripting/4.png)
43+
44+
![Inspector Window showing BasisFramework prefab](/img/scripting/5.png)
45+
46+
- Run the Initialization scene.
47+
48+
![Window showing Initialization scene running](/img/scripting/6.png)
49+
50+
- Build the Unity client. Your custom script will script will be included in the build.
51+
52+
![Window showing Unity Client Build Profiles](/img/scripting/7.png)
53+
54+
- Click the button and the TMP text object should update to show "Clicked!".
55+
56+
![Window showing custom script running](/img/scripting/8.png)

public/img/scripting/1.png

11.3 KB
Loading

public/img/scripting/2.png

9.65 KB
Loading

public/img/scripting/3.png

134 KB
Loading

public/img/scripting/4.png

10.7 KB
Loading

public/img/scripting/5.png

58.8 KB
Loading

public/img/scripting/6.png

185 KB
Loading

public/img/scripting/7.png

116 KB
Loading

public/img/scripting/8.png

15.8 KB
Loading

0 commit comments

Comments
 (0)