-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from uramakilab/canva
To the main!
- Loading branch information
Showing
54 changed files
with
25,036 additions
and
823 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
using UnityEngine; | ||
using UnityEngine.Networking; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text.RegularExpressions; | ||
using System.Net; | ||
using System.IO; | ||
|
||
abstract class APIService { | ||
|
||
public static File GetDocument() { | ||
HttpWebRequest request = (HttpWebRequest)WebRequest.Create($"https://api.figma.com/v1/files{Global.documentID}"); | ||
request.Headers.Add("Authorization", $"Bearer {Global.token}"); | ||
using (HttpWebResponse response = (HttpWebResponse) request.GetResponse()) { | ||
StreamReader reader = new StreamReader(response.GetResponseStream()); | ||
string json = reader.ReadToEnd(); | ||
Regex regex = new Regex("(|(Distance)|(RotationX)|(RotationY))#[0-9]+:[0-9]+"); | ||
json = regex.Replace(json, "$1"); | ||
return JsonUtility.FromJson<File>(json); | ||
} | ||
} | ||
|
||
public static string GetImage() { | ||
HttpWebRequest request = (HttpWebRequest)WebRequest.Create($"https://api.figma.com/v1/files{Global.documentID}/images"); | ||
request.Headers.Add("Authorization", $"Bearer {Global.token}"); | ||
using (HttpWebResponse response = (HttpWebResponse) request.GetResponse()) { | ||
StreamReader reader = new StreamReader(response.GetResponseStream()); | ||
return reader.ReadToEnd(); | ||
} | ||
} | ||
|
||
public static string ContentType(string url) { | ||
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); | ||
HttpWebResponse response = (HttpWebResponse)request.GetResponse(); | ||
string type = response.ContentType; | ||
return type.Remove(0, type.IndexOf("/")+1); | ||
} | ||
|
||
public static bool DownloadImage(string url, string path) { | ||
UnityWebRequest uwr = new UnityWebRequest(url, UnityWebRequest.kHttpVerbGET); | ||
uwr.downloadHandler = new DownloadHandlerFile(path); | ||
uwr.SendWebRequest(); | ||
while(!uwr.isDone){} | ||
return uwr.responseCode == 200 ? true : false; | ||
} | ||
|
||
public static string GetImageID(string id) { | ||
HttpWebRequest request = (HttpWebRequest)WebRequest.Create($"https://api.figma.com/v1/images{Global.documentID}?ids={id}"); | ||
request.Headers.Add("Authorization", "Bearer "+ Global.token); | ||
using (HttpWebResponse response = (HttpWebResponse) request.GetResponse()) { | ||
StreamReader reader = new StreamReader(response.GetResponseStream()); | ||
return reader.ReadToEnd(); | ||
} | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
6 changes: 6 additions & 0 deletions
6
Unity/Assets/Editor/Figma Convert/Code/API/JSON/File/Objects/ComponentProperty.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
[System.Serializable] | ||
public class ComponentProperty { | ||
public PropertyDefinitions Distance; | ||
public PropertyDefinitions RotationX; | ||
public PropertyDefinitions RotationY; | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
Unity/Assets/Editor/Figma Convert/Code/API/JSON/File/Objects/PropertyDefinitions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
[System.Serializable] | ||
public class PropertyDefinitions{ | ||
public string type; | ||
public string defaultValue; | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 9 additions & 10 deletions
19
Unity/Assets/Figma Convert/Code/Core.cs → .../Assets/Editor/Figma Convert/Code/Core.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
using UnityEngine; | ||
using System.Text; | ||
|
||
public class Builder { | ||
private ObjectProperty obj; | ||
private GameObject parent; | ||
private int escala; | ||
private GameObject gameObject; | ||
|
||
public Builder(ObjectProperty apiObj, GameObject parent, int escala) { | ||
this.obj = apiObj; | ||
this.parent = parent; | ||
this.escala = escala; | ||
} | ||
|
||
public void createObject() { | ||
if(!obj.visible) | ||
return; | ||
|
||
if(obj.type == "TEXT") | ||
gameObject = new Text(obj, escala).createObject(); | ||
else if(parent.name.Contains("Page")) { | ||
if(obj.componentPropertyDefinitions.Distance != null) { | ||
Global.objEixoZ = (float)(float.Parse(obj.componentPropertyDefinitions.Distance.defaultValue) * -1); | ||
Global.objRotationX = (float) float.Parse(obj.componentPropertyDefinitions.RotationX.defaultValue); | ||
Global.objRotationY = (float) float.Parse(obj.componentPropertyDefinitions.RotationY.defaultValue); | ||
} | ||
else { | ||
Global.objEixoZ = 0; | ||
Global.objRotationX = 0; | ||
Global.objRotationY = 0; | ||
} | ||
gameObject = new Canva(obj, escala).createObject(); | ||
gameObject.transform.Rotate(Global.objRotationX, Global.objRotationY, 0f, Space.World); | ||
} | ||
else | ||
gameObject = new Painel(obj, escala).createObject(); | ||
|
||
if(gameObject == null) | ||
return; | ||
setName(); | ||
setParent(); | ||
Debug.Log(obj.name + " Criado com Sucesso"); | ||
} | ||
|
||
private void setName() { | ||
gameObject.name = obj.name; | ||
} | ||
|
||
private void setParent() { | ||
gameObject.transform.SetParent(parent.transform); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using UnityEditor; | ||
using UnityEngine; | ||
using UnityEngine.UI; | ||
using TMPro; | ||
|
||
public class Canva : Object { | ||
|
||
public Canva(ObjectProperty obj, int escala) : base(obj, escala) {} | ||
|
||
public GameObject createObject() { | ||
GameObject gameObject = new GameObject(); | ||
gameObject.AddComponent<Canvas>(); | ||
|
||
Canvas canvas = gameObject.GetComponent<Canvas>(); | ||
canvas.renderMode = RenderMode.WorldSpace; | ||
gameObject.AddComponent<CanvasScaler>(); | ||
gameObject.AddComponent<GraphicRaycaster>(); | ||
RectTransform rectTransform = canvas.GetComponent<RectTransform>(); | ||
setSize(rectTransform); | ||
setPosition(rectTransform); | ||
|
||
GameObject painel = new Painel(obj, escala).createObject(); | ||
painel.name = obj.name; | ||
painel.transform.SetParent(gameObject.transform); | ||
return gameObject; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
using UnityEngine; | ||
using UnityEngine.UI; | ||
|
||
public class Painel : Object { | ||
|
||
public Painel(ObjectProperty obj, int escala) : base(obj, escala) {} | ||
|
||
public GameObject createObject() { | ||
gameObject = new GameObject(); | ||
Image painel = gameObject.AddComponent<Image>(); | ||
RectTransform rectTransform = painel.GetComponent<RectTransform>(); | ||
setSize(rectTransform); | ||
setPosition(rectTransform); | ||
setColor(painel); | ||
setCornerRadius(); | ||
setBorder(); | ||
|
||
if(obj.children != null) { | ||
for(int i = 0; i < obj.children.Length; i++) { | ||
Builder objeto = new Builder(obj.children[i], gameObject, escala); | ||
objeto.createObject(); | ||
} | ||
} | ||
return gameObject; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
using UnityEngine; | ||
// using UnityEngine.UI; | ||
using TMPro; | ||
|
||
public class Text : Object { | ||
|
||
public Text(ObjectProperty obj, int escala) : base(obj, escala){} | ||
|
||
public GameObject createObject() { | ||
gameObject = new GameObject(); | ||
TextMeshProUGUI text = gameObject.AddComponent<TextMeshProUGUI>(); | ||
setCharacters(text); | ||
setFontSize(text); | ||
italicAndNegrito(text); | ||
RectTransform rectTransform = gameObject.GetComponent<RectTransform>(); | ||
setSizeFont(); | ||
setSizeRectFont(rectTransform); | ||
setPosition(rectTransform); | ||
setColorText(); | ||
gameObject.transform.Rotate(180.0f, 0f, 0f, Space.World); | ||
return gameObject; | ||
} | ||
|
||
public void setCharacters(TextMeshProUGUI text) { | ||
text.text = obj.characters; | ||
} | ||
|
||
public void setFontSize(TextMeshProUGUI text) { | ||
text.fontSize = obj.style.fontSize; | ||
} | ||
|
||
public void setSizeFont() { | ||
width = (float)1/escala; | ||
height = (float)1/escala; | ||
Vector3 size = new Vector3(width, height, 1); | ||
gameObject.transform.localScale = size; | ||
} | ||
|
||
public void setSizeRectFont(RectTransform rectTransform) { | ||
width = obj.absoluteBoundingBox.width; | ||
height = obj.absoluteBoundingBox.height; | ||
rectTransform.sizeDelta = new Vector2(width, height); | ||
width = width/escala; | ||
height = height/escala; | ||
} | ||
|
||
public void italicAndNegrito(TextMeshProUGUI text) { | ||
/*if(obj.style.italic == true && obj.style.fontWeight >= 700) | ||
textMesh.fontStyle = FontStyle.BoldAndItalic; | ||
else if(obj.style.fontWeight >= 700) | ||
textMesh.fontStyle = FontStyle.Bold; | ||
else if(obj.style.italic == true) | ||
textMesh.fontStyle = FontStyle.Italic;*/ | ||
} | ||
|
||
public void setColorText() {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
static class Global { | ||
public static string documentID; | ||
public static string token; | ||
public static string apiImage; | ||
public static float objEixoZ; | ||
public static float objRotationX; | ||
public static float objRotationY; | ||
} |
Oops, something went wrong.