Пример #1
0
    private void LoadMap()
    {
        mapSaveName = loadMap.name;
        objectsArray.Clear();


        string folderName = "Level_" + mapSaveName;
        string folderPath = "Assets/Resources/Maps/" + folderName;
        string mapName    = folderPath + "/" + mapSaveName + ".asset";

        loadMap  = AssetDatabase.LoadAssetAtPath <MapSO>(mapName);
        width    = loadMap.width;
        height   = loadMap.height;
        mapArray = new GameObject[loadMap.width, loadMap.height];
        MapLoader.SpawnMap(loadMap, (GameObject tile, int x, int z) => {
            mapArray[x, z] = tile;
        });
        startTile = mapArray[(int)loadMap.startTile.x, (int)loadMap.startTile.z].gameObject;

        if (!objectsArray.ContainsKey("Enemy"))
        {
            objectsArray.Add("Enemy", new List <Vector3>());
        }

        GameObject[] enemies = GameObject.FindGameObjectsWithTag("Enemy");
        foreach (GameObject go in enemies)
        {
            objectsArray["Enemy"].Add(go.transform.position);
        }
    }
Пример #2
0
    public static void SpawnMap(MapSO loadMap, Action <GameObject, int, int> onTileSpawn = null)
    {
        RegenerateParents();
        for (int x = 0; x < loadMap.width; x++)
        {
            for (int z = 0; z < loadMap.height; z++)
            {
                GameObject tile = (GameObject)GameObject.Instantiate(Resources.Load("Prefab/FloorTile"), new Vector3(x, 0, z), Quaternion.Euler(new Vector3(90, 0, 0)));
                tile.transform.SetParent(floorParent.transform);
                tile.GetComponent <FloorTile>().IsWalkable = loadMap.map[z * loadMap.width + x];

                onTileSpawn?.Invoke(tile, x, z);
            }
        }

        //Enemies

        /* var enemyFiles = Resources.LoadAll<EnemyPatrolSO>("Maps/Level_" + loadMap.name + "/Enemies");
         * for(int i=0; i< enemyFiles.Length; i++)
         * {
         *   if (enemyFiles[i].name.Contains("meta")) continue;
         *
         *   Vector3 first = enemyFiles[i].patrolPoint[0];
         *   GameObject enemy = (GameObject)GameObject.Instantiate(Resources.Load("Prefab/Enemy"), first + Vector3.up * 0.6f, Quaternion.Euler(0,enemyFiles[i].rotations[0],0));
         *   enemy.name = "Enemy_" + i;
         *   enemy.transform.SetParent(enemyParent.transform);
         *   enemy.GetComponent<Enemy>().patrolSO = enemyFiles[i];
         * }*/
    }
Пример #3
0
        MapSO CreateColorMapSO(Texture2D colorMap)
        {
            var map = MapSO.CreateInstance <MapSO> ();

            map.CreateMap(MapSO.MapDepth.RGBA, colorMap);
            return(map);
        }
Пример #4
0
        MapSO CreateMapSO(Texture2D heightMap)
        {
            var map = MapSO.CreateInstance <MapSO> ();

            map.CreateMap(MapSO.MapDepth.Greyscale, heightMap);
            return(map);
        }
Пример #5
0
        protected override void SetupPQS(PQS pqs)
        {
            //disable easter eggs and color map
            DisableUnneededObjects(pqs);

            //change out heightmap for new one
            var height = pqs.GetPQSMod <PQSMod_VertexHeightMap> ();

            height.heightMap = MapSO.CreateInstance <MapSO> ();

            var heightMap = Utils.LoadTexture("Height/Duna_height.png");

            height.heightMap.CreateMap(MapSO.MapDepth.Greyscale, heightMap);
            height.scaleDeformityByRadius = false;
            height.heightMapDeformity     = 8000.0;
            GameObject.Destroy(heightMap);

            //new colormap
            var colorMapBlend = pqs.GetPQSMod <PQSMod_VertexColorMapBlend> ();

            colorMapBlend.modEnabled = false;
            var colorNoise = pqs.GetPQSMod <PQSMod_VertexSimplexNoiseColor> ();

            colorNoise.modEnabled = false;

            var land = pqs.GetPQSMod <PQSLandControl> ();

            land.createScatter = false;
            land.createColors  = false;

            var _LandClass  = pqs.transform.FindChild("_LandClass").gameObject;
            var heightColor = _LandClass.AddComponent <PQSMod_HeightColorRamp> ();

            heightColor.modEnabled = true;
            //just before the original color map, which is now disabled
            heightColor.order  = 9999990;
            heightColor.sphere = pqs;

            //new color ramp
            var ramp = new PQSMod_HeightColorRamp.ColorRamp();

            ramp.Add(Utils.Color(149, 85, 58), Utils.Color(122, 58, 30), -100f);                                //lowlands
            ramp.Add(Utils.Color(149, 85, 58), Utils.Color(122, 58, 30), 200f);                                 //end of lowlands
            ramp.Add(Utils.Color(192, 119, 87), Utils.Color(178, 79, 37), 1000f);                               //fade into midlands
            ramp.Add(Utils.Color(192, 119, 87), Utils.Color(178, 79, 37), 2100f);                               //end of midlands
            ramp.Add(Utils.Color(215, 170, 150), Utils.Color(220, 150, 120), 3000f);                            //fade into highlands
            ramp.Add(new Color(0.9f, 0.9f, 0.9f), new Color(0.75f, 0.75f, 0.75f), 3200f);                       //sharp start of snowlands
            ramp.Add(new Color(0.9f, 0.9f, 0.9f), new Color(0.75f, 0.75f, 0.75f), 5750f);                       //snowlands
            ramp.Add(new Color(0.87f, 0.87f, 0.87f), new Color(0.8f, 0.8f, 0.85f), 6000f);                      //sharp start of veryhighlands
            ramp.Add(new Color(0.87f, 0.87f, 0.87f), new Color(0.8f, 0.8f, 0.85f), 100000f);                    //veryhighlands go to the top

            heightColor.Ramp          = ramp;
            heightColor.simplex       = new Simplex(555, 5, 0.5, 5);
            heightColor.BaseColorBias = 0.2f;
            heightColor.OnSetup();

            //rebuild sphere
            pqs.RebuildSphere();
        }
Пример #6
0
 private void GenerateMap()
 {
     MapLoader.RegenerateParents();
     objectsArray.Clear();
     mapSaveName = "";
     loadMap     = null;
     mapArray    = new GameObject[width, height];
     MapLoader.SpawnMap(width, height, (GameObject tile, int x, int z) => {
         mapArray[x, z] = tile;
     });
 }
Пример #7
0
        protected override void SetupPQS(PQS pqs)
        {
            //new heightmap
            var height = pqs.GetPQSMod <PQSMod_VertexHeightMap> ();

            height.heightMap          = MapSO.CreateInstance <MapSO> ();
            height.heightMapDeformity = 20000;
            var heightMap = Utils.LoadTexture("Height/Moho_height.png");

            height.heightMap.CreateMap(MapSO.MapDepth.Greyscale, heightMap);
            GameObject.Destroy(heightMap);

            //setup fine details
            var simplexAbsolute = pqs.GetPQSMod <PQSMod_VertexSimplexHeightAbsolute> ();

            simplexAbsolute.deformity = 100;
            var simplex = pqs.GetPQSMod <PQSMod_VertexSimplexHeight> ();

            simplex.modEnabled = false;


            //remove old colormap
            var noiseColor = pqs.GetPQSMod <PQSMod_VertexSimplexNoiseColor> ();

            noiseColor.modEnabled = false;
            var heightColor = pqs.GetPQSMod <PQSMod_HeightColorMap> ();

            heightColor.modEnabled = false;

            var _Color    = pqs.transform.FindChild("_Color").gameObject;
            var colorRamp = _Color.AddComponent <PQSMod_HeightColorRamp> ();

            var ramp = new PQSMod_HeightColorRamp.ColorRamp();

            ramp.Add(Utils.Color(101, 48, 37), Utils.Color(104, 65, 58), -100f);
            ramp.Add(Utils.Color(118, 40, 25), Utils.Color(129, 64, 50), 3900f);
            ramp.Add(Utils.Color(155, 123, 105), Utils.Color(121, 102, 91), 13000f);
            ramp.Add(Utils.Color(90, 69, 57), Utils.Color(95, 79, 70), 17000f);
            ramp.Add(Utils.Color(115, 105, 100), Utils.Color(152, 148, 145), 20000f);
            ramp.Add(Utils.Color(115, 105, 100), Utils.Color(152, 148, 145), 100000f);

            //TODO: make ramp

            colorRamp.Ramp          = ramp;
            colorRamp.simplex       = new Simplex(666, 6, 0.6, 6);       //>:D
            colorRamp.BaseColorBias = 0.1f;
            colorRamp.modEnabled    = true;
            colorRamp.order         = 202;
            colorRamp.sphere        = pqs;

            pqs.RebuildSphere();
        }
Пример #8
0
            // Function taken from https://github.com/Kopernicus/pqsmods-standalone/blob/master/KSP/MapSO.cs L340
            public static BilinearCoords ConstructBilinearCoords(Double x, Double y, MapSO heightMap)
            {
                // Create the struct
                BilinearCoords coords = new BilinearCoords();

                // Floor
                x = x - Math.Truncate(x);
                y = y - Math.Truncate(y);
                if (x < 0)
                {
                    x = 1.0 + x;
                }
                if (y < 0)
                {
                    y = -y;
                }

                // X to U
                coords.x = x * heightMap.Width;
                if (coords.x >= heightMap.Width)
                {
                    coords.x -= heightMap.Width;
                }
                coords.xFloor   = (Int32)Math.Floor(coords.x);
                coords.xCeiling = (Int32)Math.Ceiling(coords.x);
                coords.u        = (Single)(coords.x - Math.Truncate(coords.x));
                if (coords.xCeiling >= heightMap.Width)
                {
                    coords.xCeiling -= heightMap.Width;
                }

                // Y to V
                coords.y = y * heightMap.Height;
                if (coords.y >= heightMap.Height)
                {
                    coords.y = heightMap.Height - 1 - (coords.y - heightMap.Height);
                }
                coords.yFloor   = (Int32)Math.Floor(coords.y);
                coords.yCeiling = (Int32)Math.Ceiling(coords.y);
                coords.v        = (Single)(coords.y - Math.Truncate(coords.y));
                if (coords.yCeiling >= heightMap.Height)
                {
                    coords.yCeiling = heightMap.Height - 1 - (coords.yCeiling - heightMap.Height);
                }

                // We're done
                return(coords);
            }
Пример #9
0
        protected override void SetupPQS(PQS pqs)
        {
            //new heightmap
            var height = pqs.GetPQSMod <PQSMod_VertexHeightMap> ();

            height.heightMap = MapSO.CreateInstance <MapSO> ();
            var heightMap = Utils.LoadTexture("Height/Laythe_height.png");

            height.heightMap.CreateMap(MapSO.MapDepth.Greyscale, heightMap);
            GameObject.Destroy(heightMap);

            //all that cool stuff
            SetupLaythe(pqs);

            //rebuild sphere
            pqs.RebuildSphere();
        }
        static public void Button_Select(int i)
        {
            List <string> FileNames = new List <string>();

            DirectoryInfo directory = new DirectoryInfo("GameInfo/KittopiaSpace/Textures/" + PlanetName + "/PQS/");
            var           files     = directory.GetFiles("*.png");

            foreach (FileInfo f in files)
            {
                FileNames.Add(f.Name);
            }
            FileNames.Add("Filler");

            Texture2D texture = Utils.LoadTexture("GameInfo/KittopiaSpace/Textures/" + PlanetName + "/PQS/" + FileNames[i]);

            ReturnedMapSo = (MapSO)ScriptableObject.CreateInstance(typeof(MapSO));
            ReturnedMapSo.CreateMap(MapSO.MapDepth.RGBA, texture);
        }
Пример #11
0
            private static float SingleSample(Int32 x, Int32 y, MapSO heightMap, bool bits24)
            {
                // Get the Color, not the Float-Value from the Map
                Color32 c = heightMap.GetPixelColor32(x, y);

                // Get the height data from the terrain
                float height = 0;

                if (bits24)
                {
                    height = (float)((int)c.b | ((int)c.g << 8) | ((int)c.r << 16)) / (float)0x00FFFFFF;
                }
                else
                {
                    height = (float)((int)c.b | ((int)c.g << 8)) / (float)0xFFFF;
                }

                return(height);
            }
Пример #12
0
            public static float SampleHeightmap16(Double u, Double v, MapSO heightMap, bool bits24)
            {
                if (heightMap == null || !heightMap.IsCompiled)
                {
                    return(0);
                }
                BilinearCoords coords = VertexHeightMap16.ConstructBilinearCoords(u, v, heightMap);

                return(Mathf.Lerp(
                           Mathf.Lerp(
                               SingleSample(coords.xFloor, coords.yFloor, heightMap, bits24),
                               SingleSample(coords.xCeiling, coords.yFloor, heightMap, bits24),
                               coords.u),
                           Mathf.Lerp(
                               SingleSample(coords.xFloor, coords.yCeiling, heightMap, bits24),
                               SingleSample(coords.xCeiling, coords.yCeiling, heightMap, bits24),
                               coords.u),
                           coords.v));
            }
Пример #13
0
    public void LoadMap()
    {
        currentMap = (MapSO)Resources.Load("Maps\\Level_" + mapLoad + "\\" + mapLoad);
        if (currentMap != null)
        {
            MapLoader.SpawnMap(currentMap, (GameObject tile, int x, int z) => {
                if (!tile.GetComponent <FloorTile>().IsWalkable)
                {
                    if (tile.transform.position.x != 0 && tile.transform.position.x != currentMap.width - 1 &&
                        tile.transform.position.z != 0 && tile.transform.position.z != currentMap.height - 1)
                    {
                        obstacles.Add(tile.transform.position);
                    }
                }

                if (x == currentMap.endTile.x && z == currentMap.endTile.z)
                {
                    tile.GetComponent <MeshRenderer>().material.color = Color.green;
                }
            });

            GameObject player = GameObject.FindGameObjectWithTag("Player");
            player.transform.position = new Vector3(currentMap.startTile.x, 0.6f, currentMap.startTile.z);
            // endTileVec2Pos = new Vector2(currentMap.endTile.x, currentMap.endTile.z);
        }
        Player.Instance.Init();

        MainCanvas.Instance.Init();
        var allEnemies = GameObject.FindGameObjectsWithTag("Enemy");

        navMeshSurface.BuildNavMesh();


        beserkCount  = int.Parse(beserkField.text);
        cowardCount  = int.Parse(cowardField.text);
        soldierCount = int.Parse(soldierField.text);

        healthPacksCount = int.Parse(healthPackField.text);
        ammoboxCount     = int.Parse(ammoboxField.text);

        beserkCount      = Mathf.Clamp(beserkCount, 0, 3);
        soldierCount     = Mathf.Clamp(soldierCount, 0, 3);
        cowardCount      = Mathf.Clamp(cowardCount, 0, 3);
        healthPacksCount = Mathf.Clamp(healthPacksCount, 0, 3);
        ammoboxCount     = Mathf.Clamp(ammoboxCount, 0, 3);


        List <GameObject> activeEnemies = new List <GameObject>();

        for (int i = 0; i < 3; i++)
        {
            bool val;
            val = i < beserkCount;
            beserks[i].SetActive(val);
            if (val)
            {
                activeEnemies.Add(beserks[i]);
            }

            val = i < soldierCount;
            soldiers[i].SetActive(val);
            if (val)
            {
                activeEnemies.Add(soldiers[i]);
            }

            val = i < cowardCount;
            cowards[i].SetActive(val);
            if (val)
            {
                activeEnemies.Add(cowards[i]);
            }
        }

        foreach (GameObject g in activeEnemies)
        {
            g.GetComponent <Enemy>().Init();
        }

        GameObject[] allHP = GameObject.FindGameObjectsWithTag("Healthpack");
        GameObject[] allAB = GameObject.FindGameObjectsWithTag("AmmoBox");
        for (int i = 0; i < 3; i++)
        {
            if (i < ammoboxCount)
            {
                allAB[i].SetActive(true);
            }
            else
            {
                allAB[i].SetActive(false);
            }

            if (i < healthPacksCount)
            {
                allHP[i].SetActive(true);
            }
            else
            {
                allHP[i].SetActive(false);
            }
        }

        menuPanel.SetActive(false);
    }
Пример #14
0
    // Called to draw the MapEditor windows.
    private void OnGUI()
    {
        active = true;
        EditorGUILayout.BeginHorizontal();
        width  = EditorGUILayout.IntField("Width", width);
        height = EditorGUILayout.IntField("Height", height);

        EditorGUILayout.EndHorizontal();
        if (GUILayout.Button("Generate map"))
        {
            GenerateMap();
        }
        EditorGUILayout.BeginHorizontal();
        GUILayout.Label("Place tile");
        objectType = EditorGUILayout.Popup(objectType, Enum.GetNames(typeof(PlacebleObjects)));
        EditorGUILayout.EndHorizontal();

        EditorGUILayout.BeginHorizontal();
        if (GUILayout.Button("Save map"))
        {
            if (mapSaveName != "")
            {
                SaveMap();
            }
        }
        mapSaveName = EditorGUILayout.TextField(mapSaveName);
        EditorGUILayout.EndHorizontal();

        EditorGUILayout.BeginHorizontal();
        if (GUILayout.Button("Load map"))
        {
            int controlID = GUIUtility.GetControlID(FocusType.Passive);
            EditorGUIUtility.ShowObjectPicker <MapSO>(loadMap, false, "", controlID);
            loadedClicked = true;
        }

        EditorGUILayout.EndHorizontal();


        if (Event.current.commandName == "ObjectSelectorClosed")
        {
            loadMap = (MapSO)EditorGUIUtility.GetObjectPickerObject();
            if (loadMap != null && loadedClicked)
            {
                loadedClicked = false;

                LoadMap();
            }
        }

        foldouts[(int)FoldoutsName.QUICK_ACTIONS] = EditorGUILayout.Foldout(foldouts[(int)FoldoutsName.QUICK_ACTIONS], "Actions");
        if (foldouts[(int)FoldoutsName.QUICK_ACTIONS])
        {
            if (GUILayout.Button("Flatten"))
            {
                for (int x = 0; x < width; x++)
                {
                    for (int z = 0; z < height; z++)
                    {
                        mapArray[x, z].GetComponent <FloorTile>().IsWalkable = true;
                    }
                }
            }
            if (GUILayout.Button("Outer wall"))
            {
                for (int x = 0; x < width; x++)
                {
                    for (int z = 0; z < height; z++)
                    {
                        if (x == 0 || x == width - 1 || z == 0 || z == height - 1)
                        {
                            mapArray[x, z].GetComponent <FloorTile>().IsWalkable = false;
                        }
                    }
                }
            }
        }
    }
Пример #15
0
    private void SaveMap()
    {
        if (startTile == null)
        {
            Debug.LogError("Start tile  required to save map1!");
            return;
        }

        string folderName = "Level_" + mapSaveName;
        string folderPath = "Assets/Resources/Maps/" + folderName;
        string mapName    = folderPath + "/" + mapSaveName + ".asset";

        if (!AssetDatabase.IsValidFolder(folderPath))
        {
            AssetDatabase.CreateFolder("Assets/Resources/Maps", folderName);
        }

        MapSO mapso = AssetDatabase.LoadAssetAtPath <MapSO>(mapName);

        if (mapso == null)
        {
            mapso = ScriptableObject.CreateInstance <MapSO>();
            AssetDatabase.CreateAsset(mapso, mapName);
        }

        mapso.startTile = startTile.transform.position;
        mapso.width     = width;
        mapso.height    = height;
        mapso.map       = new bool[width * height];
        for (int x = 0; x < width; x++)
        {
            for (int z = 0; z < height; z++)
            {
                mapso.map[z * height + x] = mapArray[x, z].GetComponent <FloorTile>().IsWalkable;
            }
        }

        /*  GameObject[] enemies = GameObject.FindGameObjectsWithTag("Enemy");
         *
         * mapso.enemyCount = enemies.Length;
         *
         * if(!Directory.Exists(folderPath + "/Enemies"))
         *    Directory.CreateDirectory(folderPath + "/Enemies");
         *
         * List<string> savedFiles = new List<string>();
         * if (enemies.Length > 0)
         * {
         *    int counter = 0;
         *     foreach(GameObject go in enemies)
         *     {
         *        //Check for existing SO
         *        EnemyPatrolSO enemySO = AssetDatabase.LoadAssetAtPath<EnemyPatrolSO>(folderPath + "/Enemies/" + "Enemy_" + counter + ".asset");
         *        if (enemySO == null)
         *        {
         *            enemySO = ScriptableObject.CreateInstance<EnemyPatrolSO>();
         *            enemySO.patrolPoint = new List<Vector3>();
         *            enemySO.times = new List<float>();
         *            enemySO.patrolPoint.Add(new Vector3(go.transform.position.x, 0.0f, go.transform.position.z));
         *            enemySO.times.Add(3);
         *            AssetDatabase.CreateAsset(enemySO, folderPath + "/Enemies/" + "Enemy_" + counter + ".asset");
         *        }
         *        savedFiles.Add(enemySO.name);
         *        counter++;
         *        go.GetComponent<Enemy>().patrolSO = enemySO;
         *        EditorUtility.SetDirty(enemySO);
         *        EditorUtility.SetDirty(go.GetComponent<Enemy>().patrolSO);
         *        AssetDatabase.SaveAssets();
         *        AssetDatabase.Refresh();
         *
         *    }
         * }
         */
        //Get all files in enemy folder

        /* string[] files = Directory.GetFiles(folderPath + "/Enemies");
         * foreach (string file in files)
         * {
         *   if (!savedFiles.Contains<string>(file))
         *   {
         *       if (File.Exists(file))
         *           File.Delete(file);
         *   }
         * }*/

        EditorUtility.SetDirty(mapso);
        AssetDatabase.SaveAssets();
        AssetDatabase.Refresh();
    }
 public override void CreateMap(MapSO.MapDepth depth, Texture2D tex)
 {
     base.CreateMap(depth, tex);
     isLoaded = true;
 }
 public void CreateMap(MapSO.MapDepth depth, string path, Texture2D tex)
 {
     mapPath = path;
     CreateMap(depth, tex);
 }
        public static void Button_Select( int i )
        {
            List<string> FileNames = new List<string>();

            DirectoryInfo directory = new DirectoryInfo( "GameInfo/KittopiaSpace/Textures/"+ PlanetName +"/PQS/" );
            var files = directory.GetFiles("*.png");
            foreach( FileInfo f in files )
            {
                FileNames.Add( f.Name );
            }
            FileNames.Add( "Filler" );

            Texture2D texture = Utils.LoadTexture( "GameInfo/KittopiaSpace/Textures/"+ PlanetName +"/PQS/" + FileNames[i] );

            ReturnedMapSo = (MapSO) ScriptableObject.CreateInstance(typeof (MapSO));
            ReturnedMapSo.CreateMap( MapSO.MapDepth.RGBA, texture );
        }
Пример #19
0
        protected override void SetupPQS(PQS pqs)
        {
            var dunaPQS = Utils.GetCelestialBody("Duna").pqsController;

            pqs.surfaceMaterial = new Material(dunaPQS.surfaceMaterial);

            var _LandClass = pqs.transform.FindChild("_LandClass").gameObject;

            //disable current colormap
            var noiseColor = pqs.GetPQSMod <PQSMod_VertexSimplexNoiseColor> ();

            noiseColor.modEnabled = false;
            var colorBlend = pqs.GetPQSMod <PQSMod_VertexColorMapBlend> ();

            colorBlend.modEnabled = false;
            var land = pqs.GetPQSMod <PQSLandControl> ();

            land.modEnabled = false;

            //add new colorRamp
            var colorRamp = _LandClass.AddComponent <PQSMod_HeightColorRamp> ();

            colorRamp.modEnabled = true;
            colorRamp.order      = 9999990;
            colorRamp.sphere     = pqs;

            var ramp = new PQSMod_HeightColorRamp.ColorRamp();

            ramp.Add(Utils.Color(235, 171, 74), Utils.Color(235, 171, 74), -5000f);                     //oceans
            ramp.Add(Utils.Color(235, 171, 74), Utils.Color(235, 171, 74), -50f);                       //end of oceans
            ramp.Add(Utils.Color(155, 135, 88), Utils.Color(175, 149, 87), -10f);                       //start of beaches
            ramp.Add(Utils.Color(155, 135, 88), Utils.Color(175, 149, 87), 100f);                       //end of beaches
            ramp.Add(Utils.Color(212, 171, 75), Utils.Color(189, 158, 86), 200f);                       //start of lowlands
            ramp.Add(Utils.Color(189, 158, 86), Utils.Color(155, 120, 60), 2000f);                      //fade into midlands
            ramp.Add(Utils.Color(155, 120, 60), Utils.Color(172, 139, 78), 5000f);                      //fade into highlands
            ramp.Add(Utils.Color(223, 189, 129), Utils.Color(220, 194, 149), 5500f);                    //quickly fade out to mountain tops
            ramp.Add(Utils.Color(220, 194, 149), Utils.Color(186, 184, 180), 20000f);                   //top of the curve

            colorRamp.Ramp          = ramp;
            colorRamp.BaseColorBias = 0.5f;
            colorRamp.simplex       = new Simplex(654, 6, 0.35, 4);
            colorRamp.OnSetup();

            //new heightmap
            var height = pqs.GetPQSMod <PQSMod_VertexHeightMap> ();

            height.scaleDeformityByRadius = false;
            height.heightMapOffset        = -500.0;
            height.heightMapDeformity     = 7000.0;

            height.heightMap = MapSO.CreateInstance <MapSO> ();

            var heightMap = Utils.LoadTexture("Height/Eve_height.png");

            height.heightMap.CreateMap(MapSO.MapDepth.Greyscale, heightMap);
            GameObject.Destroy(heightMap);

            //setup ocean
            PQS ocean = null;

            foreach (var child in pqs.ChildSpheres)
            {
                Log(child.gameObject.name);
                if (child.gameObject.name == "EveOcean")
                {
                    ocean = child;
                }
            }
            if (ocean != null)
            {
                Log("EveOcean found!");

                var OceanFX = ocean.transform.FindChild("OceanFX").gameObject;

                ocean.surfaceMaterial.color = Utils.Color(235, 171, 74);
                ocean.surfaceMaterial.SetColor("_ColorFromSpace", Utils.Color(235, 171, 74));
            }
        }
Пример #20
0
            /// <summary>
            /// Renders an editor for the object
            /// </summary>
            protected void RenderObject(Object @object)
            {
                // Null check
                if (@object == null)
                {
                    return;
                }

                // Get all parseable MemberInfos
                MemberInfo[] infos = @object.GetType().GetMembers()
                                     .Where(m => m.MemberType == MemberTypes.Field || m.MemberType == MemberTypes.Property)
                                     .Where(m => !(m as FieldInfo)?.IsLiteral ?? true)
                                     .Where(m => m is PropertyInfo ? (m as PropertyInfo).CanRead && (m as PropertyInfo).CanWrite : true)
                                     .ToArray();

                // Loop through all fields and display them
                foreach (MemberInfo info in infos)
                {
                    // Get the type and the value of the member
                    Type   FieldType = info.GetMemberType();
                    Object value     = info.GetValue(@object);

                    if (FieldType == typeof(String))
                    {
                        Label(info.Name); index--;
                        TextField(value.ToString(), v => info.SetValue(@object, v), new Rect(200, index * distance + 10, 170, 20));
                    }
                    else if (FieldType == typeof(Boolean))
                    {
                        Label(info.Name); index--;
                        TextField((Boolean)value, v => info.SetValue(@object, v), new Rect(200, index * distance + 10, 170, 20));
                    }
                    else if (FieldType == typeof(Int32))
                    {
                        Label(info.Name); index--;
                        TextField((Int32)value, v => info.SetValue(@object, v), new Rect(200, index * distance + 10, 170, 20));
                    }
                    else if (FieldType == typeof(Single))
                    {
                        Label(info.Name); index--;
                        TextField((Single)value, v => info.SetValue(@object, v), new Rect(200, index * distance + 10, 170, 20));
                    }
                    else if (FieldType == typeof(Double))
                    {
                        Label(info.Name); index--;
                        TextField((Double)value, v => info.SetValue(@object, v), new Rect(200, index * distance + 10, 170, 20));
                    }
                    else if (value is Enum)
                    {
                        Label(info.Name); index--;
                        Button(Localization.LOC_KITTOPIATECH_EDIT, () => {
                            UIController.Instance.SetEditedObject(KittopiaWindows.Enum, value, c => info.SetValue(@object, c));
                            UIController.Instance.EnableWindow(KittopiaWindows.Enum);
                        }, new Rect(200, index * distance + 10, 170, 20));
                    }
                    else if (FieldType == typeof(Color))
                    {
                        Label(info.Name); index--;
                        Button(Localization.LOC_KITTOPIATECH_EDIT_COLOR, () => {
                            UIController.Instance.SetEditedObject(KittopiaWindows.Color, (Color)value, c => info.SetValue(@object, c));
                            UIController.Instance.EnableWindow(KittopiaWindows.Color);
                        }, new Rect(200, index * distance + 10, 170, 20));
                    }
                    else if (FieldType == typeof(Vector3))
                    {
                        Label(info.Name); index--;
                        Vector3 value_ = (Vector3)value;
                        TextField(value_.x, f => { value_.x = f; info.SetValue(@object, value_); }, new Rect(200, index * distance + 10, 50, 20)); index--;
                        TextField(value_.y, f => { value_.y = f; info.SetValue(@object, value_); }, new Rect(260, index * distance + 10, 50, 20)); index--;
                        TextField(value_.z, f => { value_.z = f; info.SetValue(@object, value_); }, new Rect(320, index * distance + 10, 50, 20));
                    }
                    else if (FieldType == typeof(Vector3d))
                    {
                        Label(info.Name); index--;
                        Vector3d value_ = (Vector3d)value;
                        TextField(value_.x, f => { value_.x = f; info.SetValue(@object, value_); }, new Rect(200, index * distance + 10, 50, 20)); index--;
                        TextField(value_.y, f => { value_.y = f; info.SetValue(@object, value_); }, new Rect(260, index * distance + 10, 50, 20)); index--;
                        TextField(value_.z, f => { value_.z = f; info.SetValue(@object, value_); }, new Rect(320, index * distance + 10, 50, 20));
                    }
                    else if (FieldType == typeof(Vector2))
                    {
                        Label(info.Name); index--;
                        Vector2 value_ = (Vector2)value;
                        TextField(value_.x, f => { value_.x = f; info.SetValue(@object, value_); }, new Rect(200, index * distance + 10, 50, 20)); index--;
                        TextField(value_.y, f => { value_.y = f; info.SetValue(@object, value_); }, new Rect(285, index * distance + 10, 50, 20));
                    }
                    else if (FieldType == typeof(Vector2d))
                    {
                        Label(info.Name); index--;
                        Vector2d value_ = (Vector2d)value;
                        TextField(value_.x, f => { value_.x = f; info.SetValue(@object, value_); }, new Rect(200, index * distance + 10, 50, 20)); index--;
                        TextField(value_.y, f => { value_.y = f; info.SetValue(@object, value_); }, new Rect(285, index * distance + 10, 50, 20));
                    }
                    else if (FieldType == typeof(CBAttributeMapSO))
                    {
                        // Load the MapSO
                        Label(info.Name); index--;
                        Button(Localization.LOC_KITTOPIATECH_LOAD_CBMAP, () =>
                        {
                            FileWindow.type = FieldType;
                            UIController.Instance.SetEditedObject(KittopiaWindows.Files, value == null ? "" : PlanetExporter.Format(value as UnityEngine.Object), location =>
                            {
                                if (File.Exists(location))
                                {
                                    String path             = location.Replace(Path.Combine(Directory.GetCurrentDirectory(), "GameData") + Path.DirectorySeparatorChar, "");
                                    Texture2D texture       = Utility.LoadTexture(path, false, false, false);
                                    texture.name            = path.Replace("\\", "/");
                                    CBAttributeMapSO mapSO  = ScriptableObject.CreateInstance <CBAttributeMapSO>();
                                    mapSO.exactSearch       = false;
                                    mapSO.nonExactThreshold = 0.05f;
                                    mapSO.CreateMap(MapSO.MapDepth.RGB, texture);
                                    mapSO.Attributes = (value as CBAttributeMapSO).Attributes;
                                    mapSO.name       = path.Replace("\\", "/");
                                    info.SetValue(@object, mapSO);
                                }
                                else
                                {
                                    info.SetValue(@object, Resources.FindObjectsOfTypeAll <CBAttributeMapSO>().FirstOrDefault(m => m.name == location));
                                }
                            });
                            UIController.Instance.EnableWindow(KittopiaWindows.Files);
                        }, new Rect(200, index * distance + 10, 170, 20));


                        // Edit the Biome-Definitions
                        Button(Localization.LOC_KITTOPIATECH_EDIT_BIOMES, () => { UIController.Instance.SetEditedObject(KittopiaWindows.Biome, (value as CBAttributeMapSO).Attributes, att => { (value as CBAttributeMapSO).Attributes = att; info.SetValue(@object, value); }); UIController.Instance.EnableWindow(KittopiaWindows.Biome); });
                    }
                    else if (FieldType == typeof(Texture2D) || FieldType == typeof(Texture))
                    {
                        Label(info.Name); index--;
                        Button(Localization.LOC_KITTOPIATECH_LOAD_TEXTURE, () =>
                        {
                            FileWindow.type = FieldType;
                            UIController.Instance.SetEditedObject(KittopiaWindows.Files, value == null ? "" : PlanetExporter.Format(value as UnityEngine.Object), location =>
                            {
                                if (File.Exists(location))
                                {
                                    String path       = location.Replace(Path.Combine(Directory.GetCurrentDirectory(), "GameData") + Path.DirectorySeparatorChar, "");
                                    Texture2D texture = Utility.LoadTexture(path, false, false, false);
                                    texture.name      = path.Replace("\\", "/");
                                    info.SetValue(@object, texture);
                                }
                                else
                                {
                                    info.SetValue(@object, Resources.FindObjectsOfTypeAll <Texture>().FirstOrDefault(m => m.name == location));
                                }
                            });
                            UIController.Instance.EnableWindow(KittopiaWindows.Files);
                        }, new Rect(200, index * distance + 10, 170, 20));
                    }
                    else if (FieldType == typeof(PQSLandControl.LandClass[]))
                    {
                        Button(Localization.LOC_KITTOPIATECH_EDIT_LANDCLASSES, () => {
                            UIController.Instance.SetEditedObject(KittopiaWindows.LandClass, (PQSLandControl.LandClass[])value, lc => info.SetValue(@object, lc));
                            UIController.Instance.EnableWindow(KittopiaWindows.LandClass);
                        });
                    }
                    else if (FieldType == typeof(PQSMod_VertexPlanet.LandClass[]))
                    {
                        Button(Localization.LOC_KITTOPIATECH_EDIT_LANDCLASSES, () => {
                            UIController.Instance.SetEditedObject(KittopiaWindows.LandClass, (PQSMod_VertexPlanet.LandClass[])value, lc => info.SetValue(@object, lc));
                            UIController.Instance.EnableWindow(KittopiaWindows.LandClass);
                        });
                    }
                    else if (FieldType == typeof(PQSMod_HeightColorMap.LandClass[]))
                    {
                        Button(Localization.LOC_KITTOPIATECH_EDIT_LANDCLASSES, () => {
                            UIController.Instance.SetEditedObject(KittopiaWindows.LandClass, (PQSMod_HeightColorMap.LandClass[])value, lc => info.SetValue(@object, lc));
                            UIController.Instance.EnableWindow(KittopiaWindows.LandClass);
                        });
                    }
                    else if (FieldType == typeof(PQSMod_HeightColorMap2.LandClass[]))
                    {
                        Button(Localization.LOC_KITTOPIATECH_EDIT_LANDCLASSES, () => {
                            UIController.Instance.SetEditedObject(KittopiaWindows.LandClass, (PQSMod_HeightColorMap2.LandClass[])value, lc => info.SetValue(@object, lc));
                            UIController.Instance.EnableWindow(KittopiaWindows.LandClass);
                        });
                    }
                    else if (FieldType == typeof(PQSMod_HeightColorMapNoise.LandClass[]))
                    {
                        Button(Localization.LOC_KITTOPIATECH_EDIT_LANDCLASSES, () => {
                            UIController.Instance.SetEditedObject(KittopiaWindows.LandClass, (PQSMod_HeightColorMapNoise.LandClass[])value, lc => info.SetValue(@object, lc));
                            UIController.Instance.EnableWindow(KittopiaWindows.LandClass);
                        });
                    }
                    else if (FieldType == typeof(PQSLandControl.LerpRange))
                    {
                        Label(info.Name); index--;
                        Button(Localization.LOC_KITTOPIATECH_EDIT_LERPRANGE, () => {
                            UIController.Instance.SetEditedObject(KittopiaWindows.LerpRange, (PQSLandControl.LerpRange)value, lc => info.SetValue(@object, lc));
                            UIController.Instance.EnableWindow(KittopiaWindows.LerpRange);
                        }, new Rect(200, index * distance + 10, 170, 20));
                    }
                    else if (FieldType == typeof(PQSMod_VertexPlanet.SimplexWrapper))
                    {
                        Label(info.Name); index--;
                        Button(Localization.LOC_KITTOPIATECH_EDIT_SIMPLEX, () => {
                            UIController.Instance.SetEditedObject(KittopiaWindows.Simplex, (PQSMod_VertexPlanet.SimplexWrapper)value, lc => info.SetValue(@object, lc));
                            UIController.Instance.EnableWindow(KittopiaWindows.Simplex);
                        }, new Rect(200, index * distance + 10, 170, 20));
                    }
                    else if (FieldType == typeof(PQSMod_VertexPlanet.NoiseModWrapper))
                    {
                        Label(info.Name); index--;
                        Button(Localization.LOC_KITTOPIATECH_EDIT_NOISEMOD, () => {
                            UIController.Instance.SetEditedObject(KittopiaWindows.NoiseMod, (PQSMod_VertexPlanet.NoiseModWrapper)value, lc => info.SetValue(@object, lc));
                            UIController.Instance.EnableWindow(KittopiaWindows.NoiseMod);
                        }, new Rect(200, index * distance + 10, 170, 20));
                    }
                    else if (FieldType == typeof(MapSO))
                    {
                        // Depth
                        if (mapDepth == 5 && value != null)
                        {
                            mapDepth = (Int32)(value as MapSO).Depth;
                        }
                        else if (mapDepth == 5 && value == null)
                        {
                            mapDepth = 0;
                        }

                        // Load the MapSO
                        Label(info.Name); index--;
                        Button(Localization.LOC_KITTOPIATECH_LOAD_MAPSO, () =>
                        {
                            FileWindow.type = FieldType;
                            UIController.Instance.SetEditedObject(KittopiaWindows.Files, value == null ? "" : PlanetExporter.Format(value as UnityEngine.Object), location =>
                            {
                                if (File.Exists(location))
                                {
                                    String path       = location.Replace(Path.Combine(Directory.GetCurrentDirectory(), "GameData") + Path.DirectorySeparatorChar, "");
                                    Texture2D texture = Utility.LoadTexture(path, false, false, false);
                                    texture.name      = path.Replace("\\", "/");
                                    MapSO mapSO       = ScriptableObject.CreateInstance <MapSO>();
                                    mapSO.CreateMap((MapSO.MapDepth)mapDepth, texture);
                                    mapSO.name = path.Replace("\\", "/");
                                    info.SetValue(@object, mapSO);
                                }
                                else
                                {
                                    info.SetValue(@object, Resources.FindObjectsOfTypeAll <MapSO>().FirstOrDefault(m => m.name == location));
                                }
                            });
                            UIController.Instance.EnableWindow(KittopiaWindows.Files);
                        }, new Rect(200, index * distance + 10, 170, 20));
                        mapDepth = GUI.SelectionGrid(new Rect(20, index * distance + 10, 350, 20), mapDepth, new [] { "Greyscale", "HeightAlpha", "RGB", "RGBA" }, 4);
                        index++;
                    }
                    else if (FieldType == typeof(PQS))
                    {
                        Label(info.Name); index--;
                        Button(Localization.LOC_KITTOPIATECH_EDIT_SPHERE, () => {
                            UIController.Instance.SetEditedObject(KittopiaWindows.Selector, value as PQS ?? new PQS(), s => info.SetValue(@object, s));
                            UIController.Instance.EnableWindow(KittopiaWindows.Selector);
                        }, new Rect(200, index * distance + 10, 170, 20));
                    }
                    else if (FieldType == typeof(CelestialBody))
                    {
                        Label(info.Name); index--;
                        Button(Localization.LOC_KITTOPIATECH_EDIT_BODY, () =>
                        {
                            UIController.Instance.SetEditedObject(KittopiaWindows.Selector, value ?? new CelestialBody(), b => info.SetValue(@object, b));
                            UIController.Instance.EnableWindow(KittopiaWindows.Selector);
                        }, new Rect(200, index * distance + 10, 170, 20));
                    }
                    else if (value is Material) // Kopernicus creates Wrappers for the Materials, so key.FieldType == typeof(Material) would return false. :/
                    {
                        Label(info.Name); index--;
                        Button(Localization.LOC_KITTOPIATECH_EDIT_MATERIAL, () => {
                            UIController.Instance.SetEditedObject(KittopiaWindows.Material, value as Material, m => info.SetValue(@object, m));
                            UIController.Instance.EnableWindow(KittopiaWindows.Material);
                        }, new Rect(200, index * distance + 10, 170, 20));
                    }
                    else if (FieldType == typeof(FloatCurve))
                    {
                        Label(info.Name); index--;
                        Button(Localization.LOC_KITTOPIATECH_EDIT_CURVE, () => {
                            UIController.Instance.SetEditedObject(KittopiaWindows.Curve, (FloatCurve)value, lc => info.SetValue(@object, lc));
                            UIController.Instance.EnableWindow(KittopiaWindows.Curve);
                        }, new Rect(200, index * distance + 10, 170, 20));
                    }
                    else if (FieldType == typeof(AnimationCurve))
                    {
                        Label(info.Name); index--;
                        Button(Localization.LOC_KITTOPIATECH_EDIT_CURVE, () => {
                            UIController.Instance.SetEditedObject(KittopiaWindows.Curve, new FloatCurve(((AnimationCurve)value).keys), lc => info.SetValue(@object, lc.Curve));
                            UIController.Instance.EnableWindow(KittopiaWindows.Curve);
                        }, new Rect(200, index * distance + 10, 170, 20));
                    }
                    else if (FieldType == typeof(Mesh))
                    {
                        Label(info.Name); index--;
                        Button(Localization.LOC_KITTOPIATECH_EDIT_MESH, () =>
                        {
                            FileWindow.type = FieldType;
                            UIController.Instance.SetEditedObject(KittopiaWindows.Files, value == null ? "" : PlanetExporter.Format(value as UnityEngine.Object), location =>
                            {
                                if (File.Exists(location))
                                {
                                    String path       = location.Replace(Path.Combine(Directory.GetCurrentDirectory(), "GameData") + Path.DirectorySeparatorChar, "");
                                    MeshParser parser = new MeshParser(value as Mesh);
                                    parser.SetFromString(path);
                                    parser.value.name = path.Replace("\\", "/");
                                    info.SetValue(@object, parser.value);
                                }
                                else
                                {
                                    info.SetValue(@object, Resources.FindObjectsOfTypeAll <Mesh>().FirstOrDefault(m => m.name == location));
                                }
                            });
                            UIController.Instance.EnableWindow(KittopiaWindows.Files);
                        }, new Rect(200, index * distance + 10, 170, 20));
                    }
                }
            }