PersistentTrails.Utilities.parseQuaternion C# (CSharp) Method

parseQuaternion() public static method

public static parseQuaternion ( string inString ) : Quaternion
inString string
return UnityEngine.Quaternion
        public static Quaternion parseQuaternion(string inString)
        {
            string[] floatStrings = inString.Split(';');
            Quaternion result = new Quaternion();
            if (floatStrings.Length == 4)
            {
                float.TryParse(floatStrings[0], out result.x);
                float.TryParse(floatStrings[1], out result.y);
                float.TryParse(floatStrings[2], out result.z);
                float.TryParse(floatStrings[3], out result.w);
            }
            else
            {
                Debug.Log("Couldn't parse " + inString + " to Quaternion");
            }
            return result;
        }

Usage Example

Esempio n. 1
0
        public static List <PartValue> loadCraftFromFile(string fileName)
        {
            List <PartValue> loadedList = new List <PartValue>();
            PartValue        newValue   = new PartValue();
            StreamReader     stream     = new StreamReader(fileName); // exceptions handled by assembleCraft
            string           newLine    = string.Empty;
            int craftFileFormat         = 0;

            int.TryParse(stream.ReadLine(), out craftFileFormat);
            Utilities.debug.debugMessage(String.Concat("Loading crf file, format ", craftFileFormat, ", ", fileName));
            try
            {
                while (!stream.EndOfStream && !(newLine == "[EOF]"))
                {
                    newLine           = stream.ReadLine();
                    newValue.partName = newLine;
                    newValue.position = Utilities.parseVector3(stream.ReadLine());
                    newValue.rotation = Utilities.parseQuaternion(stream.ReadLine());
                    float.TryParse(stream.ReadLine(), out newValue.scale);
                    //Debug.Log("finding model " + newValue.partName);
                    newValue.model = findPartModel(newValue.partName);
                    //Debug.Log("model null? " + (newValue.model == null));
                    loadedList.Add(newValue.clone());
                }
            }
            catch (Exception e)
            {
                //Utilities.debug.debugMessage("load craft file error: " + e.ToString());
                Utilities.debug.debugMessage("Got expected exception from streamreader, part list done");
            }
            return(loadedList);
        }