Skip to content

Commit bb2cde7

Browse files
authored
Merge pull request #82 from Chylum/docs/why-cilbox
Add Clarification That Cilbox Is Especially for UGC/DLC and Security
2 parents e1f7296 + 73a1cca commit bb2cde7

1 file changed

Lines changed: 63 additions & 3 deletions

File tree

content/docs/world/scripting.mdx

Lines changed: 63 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@ For reasons, custom code must either be generated by rebuilding the client (i.e.
88

99
## How to Add Scripts Via Unity Client Build
1010

11+
<Callout type="info">
12+
13+
If you are building a game or application with the framework, and supporting user-generated content (such as scenes, avatars, or props) is not a priority, you may prefer to build your MonoBehaviour scripts natively rather than leveraging Cilbox.
14+
15+
This is because Cilbox is a CIL interpreter, which will incur a significant speed penalty and may support a subset of available language features.
16+
</Callout>
17+
1118
- Create a canvas object with a button inside it.
1219

1320
- Add a script to the button object. As a simple example, we'll create a script that updates a TMP text object called TestButton.
@@ -158,7 +165,13 @@ You should disable or remove the canvas object from the scene. This is because k
158165

159166
## How to Add Network Syncing Scripts Via Cilbox
160167

161-
The Cilbox CIL can be used to create scripts that work in runtime. Currently, Cilbox is still quite experimental. The following example shows how to create a script to make a cube rotate using Cilbox.
168+
Cilbox is a scripting system to act as glue to help provide some minimal game logic, enabling portability of basic behaviours in user-generated content such as props, avatars, and scenes. It can be used to create scripts that work at runtime.
169+
170+
Currently, Cilbox is still very experimental. The following example shows how to create a script to make a cube rotate using Cilbox.
171+
172+
<Callout type="info">
173+
Note: Cilbox is especially useful if you are making an application or game that loads user-generated content, and want to support scripting on that user content. It allows shipping scripts as something like DLC alongside your other content, while also providing a more secure sandbox for code to be executed within, preventing scripts with harmful or undesirable behaviours from executing.
174+
</Callout>
162175

163176
- Create a cube object and an ObjectRotator component to attach to it. Make sure to add [Cilboxable] above your class.
164177

@@ -208,7 +221,7 @@ Note: If your editor can't detect the Cilbox namespace, you can either create yo
208221

209222
![Window showing cube rotating Cilbox demo in app](/img/scripting/23.png)
210223

211-
Here is an additional example using shaders which you can try.
224+
Below are some additional example scripts you can try out.
212225

213226
``` cs title="NM_Wind "
214227
using UnityEngine;
@@ -235,4 +248,51 @@ public class NM_Wind : MonoBehaviour
235248
Shader.SetGlobalFloat("WIND_SETTINGS_GustWorldScale", 0.0016666667f);
236249
}
237250
}
238-
```
251+
```
252+
253+
```cs title="Gun"
254+
using UnityEngine;
255+
using Basis.Scripts.BasisSdk.Interactions;
256+
using Basis.Scripts.Device_Management.Devices;
257+
258+
[Cilboxable]
259+
public class Gun : MonoBehaviour
260+
{
261+
private BasisPickupInteractable pickup;
262+
263+
void Start()
264+
{
265+
this.pickup = GetComponent<BasisPickupInteractable>();
266+
this.pickup.OnInteractStartEvent.AddListener(OnPickup);
267+
this.pickup.OnInteractEndEvent.AddListener(OnDrop);
268+
this.pickup.OnPickupUse.AddListener(OnUse);
269+
}
270+
271+
private void OnPickup(BasisInput input)
272+
{
273+
Debug.Log("HoloGun: Picked up!");
274+
}
275+
276+
private void OnDrop(BasisInput input)
277+
{
278+
Debug.Log("HoloGun: Dropped!");
279+
}
280+
281+
void OnUse(BasisPickUpUseMode mode)
282+
{
283+
switch (mode)
284+
{
285+
case BasisPickUpUseMode.OnPickUpUseDown:
286+
Debug.Log("HoloGun: Pew Pew!");
287+
break;
288+
case BasisPickUpUseMode.OnPickUpUseUp:
289+
Debug.Log("HoloGun: Pew Pew! (released)");
290+
break;
291+
}
292+
}
293+
}
294+
```
295+
296+
<Callout type="info">
297+
Instead of BasisNetworkBehaviour, BasisNetworkShim can be inherited from to create networked scripts.
298+
</Callout>

0 commit comments

Comments
 (0)