Skip to content

Instantly share code, notes, and snippets.

@BorisKourt
Created May 7, 2020 12:33
Show Gist options
  • Save BorisKourt/ac02243eb343ead4f679d57a8c1f3603 to your computer and use it in GitHub Desktop.
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.
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