Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
JulioManoel committed Apr 4, 2023
1 parent 3667898 commit 9fb467a
Show file tree
Hide file tree
Showing 12 changed files with 23,419 additions and 519 deletions.
10 changes: 3 additions & 7 deletions Unity/Assets/Editor/Figma Convert/Code/API/APIService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using UnityEngine.Networking;
using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using System.Net;
using System.IO;

Expand All @@ -13,15 +14,10 @@ public static File GetDocument() {
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);
}

// HttpWebResponse response = (HttpWebResponse)request.GetResponse();
// StreamReader reader = new StreamReader(response.GetResponseStream());
// string json = reader.ReadToEnd();
// return JsonUtility.FromJson<File>(json);
// return JsonConvert.DeserializeObject<Dictionary<string, string>>(json);
// return JsonConvert.DeserializeObject(json);
}

public static string GetImage() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
using System.Collections.Generic;

[System.Serializable]
public class ObjectProperty {
public string id;
public string name;
public bool visible = true;
public string type;
public string scrollBehavior;
// public ComponentProperty componentPropertyDefinitions;
public ComponentProperty componentPropertyDefinitions;
public string blendMode;
public ObjectProperty[] children = null;
public Absolute absoluteBoundingBox;
Expand Down
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;
}
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;
}
3 changes: 1 addition & 2 deletions Unity/Assets/Editor/Figma Convert/Code/Core.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@ public static void Start(int escala){

// Chamada da API
File apiDocument = APIService.GetDocument();
// Object apiDocument = APIService.GetDocument();
Global.apiImage = APIService.GetImage();

// Loop Pagina
for(int i = 0; i<apiDocument.document.children.Length; i++){

Expand Down
14 changes: 13 additions & 1 deletion Unity/Assets/Editor/Figma Convert/Code/build/Builder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,20 @@ public void createObject() {

if(obj.type == "TEXT")
gameObject = new Text(obj, escala).createObject();
else if(parent.name.Contains("Page"))
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();

Expand Down
1 change: 0 additions & 1 deletion Unity/Assets/Editor/Figma Convert/Code/build/Canva.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,4 @@ public GameObject createObject() {
painel.transform.SetParent(gameObject.transform);
return gameObject;
}

}
3 changes: 3 additions & 0 deletions Unity/Assets/Editor/Figma Convert/Code/classes/Global.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@ 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;
}
8 changes: 7 additions & 1 deletion Unity/Assets/Editor/Figma Convert/Code/classes/Object.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ public abstract class Object {
public ObjectProperty obj;
public float eixoX;
public float eixoY;
public float eixoZ = 0;
public int escala;
public float width;
public float height;
Expand Down Expand Up @@ -34,7 +35,12 @@ public void setPosition(RectTransform rectTransform) {
eixoX += obj.strokeWeight/(float)escala;
eixoY += obj.strokeWeight/(float)escala/2;
}
rectTransform.localPosition = new Vector3(eixoX, eixoY, 0);
eixoZ = Global.objEixoZ;
rectTransform.localPosition = new Vector3(eixoX, eixoY, eixoZ);
}

public void setRotation() {

}

public void setColor(Image painel) {
Expand Down
Loading

0 comments on commit 9fb467a

Please sign in to comment.