Created
May 7, 2020 12:33
-
-
Save BorisKourt/ac02243eb343ead4f679d57a8c1f3603 to your computer and use it in GitHub Desktop.
Proposal for JSON Transform serialization. With possibility to expand to other Entity data.
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
using System; | |
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
namespace KuratorCore.Serialize { | |
[Serializable] | |
public class KuratorTransform { | |
public Vector3 localPosition; | |
public Quaternion localRotation; | |
public Vector3 localScale; | |
} | |
public class KuratorSerializeEntity : MonoBehaviour | |
{ | |
private Transform transform; | |
private KuratorTransform kTransform; | |
void Start() | |
{ | |
transform = gameObject.GetComponent<Transform>(); | |
kTransform = new KuratorTransform(); | |
updateTransform(); | |
Debug.Log(getCurrentTransformAsJson()); | |
} | |
void updateTransform() { | |
kTransform.localPosition = transform.position; | |
kTransform.localRotation = transform.rotation; | |
kTransform.localScale = transform.localScale; | |
} | |
string getCurrentTransformAsJson() { | |
updateTransform(); | |
return JsonUtility.ToJson(kTransform); | |
} | |
void Update() { } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment