Exemple #1
0
        //====================  BASIC INTERFACE  ====================//

        override protected void InitTool()
        {
            base.InitTool();

            Cursor.visible = true;

            //string pointsData = GameMgr.CurrentData();

            //string fileToFind = GameMgr.CurrentDataName();
            string fileToFind = "cnv";

            // Check to make sure if files need to be created...
            string documentsFolder = string.Empty;

            if (Application.platform == RuntimePlatform.OSXEditor || Application.platform == RuntimePlatform.OSXPlayer)
            {
                documentsFolder = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
            }
            else
            {
                documentsFolder = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
            }

            // Makes sure the folders are created.

            string quorumFolder = Path.Combine(documentsFolder, "Quorum");

            Directory.CreateDirectory(quorumFolder);

            string cnvFolder = Path.Combine(quorumFolder, "CNV");

            Directory.CreateDirectory(cnvFolder);

            string filename = string.Format("{0}{1}{2}", cnvFolder, Path.DirectorySeparatorChar, fileToFind);

            Debug.LogFormat("Parsing points from file {0} {1}", GameMgr.CurrentDataName(), filename);

            string[] pointsData = null;

            /*using (FileStream fs = File.Open(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
             * using (BufferedStream bs = new BufferedStream(fs))
             * using (StreamReader sr = new StreamReader(bs))
             * {
             *  string line;
             *  while ((line = sr.ReadLine()) != null)
             *  {
             *
             *  }
             * }*/

            try
            {
                string[] filetypes = { "csv", "txt" };
                foreach (string filetype in filetypes)
                {
                    string testFile = string.Format("{0}.{1}", filename, filetype);
                    if (File.Exists(testFile))
                    {
                        //pointsData = File.ReadAllLines(testFile);

                        _currentFile = testFile;
                        _totalLines  = CountLines(_currentFile);
                        _halfLines   = Mathf.FloorToInt(_totalLines / 2);

                        pointsData = SampleFile(_currentFile, PointsOnScreen);

                        Debug.Log(_currentFile + " has " + _totalLines + " lines");
                        break;
                    }
                }
            }
            catch (IOException e)
            {
                Debug.Log(e.StackTrace);
            }

            if ((pointsData != null) && (pointsData.Length > 0))
            {
                //string[] lines = pointsData.Split(new string[] { "\n", "\r\n", "\r" }, StringSplitOptions.RemoveEmptyEntries);
                DrawPointStrings(pointsData);
            }
            else
            {
                Debug.LogErrorFormat("Could not find file {0}!", filename);
            }

            _userSegments = new List <Segment>();
            _userSegments.Add(GenSegmentByUV(1f, 0.5f));
            RedrawCanvas();

            // Reset last zoom to default starting at 0.
            _lastZoom = 0;

            // Old version of extracting data points for segment tool.

            /*string pointsData = GameMgr.CurrentData();
             * if ((pointsData != null) && (pointsData.Length > 0))
             * {
             *  float x = 0;
             *  List<Vector2> points = new List<Vector2>();
             *  string[] lines = pointsData.Split('\n');
             *  foreach (string line in lines)
             *  {
             *      points.Add(new Vector2(x++, float.Parse(line)));
             *  }
             *  GenerateAndAssignVizTex2D(points);
             * }
             *
             * _userSegments = new List<Segment>();
             * _userSegments.Add(GenSegmentByUV(1f, 0.5f));
             * RedrawCanvas();*/
        }