Skip to content

Instantly share code, notes, and snippets.

@randompast
Created January 28, 2018 14:28
Show Gist options
  • Save randompast/c477bd1e870d191ae17e950777250ea1 to your computer and use it in GitHub Desktop.
Save randompast/c477bd1e870d191ae17e950777250ea1 to your computer and use it in GitHub Desktop.
Simple save with C#/Unity
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.IO;
public class io : MonoBehaviour {
// Use this for initialization
void Start () {
dat d = new dat ();
d.make (3);
File.WriteAllText ("WRITE.dat", JsonUtility.ToJson(d));
string s = File.ReadAllText("WRITE.dat");
dat d2 = JsonUtility.FromJson<dat> (s);
string original;
string result;
for (int i = 0; i < d2.p.Length; i++) {
original = "";
result = "";
original += "op " + d.p[i].x + " " + d.p[i].y + " " + d.p[i].z + "\n";
original += "or " + d.r[i].x + " " + d.r[i].y + " " + d.r[i].z + "\n";
result += "rp " + d2.p[i].x + " " + d2.p[i].y + " " + d2.p[i].z + "\n";
result += "rr " + d2.r[i].x + " " + d2.r[i].y + " " + d2.r[i].z + "\n";
print (original);
print (result);
}
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[System.Serializable]
public class dat {
public Vector3[] p;
public Quaternion[] r;
public void make(int n){
p = new Vector3[n];
r = new Quaternion[n];
for(int i = 0; i < p.Length; i++){
p[i] = Random.insideUnitSphere * 10f;
}
for(int i = 0; i < r.Length; i++){
r[i] = Random.rotation;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment