示例#1
0
        public static bool LoadFromFilepath(out Calibration loadedCalibration, string path)
        {
            bool   fileExists = false;
            string calibrationStr;

            loadedCalibration = new Calibration();
            if (!File.Exists(path))
            {
                Debug.LogWarning(Misc.debugText + "Calibration file not found!");
            }
            else
            {
                calibrationStr = File.ReadAllText(path);
                if (calibrationStr.IndexOf('{') < 0 || calibrationStr.IndexOf('}') < 0)
                {
                    // if the file exists but is unpopulated by any info, don't try to parse it
                    // this is a bug with jsonUtility that it doesn't know how to handle a fully empty text file >:(
                    Debug.LogWarning(Misc.debugText + "Calibration file not found!");
                }
                else
                {
                    // if it's made it this far, just load it
                    fileExists = true;
                    // removed line to reduce console clutter
                    // todo: make a setting for verbose output that does this
                    // Debug.Log(Misc.debugText + "Calibration loaded! loaded from " + path);
                    loadedCalibration = JsonUtility.FromJson <Calibration>(calibrationStr);
                    // loadedCalibration.loadedFrom = path;
                }
            }
            // make sure test value is always 0 unless specified by calibrator
            // inverted viewcone is handled separately now, so just take the abs of it
            loadedCalibration.viewCone.Value = Mathf.Abs(loadedCalibration.viewCone.Value);

            loadedCalibrations = new List <Calibration>()
            {
                loadedCalibration
            };

            return(fileExists);
        }