|
1 |
| -# UdonSharp |
2 |
| -## An experimental compiler for compiling C# to Udon assembly |
| 1 | +# UdonSharp has moved to the VRChat-Community git https://github.com/vrchat-community/UdonSharp |
3 | 2 |
|
4 |
| -UdonSharp is a compiler that compiles C# to Udon assembly. UdonSharp is not currently conformant to any version of the C# language specification, so there are many things that are not implemented or will not work. If you want to learn C#, I don't recommend you use UdonSharp for learning as it is right now, since there may be language features tutorials assume exist that don't yet exist in U#. |
| 3 | +New issues and pull requests should be done on the vrchat-community repository. |
5 | 4 |
|
6 |
| -This compiler is in an early state and I have no prior experience making compilers. There has been very little work done on optimizations. Despite that, programs compiled by this generally perform similarly to their graph-compiled counterparts. Though due to how Udon currently handles copying structs, UdonSharp scripts can generate more garbage than the graph counterparts at the moment. |
7 |
| - |
8 |
| -## Features that Udon supports which are currently not supported by U# |
9 |
| -- UdonSharp is currently at feature parity with the Udon graph as far as I am aware. Please message me or make an issue if you find something that should be supported, but is not. |
10 |
| - |
11 |
| -## C# features supported |
12 |
| -- Automatic property and field accessor handling for getting and setting |
13 |
| -- Flow control |
14 |
| - - Supports: `if` `else` `while` `for` `do` `foreach` `switch` `return` `break` `continue` `ternary operator (condition ? true : false)` `??` |
15 |
| - - `goto` is not currently supported: https://xkcd.com/292/ I may add it in the future anyways |
16 |
| -- Extern method overload resolution with support for default arguments and `params` argument lists |
17 |
| -- Implicit and explicit type conversions |
18 |
| -- Arrays and array indexers |
19 |
| -- All builtin arithmetic operators |
20 |
| -- Conditional short circuiting `(true || CheckIfTrue())` will not execute CheckIfTrue() |
21 |
| -- `typeof()` |
22 |
| -- Extern methods with out or ref parameters (such as many variants of `Physics.Raycast()`) |
23 |
| -- User defined methods with parameters and return values. (This does not currently support method overloads, default parameter values, or `ref`/`params` parameters) |
24 |
| -- User defined properties |
25 |
| -- Unity/Udon event callbacks with arguments. For instance, registering a OnPlayerJoined event with a VRCPlayerApi argument is valid. |
26 |
| -- String interpolation |
27 |
| -- Field initializers |
28 |
| -- Jagged arrays |
29 |
| -- Referencing other custom classes, accessing fields, and calling methods on them |
30 |
| -- Recursive method calls are supported via the `[RecursiveMethod]` attribute |
31 |
| - |
32 |
| -## Differences from regular Unity C# to note |
33 |
| -- For the best experience making UdonSharp scripts, make your scripts inherit from `UdonSharpBehaviour` instead of `MonoBehaviour` |
34 |
| -- `Instantiate()` uses a method named `VRCInstantiate()` currently since VRC handles instantiate differently. |
35 |
| -- If you need to call `GetComponent<UdonBehaviour>()` you will need to use `(UdonBehaviour)GetComponent(typeof(UdonBehaviour))` at the moment since the generic get component is not exposed for UdonBehaviour yet. GetComponent<T>() works for other Unity component types though. |
36 |
| -- Udon currently only supports array `[]` collections and by extension UdonSharp only supports arrays at the moment. It looks like they might support `List<T>` at some point, but it is not there yet. |
37 |
| -- Field initilizers are evaluated at compile time, if you have any init logic that depends on other objects in the scene you should use Start for this. |
38 |
| -- Use the `UdonSynced` attribute on fields that you want to sync. |
39 |
| -- Numeric casts are checked for overflow due to UdonVM limitations |
40 |
| -- The internal type of variables returned by `.GetType()` will not always match what you may expect since U# abstracts some types in order to make them work in Udon. For instance, any jagged array type will return a type of `object[]` instead of something like `int[][]` for a 2D int jagged array. |
41 |
| - |
42 |
| -## Udon bugs that affect U# |
43 |
| -- Mutating methods on structs do not modify the struct (this can be seen on things like calling Normalize() on a Vector3) https://vrchat.canny.io/vrchat-udon-closed-alpha-bugs/p/raysetorigin-and-raysetdirection-not-working |
44 |
| -- Instantiated objects will lose their UdonBehaviours when instantiated from a prefab and cannot be interacted with/triggered https://vrchat.canny.io/vrchat-udon-closed-alpha-bugs/p/interactive-objects-break-after-being-clonedinstanciated-on-live-worlds |
45 |
| - |
46 |
| -## Setup |
47 |
| - |
48 |
| -### Requirements |
49 |
| -- Unity 2018.4.20f1 |
50 |
| -- [VRCSDK3 + UdonSDK](https://vrchat.com/home/download) |
51 |
| -- The latest [release](https://github.com/Merlin-san/UdonSharp/releases/latest) of UdonSharp |
52 |
| - |
53 |
| -### Installation |
54 |
| -1. Read the getting started with Udon doc page https://docs.vrchat.com/docs/getting-started-with-udon this has basic installation instructions for Udon. |
55 |
| -2. Install the latest version of the VRCSDK3 linked on the getting started. |
56 |
| -3. Get the latest release of UdonSharp from [here](https://github.com/Merlin-san/UdonSharp/releases/latest) and install it to your project. |
57 |
| - |
58 |
| -### Getting started |
59 |
| -1. Make a new object in your scene |
60 |
| -2. Add an `Udon Behaviour` component to your object |
61 |
| -3. Below the "New Program" button click the dropdown and select "Udon C# Program Asset" |
62 |
| -4. Now click the New Program button, this will create a new UdonSharp program asset for you |
63 |
| -5. Click the Create Script button and choose a save destination and name for the script. |
64 |
| -6. This will create a template script that's ready for you to start working on, open the script in your editor of choice and start programming |
65 |
| - |
66 |
| -#### Asset explorer asset creation |
67 |
| - |
68 |
| -Instead of creating assets from an UdonBehaviour you can also do the following: |
69 |
| -1. Right-click in your project asset explorer |
70 |
| -2. Navigate to Create > U# script |
71 |
| -3. Click U# script, this will open a create file dialog |
72 |
| -4. Choose a name for your script and click Save |
73 |
| -5. This will create a .cs script file and an UdonSharp program asset that's set up for the script in the same directory |
74 |
| - |
75 |
| -### Example scripts |
76 |
| - |
77 |
| -#### The rotating cube demo |
78 |
| - |
79 |
| -This rotates the object that it's attached to by 90 degrees every second |
80 |
| - |
81 |
| -```cs |
82 |
| -using UnityEngine; |
83 |
| -using UdonSharp; |
84 |
| - |
85 |
| -public class RotatingCubeBehaviour : UdonSharpBehaviour |
86 |
| -{ |
87 |
| - private void Update() |
88 |
| - { |
89 |
| - transform.Rotate(Vector3.up, 90f * Time.deltaTime); |
90 |
| - } |
91 |
| -} |
92 |
| -``` |
93 |
| - |
94 |
| -#### Other examples |
95 |
| - |
96 |
| -For more example scripts take a look at the wiki page for [examples](https://github.com/Merlin-san/UdonSharp/wiki/examples), the Examples folder included with U#, or the [community resources](https://github.com/Merlin-san/UdonSharp/wiki/community-resources) page on the wiki. |
97 |
| - |
98 |
| -## Credits |
99 |
| -[**Toocanzs**](https://github.com/Toocanzs) - Implementing field initializers and helping with miscellaneous things |
100 |
| - |
101 |
| -[**PhaxeNor**](https://github.com/PhaxeNor) - Help with wiki and documentation |
102 |
| - |
103 |
| -[**bd_**](https://github.com/bdunderscore) - Significant optimizations to compiled code |
104 |
| - |
105 |
| -[**mika-f**](https://github.com/mika-f/) - Implementation of user defined property support |
106 |
| - |
107 |
| -[**UdonPie Compiler**](https://github.com/zz-roba/UdonPieCompiler) - For demonstrating how straightforward it can be to write a compiler for Udon |
108 |
| - |
109 |
| -## Links |
110 |
| - [](https://discord.gg/Ub2n8ZA) - For support and bug reports |
111 |
| - |
112 |
| - <a href="https://www.patreon.com/MerlinVR"><img src="https://img.shields.io/endpoint.svg?url=https%3A%2F%2Fmerlin-patreon.herokuapp.com%2FMerlinVR" alt="Patreon donate button" /> </a> - Support the development of UdonSharp |
| 5 | +Please do not make new issues or pull requests on this repository. |
0 commit comments