PersistentTrails.Utilities.parseVector3 C# (CSharp) Method

parseVector3() public static method

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

Usage Example

Exemplo 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);
        }