コード例 #1
0
        private static void parseBoundaryData()
        {
            GameObject collisionRoot = new GameObject("CollisionRoot");

            collisionRoot.transform.position = Vector3.zero;
            collisionRoot.transform.rotation = Quaternion.identity;

            GameObject borderRoot = new GameObject("BordernRoot");

            borderRoot.transform.position = Vector3.zero;
            borderRoot.transform.rotation = Quaternion.identity;

            TextAsset bordersCSV = Resources.Load("Stardata/boundaries") as TextAsset;

            if (bordersCSV == null)
            {
                Debug.LogError("could not load border csv.");
                return;
            }

            string[] lines = bordersCSV.ToString().Split('\n');

            List <Vector2> borderPoints         = new List <Vector2>();
            int            currentAsterismIndex = -1;

            for (int i = 0; i < lines.Length; i++)
            {
                string   line   = lines[i];
                string[] fields = line.Split(',');

                if (fields.Length < 4)
                {
                    Debug.Log("incompleteLine: " + line);
                    continue;
                }

                string abreviation       = fields[2];
                string constellationName = m_abrevLookup[abreviation];

                if (currentAsterismIndex == -1 || constellationName != AsterismData[currentAsterismIndex].name)
                {
                    // Store vertecies from last asterism parsed.
                    if (currentAsterismIndex != -1 && borderPoints != null)
                    {
                        Asterism  currentAsterism = AsterismData[currentAsterismIndex];
                        Vector2[] border          = borderPoints.ToArray();

                        Vector3[] lineVerticies = new Vector3[border.Length + 1];
                        coordsToThreeSpace(border).CopyTo(lineVerticies, 1);
                        lineVerticies[0] = lineVerticies[lineVerticies.Length - 1];

                        if (m_borderLineMaterial == null)
                        {
                            m_borderLineMaterial = Resources.Load("Lines/LineMat") as Material;
                        }

                        LineObject borderLine = LineObject.LineFactory(lineVerticies, 5.0f, AsterismDrawer.Target, m_borderLineMaterial, true);
                        borderLine.transform.parent = borderRoot.transform;
                        currentAsterism.borderArt   = borderLine;

                        Mesh       newMesh = meshFromBorders(border);
                        GameObject prefab  = Resources.Load("baseObj") as GameObject;
                        GameObject go      = GameObject.Instantiate(prefab, Vector3.zero, Quaternion.identity) as GameObject;
                        go.transform.GetComponent <MeshFilter>().mesh            = newMesh;
                        go.transform.GetComponent <MeshCollider>().sharedMesh    = newMesh;
                        go.transform.GetComponent <AsterismReference>().Asterism = currentAsterism;
                        go.transform.GetComponent <AsterismReference>().index    = currentAsterismIndex;
                        go.name             = "Collision_" + currentAsterism.name;
                        go.transform.parent = collisionRoot.transform;
                        AsterismData[currentAsterismIndex] = currentAsterism;
                    }

                    // Grab the next asterism being parsed.
                    int indexOfAsterism = asterismIndexFromName(constellationName);
                    if (indexOfAsterism == -1)
                    {
                        currentAsterismIndex = -1;
//            Debug.LogError("Parsing border of unknown constellation: " + constellationName);
                        continue;
                    }
                    currentAsterismIndex = indexOfAsterism;
                    borderPoints         = new List <Vector2>();
                }

                float xComponent = 0.0f;
                float yComponent = 0.0f;

                bool xParsed = float.TryParse(fields[0], out xComponent);
                bool yParsed = float.TryParse(fields[1], out yComponent);

                if (!xParsed || !yParsed)
                {
                    Debug.LogError("Could not parse x and y coords");
                    continue;
                }

                Vector2 newCoord = new Vector2(xComponent, yComponent);

                borderPoints.Add(newCoord);

                // Make sure to store the last point.
                if (i == lines.Length - 1)
                {
                    if (i < AsterismData.Length)
                    {
                        Asterism currentAsterism = AsterismData[i];
                        currentAsterism.borders = borderPoints.ToArray();
                        AsterismData[i]         = currentAsterism;
                    }
                }
            }
        }
コード例 #2
0
        public static void GetAsterismLines(ref StarData[] starData)
        {
            bool initilized = true;

            for (int i = 0; i < AsterismParser.AsterismData.Length; i++)
            {
                if (!initilized)
                {
                    break;
                }
                Asterism  asterism      = AsterismParser.AsterismData[i];
                Vector3[] positionArray = new Vector3[asterism.HD_ids.Length];
                for (int j = 0; j < asterism.HD_ids.Length; j++)
                {
                    uint hdid = asterism.HD_ids[j];

                    try {
                        StarData   star    = starData[StarParser.HD_idToIndex[hdid]];
                        GameObject starObj = star.GameObjectRepresentation;
                        if (starObj != null)
                        {
                            if (starObj.transform.position == Vector3.zero)
                            {
                                initilized = false;
                                break;
                            }

                            positionArray[j] = starObj.transform.position;
                        }
                        else
                        {
                            Debug.LogWarning("Ummm...this star is missing a game object. Skipping the asterism: " + asterism.name);
                        }
                    }
                    catch (KeyNotFoundException e) {
                        Debug.Log(e.Message);
                        Debug.LogWarning("Ummm...this star is missing: " + hdid + ". Skipping the asterism: " + asterism.name);
                        continue;
                    }
                }

                if (!initilized)
                {
                    return;
                }

                if (asterism.lineArt == null)
                {
                    if (m_lineMat == null)
                    {
                        m_lineMat = Resources.Load("Lines/LineMat") as Material;
                    }

                    if (m_asterismLineRoot == null)
                    {
                        m_asterismLineRoot = new GameObject("AsterismLineRoot");
                    }

                    LineObject asterismLines = LineObject.LineFactory(positionArray, 3.0f, m_target, m_lineMat);

                    asterismLines.gameObject.name = asterism.name + "_line";

                    asterismLines.transform.parent = m_asterismLineRoot.transform;

                    asterism.lineArt = asterismLines;
                }
                else
                {
                    asterism.lineArt.Points = positionArray;
                }
                AsterismParser.AsterismData[i] = asterism;
            }

            setAsterismColor(m_asterismColor);
        }