Example #1
0
    public static CelestialBody Create(FileInfo file)
    {
        CelestialBodyLoader loader = new CelestialBodyLoader();

        if (loader.Load(file))
        {
            UnityEngine.Object prefab = Resources.Load(CelestialBodyLoader.PrefabPath + loader.m_Name, typeof(GameObject));

            if (null != prefab)
            {
                GameObject gameObject = UnityEngine.Object.Instantiate(prefab) as GameObject;

                if (null != gameObject)
                {
                    gameObject.name = loader.m_Name;

                    if (loader.m_Type == "Planet")
                    {
                        CelestialPlanet newPlanet = gameObject.AddComponent <CelestialPlanet>();

                        if (null != newPlanet)
                        {
                            if (newPlanet.Initialize(loader))
                            {
                                return(newPlanet);
                            }
                        }
                    }
                    else if (loader.m_Type == "Ship")
                    {
                        CelestialShip newShip = gameObject.AddComponent <CelestialShip>();

                        if (null != newShip)
                        {
                            if (newShip.Initialize(loader))
                            {
                                return(newShip);
                            }
                        }
                    }
                    else if (loader.m_Type == "Moon")
                    {
                        CelestialMoon newMoon = gameObject.AddComponent <CelestialMoon>();

                        if (null != newMoon)
                        {
                            if (newMoon.Initialize(loader))
                            {
                                return(newMoon);
                            }
                        }
                    }
                }
            }
        }

        return(null);
    }
Example #2
0
    public override bool Initialize(CelestialBodyLoader loader)
    {
        if (base.Initialize(loader))
        {
            m_CelestialType = CelestialType.Moon;

            return(true);
        }

        return(false);
    }
Example #3
0
    public override bool Initialize(CelestialBodyLoader loader)
    {
        if (base.Initialize(loader))
        {
            List <float> floatList = null;

            if (false == loader.GetData(m_MeanLongitudeLabel, ref floatList))
            {
                Debug.LogError("Error");
                return(false);
            }
            m_MeanEquinoxData[(int)PlanetPositionUtility.OrbitalElements.MEAN_LONGITUDE_OF_PLANET].AddRange(floatList);

            if (false == loader.GetData(m_SemiMajorAxisOfOrbitLabel, ref floatList))
            {
                Debug.LogError("Error");
                return(false);
            }
            m_MeanEquinoxData[(int)PlanetPositionUtility.OrbitalElements.SEMI_MAJOR_AXIS_OF_ORBIT].AddRange(floatList);

            if (false == loader.GetData(m_EccentricityOfOrbitLabel, ref floatList))
            {
                Debug.LogError("Error");
                return(false);
            }
            m_MeanEquinoxData[(int)PlanetPositionUtility.OrbitalElements.ECCENTRICITY_OF_THE_ORBIT].AddRange(floatList);

            if (false == loader.GetData(m_InclinationOnPlaneOfEclipticLabel, ref floatList))
            {
                Debug.LogError("Error");
                return(false);
            }
            m_MeanEquinoxData[(int)PlanetPositionUtility.OrbitalElements.INCLINATION_ON_PLANE_OF_ECLIPTIC].AddRange(floatList);

            // ArgumentOfPerihelion (optional)
            if (loader.GetData(m_ArgumentOfPerihelionLabel, ref floatList))
            {
                m_MeanEquinoxData[(int)PlanetPositionUtility.OrbitalElements.ARGUMENT_OF_PERIHELION].AddRange(floatList);
            }

            // LongitudeOfAscendingNode (optional)
            if (loader.GetData(m_LongitudeOfAscendingNodeLabel, ref floatList))
            {
                m_MeanEquinoxData[(int)PlanetPositionUtility.OrbitalElements.LONGITUDE_OF_ASCENDING_NODE].AddRange(floatList);
            }

            m_CelestialType = CelestialType.Planet;

            return(true);
        }

        return(false);
    }
Example #4
0
    public virtual bool Initialize(CelestialBodyLoader loader)
    {
        // Has Orbit (optional)
        m_OrbitParentName = "";
        loader.GetData(m_OrbitFlagLabel, ref m_OrbitParentName);

        if (loader.m_Radius <= 0.0)
        {
            Debug.LogError("Error");
            return(false);
        }
        m_RadiusInKM = loader.m_Radius;

        // TODO: This is a sphere shaped calculation so will need to support other types eventually?
        // Initial scale is in game diameter (2 * radius)
        m_InitialScale = CelestialRadius * 2;

        Scale = 1;

        return(true);
    }