// Start is called before the first frame update void Start() { cam = Camera.main; param = new CamParameters(); if (File.Exists(Application.dataPath + "/CamParam.json")) { param = Load(Application.dataPath + "/CamParam.json"); } else { param.rot = cam.transform.rotation; param.pos = cam.transform.position; Save(param, Application.dataPath + "/CamParam.json"); } stepSize = Mathf.Pow(10, param.stepSizePower); cam = Camera.main; }
// Update is called once per frame void Update() { if (Input.anyKeyDown && !Input.GetKeyDown(KeyCode.Space)) { printUntil = Time.time + 5; } if (Input.GetKeyDown(KeyCode.I)) { changed = true; param = Load(Application.dataPath + "/CamParam.json"); } if (Input.GetKeyDown(KeyCode.T)) { changed = true; param.stepSizePower += 1; } if (Input.GetKeyDown(KeyCode.G)) { changed = true; param.stepSizePower -= 1; } if (Input.GetKeyDown(KeyCode.W)) { changed = true; param.pos += new Vector3(0, 0, -stepSize); } if (Input.GetKeyDown(KeyCode.S)) { changed = true; param.pos += new Vector3(0, 0, stepSize); } if (Input.GetKeyDown(KeyCode.A)) { changed = true; param.pos += new Vector3(stepSize, 0, 0); } if (Input.GetKeyDown(KeyCode.D)) { changed = true; param.pos += new Vector3(-stepSize, 0, 0); } if (Input.GetKeyDown(KeyCode.R)) { changed = true; param.pos += new Vector3(0, stepSize, 0); } if (Input.GetKeyDown(KeyCode.F)) { changed = true; param.pos += new Vector3(0, -stepSize, 0); } if (Input.GetKeyDown(KeyCode.LeftArrow)) { changed = true; param.rot.eulerAngles += new Vector3(0, -stepSize, 0); } if (Input.GetKeyDown(KeyCode.RightArrow)) { changed = true; param.rot.eulerAngles += new Vector3(0, stepSize, 0); } if (Input.GetKeyDown(KeyCode.UpArrow)) { changed = true; param.rot.eulerAngles += new Vector3(stepSize, 0, 0); } if (Input.GetKeyDown(KeyCode.DownArrow)) { changed = true; param.rot.eulerAngles += new Vector3(-stepSize, 0, 0); } if (Input.GetKeyDown(KeyCode.Z)) { changed = true; param.focal += stepSize; } if (Input.GetKeyDown(KeyCode.H)) { changed = true; param.focal -= stepSize; } if (Input.GetKeyDown(KeyCode.X)) { changed = true; param.kinectZoom += stepSize; } if (Input.GetKeyDown(KeyCode.Y)) { changed = true; param.kinectZoom -= stepSize; } if (Input.GetKeyDown(KeyCode.L)) { changed = true; param = new CamParameters(); } if (Input.GetKeyDown(KeyCode.O)) { changed = true; Save(param, Application.dataPath + "/CamParam.json"); } if (changed) { changed = !changed; stepSize = Mathf.Pow(10, param.stepSizePower); cam.transform.position = param.pos; cam.focalLength = param.focal; cam.transform.rotation = param.rot; GameObject.FindObjectOfType <KinectInput>().zoom = param.kinectZoom; } }
public void Save(CamParameters param, string path) { string jsonData = JsonUtility.ToJson(param, true); File.WriteAllText(path, jsonData); }