Пример #1
0
        StarSystem CreateStarSystem(Vector2 position)
        {
            SystemType systemType = map.systemTypes.Find(GetSystemType).systemType;

            if (systemType == null)
            {
                systemType = map.systemTypes.Find((x) => x.systemType.useDefault).systemType;
            }

            GameObject systemObject = systemType.gameObjects.Find((x) => UnityEngine.Random.Range(0f, 1f) <= x.probability).gameObject;

            if (systemObject == null)
            {
                systemObject = systemType.gameObjects[0].gameObject;
            }
            systemObject = GameObject.Instantiate(systemObject);
            float size = UnityEngine.Random.Range(systemType.minSizeMultiplier, systemType.maxSizeMultiplier);

            systemObject.transform.GetChild(0).localScale = new Vector3(size, 1, size);

            string systemName = (starSystems.Count == 0 && systemType.names.Count > 0) ? systemType.names[0] : "System";

            foreach (StarSystem system in starSystems)
            {
                systemName = systemType.names.Find((x) => (x != system.Name));
                if (systemName == null)
                {
                    systemName = "System"; //TODO: replace with default names
                }
            }

            List <Planet> planets = new List <Planet>();

            for (int i = 0; i < UnityEngine.Random.Range(systemType.minPlanets, systemType.maxPlanets); i++)
            {
                PlanetType planet = systemType.planets.Find((x) => UnityEngine.Random.Range(0f, 1f) <= x.probability).planet;
                if (planet == null)
                {
                    planet = systemType.planets[0].planet;
                }
                planets.Add(new Planet(planet.name));
            }

            return(new StarSystem(systemName, systemObject, planets, position));
        }
Пример #2
0
            override public void OnInspectorGUI()
            {
                PlanetType planetType = (PlanetType)target;

                EditorUtility.SetDirty(planetType);

                EditorGUILayout.BeginVertical();

                generalSettings = EditorGUILayout.Foldout(generalSettings, "Planet General Settings", true);
                if (generalSettings)
                {
                    string storedPlanetTypeName = planetType.name;
                    planetType.name = EditorGUILayout.DelayedTextField("Type Name: ", planetType.name);
                    if (planetType.name != storedPlanetTypeName)
                    {
                        string assetPath = AssetDatabase.GetAssetPath(planetType.GetInstanceID());
                        AssetDatabase.RenameAsset(assetPath, planetType.name);
                        AssetDatabase.SaveAssets();
                    }
                }
            }