예제 #1
0
파일: MapManager.cs 프로젝트: XDKlein/forth
 bool GetSystemType(SystemTypeAndProbability systemTypes)
 {
     if (UnityEngine.Random.Range(0f, 1f) <= systemTypes.probability)
     {
         if (!systemTypes.systemType.useDefault)
         {
             foreach (StarSystem system in starSystems)
             {
                 if (systemTypes.systemType.names.Contains(system.Name))
                 {
                     return(false);
                 }
             }
         }
         return(true);
     }
     return(false);
 }
예제 #2
0
        override public void OnInspectorGUI()
        {
            MapType mapType = (MapType)target;

            EditorUtility.SetDirty(mapType);

            EditorGUILayout.BeginVertical();
            string storedName = mapType.name;

            mapType.name = EditorGUILayout.DelayedTextField("Map Type Name: ", mapType.name);
            if (mapType.name != storedName)
            {
                string assetPath = AssetDatabase.GetAssetPath(mapType.GetInstanceID());
                AssetDatabase.RenameAsset(assetPath, mapType.name);
                AssetDatabase.SaveAssets();
            }

            generalSettings = EditorGUILayout.Foldout(generalSettings, "General Map Settings", true);
            if (generalSettings)
            {
                EditorGUI.indentLevel++;
                mapType.size = EditorGUILayout.Vector2Field("Map Size: ", mapType.size);
                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.Space(); EditorGUILayout.Space(); EditorGUILayout.Space();
                GUILayout.Label("Stars: ");
                EditorGUIUtility.labelWidth = 60f;
                mapType.minSystems          = EditorGUILayout.IntField("Min: ", mapType.minSystems);
                mapType.maxSystems          = EditorGUILayout.IntField("Max: ", mapType.maxSystems);
                EditorGUILayout.EndHorizontal();

                EditorGUILayout.Space();
                EditorGUIUtility.labelWidth = 120f;
                mapType.template            = (Texture2D)EditorGUILayout.ObjectField("Map Texture: ", mapType.template, typeof(Texture2D), false);
                EditorGUI.indentLevel--;
            }

            systemTypesSettings = EditorGUILayout.Foldout(systemTypesSettings, "System Types Settings", true);
            if (systemTypesSettings)
            {
                EditorGUI.indentLevel++;
                int objectsCount = Mathf.Max(0, EditorGUILayout.DelayedIntField("Size: ", mapType.systemTypes.Count));
                while (objectsCount < mapType.systemTypes.Count)
                {
                    mapType.systemTypes.RemoveAt(mapType.systemTypes.Count - 1);
                }
                while (objectsCount > mapType.systemTypes.Count)
                {
                    mapType.systemTypes.Add(new SystemTypeAndProbability());
                }
                EditorGUILayout.BeginVertical();
                EditorGUI.indentLevel++;

                if (objectsCount > 0)
                {
                    EditorGUILayout.BeginHorizontal();
                    EditorGUILayout.Space();
                    GUILayout.Label("System Type");
                    GUILayout.Label("Probability");
                    EditorGUILayout.EndHorizontal();
                }
                for (int i = 0; i < mapType.systemTypes.Count; i++)
                {
                    SystemTypeAndProbability structure = mapType.systemTypes[i];
                    EditorGUILayout.BeginHorizontal();
                    EditorGUILayout.Space();
                    structure.systemType  = (SystemType)EditorGUILayout.ObjectField(mapType.systemTypes[i].systemType, typeof(SystemType), false);
                    structure.probability = EditorGUILayout.Slider(mapType.systemTypes[i].probability, 0f, 1f);
                    EditorGUILayout.EndHorizontal();
                    mapType.systemTypes[i] = structure;
                }
                EditorGUI.indentLevel--;
                EditorGUILayout.EndVertical();
            }
            if (GUILayout.Button("Save Object"))
            {
                mapType.systemTypes.Sort((x, y) => y.probability.CompareTo(x.probability));

                string assetPath = AssetDatabase.GetAssetPath(mapType.GetInstanceID());
                AssetDatabase.RenameAsset(assetPath, mapType.name);
                AssetDatabase.SaveAssets();
            }
            EditorGUILayout.EndVertical();
        }