Skip to content

Commit 97116f6

Browse files
authored
Documentation: Add guide on how to script via Cilbox (#59)
* Documentation: Add guide on how to script via Cilbox * Documentation: Remove redundant Basis UI component step in Canvas UI guide * Documentation: Remove redundant Basis UI component step in Canvas UI guide (forgot to save!)
1 parent f4beff8 commit 97116f6

12 files changed

Lines changed: 83 additions & 8 deletions

File tree

content/docs/world/scripting.mdx

Lines changed: 83 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ The overridden **OnPlayerJoined()** is used as, without it, newly joining player
132132

133133
![Inspector Window showing BasisFramework prefab](/img/scripting/13.5.png)
134134

135-
- Add a Basis Scene component to the an empty Gameobject, enter an Asset Bundle Name and press the 'Create Scene Bee File' button. Store it in a remote server.
135+
- Add a Basis Scene component to an empty Gameobject, enter an Asset Bundle Name and press the 'Create Scene Bee File' button. Store it in a remote server.
136136

137137
<Callout type="info">
138138
You should disable or remove the canvas object from the scene. This is because keeping it active will result in two copies of it existing in the scene later: one copy from the scene itself and another generated by the XML.
@@ -154,4 +154,85 @@ You should disable or remove the canvas object from the scene. This is because k
154154

155155
- Click the button and the TMP text object should update the count after each button click for both local and remote players.
156156

157-
![Inspector Window showing scene running in client](/img/scripting/15.png)
157+
![Inspector Window showing scene running in client](/img/scripting/15.png)
158+
159+
## How to Add Network Syncing Scripts Via Cilbox
160+
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.
162+
163+
- Create a cube object and an ObjectRotator component to attach to it. Make sure to add [Cilboxable] above your class.
164+
165+
```cs title="ObjectRotator.cs"
166+
using UnityEngine;
167+
168+
[Cilboxable]
169+
public class ObjectRotator : MonoBehaviour
170+
{
171+
[SerializeField] private Vector3 rotationSpeed = new Vector3(0, 100f, 0);
172+
173+
private void Update()
174+
{
175+
transform.Rotate(rotationSpeed * Time.deltaTime);
176+
}
177+
}
178+
```
179+
180+
![Inspector Window showing cube with rotation script attached](/img/scripting/16.png)
181+
182+
- Create an empty Gameobject and attach a Cilbox Basis Scene component to it. The Cilbox Basis Scene becomes the cilbox that all your scripts run in.
183+
184+
<Callout type="info">
185+
Note: If your editor can't detect the Cilbox namespace, you can either create your own .asmdef file and reference Cilbox, or simply open the Cilbox asmdef and select *Auto Referenced* to resolve this.
186+
187+
![Inspector Window showing cube with rotation script attached](/img/scripting/16.5.png)
188+
</Callout>
189+
190+
![Inspector Window showing CilboxSceneBasis component](/img/scripting/17.png)
191+
192+
- Add a Basis Scene component to an empty Gameobject, enter an Asset Bundle Name and press the 'Create Scene Bee File' button. Store it in a remote server.
193+
194+
![Inspector Window showing Basis Scene component](/img/scripting/18.png)
195+
196+
![Inspector Window Load Config](/img/scripting/19.png)
197+
198+
- When you run the scene in playmode, your created script will be compiled by Unity normally. However, before actually being able to play, the scripts are swapped out by a Cilbox Proxy component. These are what actually execute as components during runtime. Basis uses its copy of Cilbox Proxy and Cilbox Basis Scene instead of yours, but your data gets serialized.
199+
200+
201+
![Inspector Window showing created Cilbox Proxy component](/img/scripting/20.png)
202+
203+
![Inspector Window showing Cilbox Scene Basis component updated in play mode](/img/scripting/21.png)
204+
205+
![Window showing play mode](/img/scripting/22.png)
206+
207+
- Run the Initialization scene and test your Cilbox script in the app. The cube should rotate.
208+
209+
![Window showing cube rotating Cilbox demo in app](/img/scripting/23.png)
210+
211+
Here is an additional example using shaders which you can try.
212+
213+
``` cs title="NM_Wind "
214+
using UnityEngine;
215+
216+
[Cilboxable]
217+
public class NM_Wind : MonoBehaviour
218+
{
219+
public Texture2D NoiseTexture;
220+
public Texture2D GustMaskTexture;
221+
public void Start()
222+
{
223+
ApplySettings();
224+
}
225+
void ApplySettings()
226+
{
227+
Shader.SetGlobalTexture("WIND_SETTINGS_TexNoise", NoiseTexture);
228+
Shader.SetGlobalTexture("WIND_SETTINGS_TexGust", GustMaskTexture);
229+
Shader.SetGlobalVector("WIND_SETTINGS_WorldDirectionAndSpeed", new Vector4(1, 1, 1, 30 * 0.2777f));
230+
Shader.SetGlobalFloat("WIND_SETTINGS_FlexNoiseScale", 1.0f / 175.0f);
231+
Shader.SetGlobalFloat("WIND_SETTINGS_ShiverNoiseScale", 1.0f / 10.0f);
232+
Shader.SetGlobalFloat("WIND_SETTINGS_Turbulence", 30 * 0.25f);
233+
Shader.SetGlobalFloat("WIND_SETTINGS_GustSpeed", 50);
234+
Shader.SetGlobalFloat("WIND_SETTINGS_GustScale", 1.0f);
235+
Shader.SetGlobalFloat("WIND_SETTINGS_GustWorldScale", 0.0016666667f);
236+
}
237+
}
238+
```

content/docs/world/ui-canvas.mdx

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,6 @@ Note: If you are making a World Space canvas, an X,Y,Z a scale of 0.001 is usual
2222

2323
![BasisFramework UI canvas add Basis Graphic Raycaster](/img/ui-canvas/3.png)
2424

25-
- Add a Basis UI Component, making sure to assign the required fields in the inspector.
26-
27-
![BasisFramework UI canvas add Basis UI Component](/img/ui-canvas/4.png)
28-
29-
![BasisFramework UI canvas add Basis UI Component required fields](/img/ui-canvas/5.png)
30-
3125
- Change the canvas layer to OverlayUI.
3226

3327
![BasisFramework UI canvas layer OverlayUI](/img/ui-canvas/6.png)

public/img/scripting/16.5.png

89 KB
Loading

public/img/scripting/16.png

42.9 KB
Loading

public/img/scripting/17.png

49.8 KB
Loading

public/img/scripting/18.png

48.5 KB
Loading

public/img/scripting/19.png

47.9 KB
Loading

public/img/scripting/20.png

75.1 KB
Loading

public/img/scripting/21.png

50.2 KB
Loading

public/img/scripting/22.png

132 KB
Loading

0 commit comments

Comments
 (0)