This mini-project aims to recreate some basic processing functions in Unity3D, using a single drag and drop file.
This is made for Unity3D version 2020.2 or newer but is largely untested (It uses C# v8 stuff).
- Download the
ProcessingLite.cs
file. - Drag and drop the
ProcessingLite.cs
file into your unity project.
(You don't need to add it to your scene) - Change inherence from the class
MonoBehaviour
toProcessingLite.GP21
.
(You will still have all MonoBehaviour functionality). - Use the supported commands in
Start
and/orUpdate
functions.
Please note that the origin of the program will be different from processing. The camera is automatically moved so that origin is placed in the lower left corner of the screen.
The positions is measured in Unity Units and not pixels.
These changes have been made to make the future transition into Unity much easier.
All these commands will not have full processing support (Example: rounded corners on rectangles). The base version of these commands should work.
Height
, this returns the height of the screen in Unity-units.Width
, this returns the width of the screen in Unity-units.
- Attributes
StrokeWeight(line width)
- Vertex
BeginShape()
EndShape()
Vertex(x, y)
- 2D primitives
Circle(x, y, diameter)
Ellipse(x, y, height, width)
Line(x1, y1, x2, y2)
Point(x, y)
Quad(x1, y1, x2, y2, x3, y3, x4, y4)
Rect(x1, y1, x2, y2)
Square(x1, y1, size)
Triangle(x1, y1, x2, y2, x3, y3)
Background(color)
Fill(color)
NoFill()
NoStroke()
Stroke(color)
MouseX
MouseY
Some features from Processing will not be ported over since the already exist in Unity.
- Data
- Input (most of them)
- Transform
- Math and Constants
- PVector
In Unity, create a class called Test
.
Change the inheritance from MonoBehaviour
to ProcessingLite.GP21
Run the program. If you see the word Hi, then it's working as intended.
using UnityEngine;
public class Test : ProcessingLite.GP21
{
void Start()
{
Line(4, 7, 4, 3);
Line(4, 5, 6, 5);
Line(6, 7, 6, 3);
Line(8, 5.5f, 8, 3);
Line(8, 7, 8, 6.8f);
}
}