40
loading...
This website collects cookies to deliver better user experience
Resources
would be handful. gameObject
by creating and adding necessary components in runtime. But it would take some effort. At this point, I asked myself, why not create a wrapper api for that?OnGUI
in unity, love.draw
will execute block and draw graphic related stuff. It's that easy. function love.draw()
love.graphics.rectangle("fill", 20, 50, 60, 120 )
love.graphics.setColor(0, 1, 0, 1)
love.graphics.print("This is a pretty lame example.", 10, 200)
end
private void Start()
{
Quill.Init();
}
...
Quill.mainCanvas.sortingOrder = 100;
Quill.mainCanvas.renderMode = RenderMode.WorldSpace;
...
* QuillElement (Empty) // Wraps RectTransform and provides base functionality
* QuillLabel // Derives from Text
* QuillBox // Derives from Image
* QuillButton // Derives from Button
private void Start()
{
Quill.Init();
var box = Quill.CreateBox(Color.red);
Quill.mainRoot.Add(box);
box.SetSize(200, 200);
box.SetPosition(50, -50);
var label = Quill.CreateLabel("hello world");
box.root.Add(label);
label.SetPosition(50, -50);
}
IQuillElements
so base functionality of RectTransorm
is available for each elements.QuillButton button;
private void Start()
{
Quill.Init();
var box = Quill.CreateBox(Color.red);
Quill.mainRoot.Add(box);
box.SetSize(300, 300);
button = Quill.CreateButton("hello button");
button.box.color = Color.blue;
box.root.Add(button);
button.box.SetSize(200, 40);
button.box.SetPosition(50, -50);
button.onClick.AddListener(OnButtonClick);
box.SetPosition(50, -50);
}
private void OnButtonClick()
{
button.label.text = "this button clicked";
}
// ScoreManager
int score;
private void Update()
{
score += 5;
if (Input.GetKeyDown(KeyCode.Space))
{
var data = new MessageData("score");
data.container.Add("playerName", "John");
data.container.Add("playerScore", score);
Quill.message.Post(data);
}
}
// ScoreView
QuillLabel scoreLabel;
int currentScore;
private void Start()
{
scoreLabel = Quill.CreateLabel("score: " + currentScore);
Quill.message.Register(MessageListener);
}
private void MessageListener(MessageData data)
{
if (data.id == "score")
{
// handle event
}
}
Quill
initialization, QuillLua
takes step in.private void Start()
{
Quill.Init();
QuillLua.Run();
}
private void Update()
{
QuillLua.OnUpdate();
}
private void OnDestroy()
{
QuillLua.Exit();
}
Resources
folder in Unity there is another special folder StreamingAssets
. This folder will be available after built. QuillLua
will read all lua files placed in StreamingAssets/LUA
directory and these special functions will be called, accordingly.function OnInit()
end
function OnUpdate(dt)
end
function OnMessage(data)
end
function OnExit()
end
OnMessage
callback listens for events dispatched from c# api. Any data added to message data container will be coverted to a lua table...
var data = new MessageData("on_player_score");
data.container.Add("score", 3);
data.container.Add("player", "cemuka");
Quill.message.Post(data); // this is opttional, if scope is lua
QuillLua.MessagePost(data);
...
function OnMessage(data)
if data.id == "on_player_score" then
quill.log(data.container.player)
quill.log(data.container.score)
end
end
clickHandler
function. Its label will hide after 3 seconds.local button = nil
local timer = 0
local timerStarted = false
function cilckHandler()
button.label.setText("button clicked")
local buttonColor = button.box.getColor()
buttonColor.a = 0.3
button.box.setColor(buttonColor)
timer = 3
timerStarted = true
end
function OnInit()
root = quill.mainRoot()
color = {}
color.r = 0.4
color.g = 0.8
color.b = 0.3
color.a = 1
button = quill.button("this is a button")
button.box.setColor(color)
button.onClick.add(cilckHandler)
root.addChild(button)
button.setPosition(20,-200)
end
function OnUpdate(dt)
if timerStarted then
timer = timer - dt
if timer < 0 then
button.label.hide()
timerStarted = false;
end
end
end
...
root = quill.mainRoot()
local firaCode = "Fira Code"
quill.loadFont(firaCode, 24);
local label1 = quill.label("label1") -- default font (Arial)
local label2 = quill.label("label2") -- default font (Arial)
label2.setFont(firaCode) -- Fira Code
quill.setDefaultFont(firaCode) -- now default font is Fira Code
local label3 = quill.label("label3") -- default font (Fira Code)
root.addChild(label1)
root.addChild(label2)
root.addChild(label3)
label1.setPosition(100, -100)
label2.setPosition(100, -150)
label3.setPosition(100, -200)
...
QuillLua
will look up is StreamingAssets/IMAGE
....
local box = quill.box()
box.setColor(color)
box.setSize(300, 100)
box.sprite("icons/body.png");
...
...
options = {}
options.filterMode = "Point"
options.pivotX = 0.5
options.pivotY = 0.5
options.extrude = 0
options.pixelsPerUnit = 100
options.borderX = 3
options.borderY = 3
options.borderZ = 3
options.borderW = 3
local box = quill.box()
box.setColor(color)
box.setSize(300, 100)
box.sprite("body.png", options);
box.setImageType("Sliced");
root.addChild(box);
box.setPosition(100,-100)
...
-- lib/test.lua
test = {}
function test.greeter()
quill.log("hello modules")
end
return test
-- main.lua
local module = require("lib/test")
function OnInit()
module.greeter()
end