Beispiel #1
0
    static void RunTest()
    {
        string filepath = EditorUtility.OpenFilePanel(
            "Select JSON file to import",
            "",
            "json");
        TiledLevel level;
        if (filepath.Length > 0) {
            level = new TiledLevel(filepath);
            Debug.Log (level.Tilesets[0].GetTileProperties(5).Bottom);

        } else {
            level = null;
        }
    }
Beispiel #2
0
    private static void setMaterials(TileProperties properties, GameObject mapPrimitive, int number, TiledLevel level, TileSet set)
    {
        MapComponent primitve = mapPrimitive.GetComponent<MapComponent> ();
        if (primitve == null)
            return;
        string name = set.Name;
        //Texture2D text = (Texture2D) level.Tilesets[0].Texture;
        string texturepath = "Assets/Textures/" + name + ".asset";

        string frontpath = SaveTileMaterial(name, number, texturepath, set);
        string backpath = SaveTileMaterial(name, properties.Back, texturepath, set);
        string toppath = SaveTileMaterial(name, properties.Top, texturepath, set);
        string bottompath = SaveTileMaterial(name, properties.Bottom, texturepath, set);
        string leftpath = SaveTileMaterial(name, properties.Left, texturepath, set);
        string rightpath = SaveTileMaterial(name, properties.Right, texturepath, set);

        if (!frontpath.Equals ("")) {
            primitve.SetFrontMaterial((Material) AssetDatabase.LoadAssetAtPath(frontpath, typeof(Material)));
        }
        if (!backpath.Equals ("")) {
            primitve.SetBackMaterial((Material) AssetDatabase.LoadAssetAtPath(backpath, typeof(Material)));
        }
        if (!toppath.Equals ("")) {
            primitve.SetTopMaterial((Material) AssetDatabase.LoadAssetAtPath(toppath, typeof(Material)));
        }
        if (!bottompath.Equals ("")) {
            primitve.SetBottomMaterial((Material) AssetDatabase.LoadAssetAtPath(bottompath, typeof(Material)));
        }
        if (!leftpath.Equals ("")) {
            primitve.SetLeftMaterial((Material) AssetDatabase.LoadAssetAtPath(leftpath, typeof(Material)));
        }
        if (!rightpath.Equals ("")) {
            primitve.SetRightMaterial((Material) AssetDatabase.LoadAssetAtPath(rightpath, typeof(Material)));
        }
    }
Beispiel #3
0
    static void ImportJson()
    {
        TiledLevel level;
        GameObject map;

        AssetDatabase.CreateFolder("Assets/Meshes/", "TiledMeshes");
        AssetDatabase.CreateFolder("Assets/Prefabs/", "TiledPrefabs");

        string prefabPath = "Assets/Prefabs/TiledPrefabs/";
        AssetDatabase.DeleteAsset(prefabPath);

        string filepath = EditorUtility.OpenFilePanel(
            "Select JSON file to import",
            "",
            "json");

        if (filepath.Length > 0) {
            level = new TiledLevel (filepath);
        } else {
            level = null;
        }

        map = new GameObject ();

        if (level != null) {
            int z = 0;
            Debug.Log("There are " + level.Tilesets.Length + " tilesets");
            foreach(TiledLayer layer in level.Layers){
                int count = 0;
                for(int row = layer.Height-1; row >=0; row --){
                    for(int column = 0; column < layer.Width; column++){
                        int number = layer.Data[count] -1;
                        if(number != -1){
                            TileSet tileset = level.getTileSetForNumber(number);
                            TileProperties properties = tileset.GetTileProperties(number);
                            GameObject newobj = Instantiate (Resources.Load ("cube" ,typeof(GameObject)))as GameObject;
                            setCollisionType(newobj, properties);
                            newobj.transform.position = (new Vector3(column, row, z));
                            setMaterials(properties, newobj, number, level, tileset);
                            newobj.transform.SetParent(map.transform);
                        }else{
                            //Debug.Log("ZERO ENCOUNTERED");
                        }
                        count++;
                    }
                }

                z++;
            }
        }
        prefabPath = prefabPath + getNameFromFilepath(filepath) + ".prefab";
        PrefabUtility.CreatePrefab(prefabPath, map);
        //AssetDataBase.Refresh ();
    }