Пример #1
0
    public void readStaticShips()
    {
        // Create an instance of StreamReader to read from a file. Same dir as file
        // The using statement also closes the StreamReader.
        using (StreamReader sr = new StreamReader("ais_static_messages_examples.json"))
        //using (StreamReader sr = new StreamReader("titan only.json"))
        //using (StreamReader sr = new StreamReader("ais_dynamic_messages_examples.json"))
        {
            line = sr.ReadLine();
            line = sr.ReadLine();
            // Read and display lines from the file until
            // the end of the file is reached.

            String name = "", MMSI = "", callsign = "", timestamp = "", shipType = "", bowToPosition = "",
                   sternToPosition = "", portToPosition = "", starboardToPosition = "", destination = "";

            while ((line = sr.ReadLine()) != null)
            {
                line = sr.ReadLine();

                timestamp = sr.ReadLine().Trim();
                timestamp = Regex.Replace(timestamp, "[\":, ]", "").Substring(27);
                for (int i = 0; i < 2; i++)
                {
                    line = sr.ReadLine();
                }
                MMSI = sr.ReadLine().Trim();
                MMSI = Regex.Replace(MMSI, "[\":, ]", "").Substring(4);
                for (int i = 0; i < 2; i++)
                {
                    line = sr.ReadLine();
                }
                callsign = sr.ReadLine().Trim();
                callsign = Regex.Replace(callsign, "[\":, ]", "").Substring(10);

                name = sr.ReadLine().Trim();
                name = Regex.Replace(name, "[\":, ]", "").Substring(4); //remove punctuation and spaces

                shipType = sr.ReadLine().Trim();
                shipType = Regex.Replace(shipType, "[\":, ]", "").Substring(22);

                bowToPosition = sr.ReadLine().Trim();
                bowToPosition = Regex.Replace(bowToPosition, "[\":, ]", "").Substring(20);

                sternToPosition = sr.ReadLine().Trim();
                sternToPosition = Regex.Replace(sternToPosition, "[\":, ]", "").Substring(22);

                portToPosition = sr.ReadLine().Trim();
                portToPosition = Regex.Replace(portToPosition, "[\":, ]", "").Substring(21);

                starboardToPosition = sr.ReadLine().Trim();
                starboardToPosition = Regex.Replace(starboardToPosition, "[\":, ]", "").Substring(26);
                for (int i = 0; i < 2; i++)
                {
                    line = sr.ReadLine();
                }
                destination = sr.ReadLine().Trim();
                destination = Regex.Replace(destination, "[\":, ]", "").Substring(11);
                for (int i = 0; i < 4; i++)
                {
                    line = sr.ReadLine();
                }

                //sAIS = new staticAIS(name, MMSI, callsign, timestamp, shipType, bowToPosition,
                //sternToPosition, portToPosition, starboardToPosition, destination);
                sAIS = new staticAIS();
                //if (!Shiplist.Contains(sAIS.name))
                if (!StaticShipNamelist.Any(p => p.name == sAIS.name))
                {
                    StaticShipNamelist.Add(sAIS);
                }
                //Console.WriteLine(sAIS);
            }

            StaticShipNamelist.ForEach(Debug.Log);

            foreach (staticAIS i in StaticShipNamelist)
            {
                Debug.Log("Name: " + i.name + " BowPosition: " + i.bow_to_position_unit);
                instantiateNewShip(i);
            }

            foreach (GameObject i in ships)
            {
                i.name = "WHY";
                //i.GetComponent<TextMesh>().text = "this works";
            }

            Debug.Log("Boat Count: " + StaticShipNamelist.Count);
            //return sAIS;
        }
    }
Пример #2
0
    private void instantiateNewShip(staticAIS i)
    {
        //Instantiate ship (cube) and get a ref to it in newObj

        pos          = new Vector3(i.bow_to_position_unit, 1, i.bow_to_position_unit);
        newShip      = (GameObject)Instantiate(obj, pos, rotation);
        newShip.name = i.name;
        newShip.transform.localScale += new Vector3(4, 4, 4);
        //Instantiate text and get a red to it in newTextObj
        //newTextObj = (GameObject)Instantiate(textObj, pos + offset, transform.rotation);
        newTextObj = (GameObject)Instantiate(textObj, pos + offset, transform.rotation);

        //sets textObj as child of newObj in hierachy
        newTextObj.transform.parent = newShip.transform;

        /*
         *  TextController.cpp seems redundant at the moment since you can just apply the newObj (ship)'s position to the text
         */
        /*
         *  get a ref of the instance's TextController.cpp in tc (short for TextController)
         *  assign target to follow -> newObj
         *  assign newTextObj's offset from its target so no overlap
         */
        tc        = newTextObj.GetComponent <TextController>();
        tc.target = newShip;
        tc.offset = offset;

        //newTextObj.AddComponent<CameraFacing>();
        //change text code here
        //newTextObj.GetComponent<TextMesh>().text = names[index];
        newTextObj.GetComponent <TextMesh>().fontSize = 60;
        newTextObj.GetComponent <TextMesh>().text     = i.name + '\n' + "VELOCITY: 0";

        textObjects.Add(tc);
        ships.Add(newShip);

        //lat = lat + 2500;
        //lon = lon + 5000;

        /*
         * lat = lat * radians;
         * lon = lon * radians;
         * convertGPS(lat, lon);
         * convertGPS2(lat, lon);
         *
         * //latitude = 41.145556;  (φ)
         * //longitude = -73.995;    (λ)
         *
         * // get x value
         * float x = (lon + 180) * (mapWidth / 360);
         *
         * // convert from degrees to radians
         * float latRad = lat * radians;
         *
         * // get y value
         * float mercN = Math.Log(Math.Tan((Math.PI / 4) + (latRad / 2))).ToFloat();
         * float y = (mapHeight / 2) - (mapWidth * mercN / (2 * Math.PI)).ToFloat();
         */
        //pos = Quaternion.AngleAxis(lon.ToFloat(), -Vector3.up) * Quaternion.AngleAxis(lat.ToFloat(), -Vector3.right) * new Vector3(0, 0, 1);

        // move marker to position
    }