Example #1
0
    static void ListPrefabsInGame()
    {
        var prefabManager = SceneAsset.FindObjectOfType <PrefabManager>();

        if (prefabManager == null)
        {
            Debug.LogError("Unable to find prefab manager");
            return;
        }

        var location = "Assets/Prefabs";

        var path   = $"{Directory.GetCurrentDirectory()}/{location}";
        var files  = Directory.EnumerateFiles(path);
        var assets = AssetDatabase.LoadAllAssetsAtPath(path);

        prefabManager.Prefabs = new  List <Prefab>();
        foreach (var file in files)
        {
            var filename = Path.GetFileName(file);
            var ass      = AssetDatabase.LoadAssetAtPath <GameObject>($"{location}/{filename}");
            // var ass = (GameObject)asset;
            if (ass == null)
            {
                continue;
            }
            prefabManager.Prefabs.Add(new Prefab()
            {
                GameObject = ass,
                Name       = ass.name
            });
        }
    }
Example #2
0
 public static void SwitchAllLearningBrainToControlMode()
 {
     Debug.Log("The Switching to control mode function is triggered");
     string[] scenePaths = Directory.GetFiles("Assets/ML-Agents/Examples/", "*.unity", SearchOption.AllDirectories);
     foreach (string scenePath in scenePaths)
     {
         var curScene = EditorSceneManager.OpenScene(scenePath);
         var aca      = SceneAsset.FindObjectOfType <Academy>();
         if (aca != null)
         {
             var learningBrains = aca.broadcastHub.broadcastingBrains.Where(
                 x => x != null && x is LearningBrain);
             foreach (Brain brain in learningBrains)
             {
                 if (!aca.broadcastHub.IsControlled(brain))
                 {
                     Debug.Log("Switched brain in scene " + scenePath);
                     aca.broadcastHub.SetControlled(brain, true);
                 }
             }
             EditorSceneManager.SaveScene(curScene);
         }
         else
         {
             Debug.Log("scene " + scenePath + " doesn't have a Academy in it");
         }
     }
 }
Example #3
0
    static void LoadMap()
    {
        var map      = SceneAsset.FindObjectOfType <MapLoader>();
        var path     = EditorUtility.OpenFilePanel("Load Map", MapLoader.GetDefaultFilePath(), "map");
        var filename = Path.GetFileNameWithoutExtension(path);

        map.StartCoroutine(map.LoadMap(filename, false));
    }
Example #4
0
    static void ClearMap()
    {
        var map = SceneAsset.FindObjectOfType <MapLoader>();

        map.Foreground.ClearAllTiles();
        map.BackGround.ClearAllTiles();
        map.Walls.ClearAllTiles();
        map.Name = "";
    }
Example #5
0
 static void AddSimpleProfileUI()
 {
     if (SceneAsset.FindObjectOfType <SimpleSceneUI>() == null)
     {
         PrefabUtility.InstantiatePrefab(Resources.Load("Prefabs/Examples/Canvas (Simple Scene UI)"));
     }
     if (SceneAsset.FindObjectOfType <EventSystem>() == null)
     {
         var eventSystem = new GameObject("EventSystem", typeof(EventSystem), typeof(StandaloneInputModule));
     }
     MarkSceneAsDirty();
 }
Example #6
0
 static void AddProfileManager()
 {
     if (SceneAsset.FindObjectOfType <EasyProfileManager>() == null)
     {
         PrefabUtility.InstantiatePrefab(Resources.Load("Prefabs/Managers/[EasyProfileManager]"));
     }
     if (SceneAsset.FindObjectOfType <EventSystem>() == null)
     {
         var eventSystem = new GameObject("EventSystem", typeof(EventSystem), typeof(StandaloneInputModule));
     }
     MarkSceneAsDirty();
 }
Example #7
0
    static void CreateTrees()
    {
        var map     = SceneAsset.FindObjectOfType <MapLoader>();
        var tileman = SceneAsset.FindObjectOfType <TileManager>();

        var locations = map.Walls.GetAllTileData().Where(x => x.TileName == "Apple Trees_32_0");

        foreach (var pos in locations)
        {
            AddTileObj(pos.Postion, tileobjects[0], map);
        }
    }
Example #8
0
    public static void SetScene()
    {
        Debug.Log("Setting Scene");
        if (SceneAsset.FindObjectOfType <UIManager>() == null)
        {
            PrefabUtility.InstantiatePrefab(Resources.Load("Core/Game UI"));
        }
        if (SceneAsset.FindObjectOfType <EventSystem>() == null)
        {
            var eventSystem = new GameObject("EventSystem", typeof(EventSystem), typeof(StandaloneInputModule));
        }
        if (SceneAsset.FindObjectOfType <GameManager>() == null)
        {
            PrefabUtility.InstantiatePrefab(Resources.Load("Core/Game Manager"));
        }
        if (SceneAsset.FindObjectOfType <LevelManager>() == null)
        {
            PrefabUtility.InstantiatePrefab(Resources.Load("Core/Level Manager"));
        }
        if (SceneAsset.FindObjectOfType <Camera>() == null)
        {
            PrefabUtility.InstantiatePrefab(Resources.Load("Core/Camera Parent"));
        }
        else
        {
            if (SceneAsset.FindObjectOfType <CameraShake>() == null)
            {
                GameObject Camera = SceneAsset.FindObjectOfType <Camera>().gameObject;
                SceneAsset.DestroyImmediate(Camera);
                PrefabUtility.InstantiatePrefab(Resources.Load("Core/Camera Parent"));
            }
        }
        if (SceneAsset.FindObjectOfType <Grid>() == null)
        {
            PrefabUtility.InstantiatePrefab(Resources.Load("Core/Basic Tilemap Grid"));
        }

        if (SceneAsset.FindObjectOfType <SoundManager>() == null)
        {
            PrefabUtility.InstantiatePrefab(Resources.Load("Core/Sound Manager"));
        }
        if (SceneAsset.FindObjectOfType <Light2D>() == null)
        {
            PrefabUtility.InstantiatePrefab(Resources.Load("Core/Global Light"));
        }
        if (SceneAsset.FindObjectOfType <PathFindingGrid>() == null)
        {
            PrefabUtility.InstantiatePrefab(Resources.Load("Core/PathFindingGrid"));
            PathFindingGrid grid = SceneAsset.FindObjectOfType <PathFindingGrid>();
            grid.UnBuild();
            grid.Build();
        }
    }
Example #9
0
    static void SaveMap()
    {
        var map = SceneAsset.FindObjectOfType <MapLoader>();
        //if (string.IsNullOrWhiteSpace(map.Name))
        //{
        var path     = EditorUtility.SaveFilePanel("Save map", MapLoader.GetDefaultFilePath(), "", "map");
        var filename = Path.GetFileNameWithoutExtension(path);

        map.Name = filename;
        // }

        map.SaveMap(map.Name);
    }
Example #10
0
    static void CreateAnimationFunction()
    {
        var animationManager = SceneAsset.FindObjectOfType <AnimationManager>();

        if (animationManager == null)
        {
            Debug.LogError("Unable to find Animation Manager");
            return;
        }
        animationManager.AnimationCollections = new List <AnimationCollection>();


        var layers = Directory.GetDirectories("Assets/Sprites/Standard/Character");

        foreach (var layer in layers)
        {
            var layername = Path.GetFileName(layer);

            if (!Directory.Exists($"{AnimationSavePath}/{layername}"))
            {
                Directory.CreateDirectory($"{AnimationSavePath}/{layername}");
            }

            animationManager.AnimationCollections.AddRange(CreateForLayer(layername, "Assets/Sprites/Standard/Character"));
        }
        var layers2 = Directory.GetDirectories("Assets/Sprites/Standard/Equipment");

        foreach (var layer in layers2)
        {
            var layername = Path.GetFileName(layer);

            if (!Directory.Exists($"{AnimationSavePath}/{layername}"))
            {
                Directory.CreateDirectory($"{AnimationSavePath}/{layername}");
            }

            animationManager.AnimationCollections.AddRange(CreateForLayer(layername, "Assets/Sprites/Standard/Equipment"));
        }

        //allAssets.Fin
        //   Sprite[] sprites = spri as Sprite[];
        //   CreateAnimation("all", sprites);
    }
Example #11
0
    static void VaryWater()
    {
        var map     = SceneAsset.FindObjectOfType <MapLoader>();
        var tileman = SceneAsset.FindObjectOfType <TileManager>();

        var locations = map.Walls.GetAllTileData().Where(x => x.TileName == "Assorted Terrain 2_512_224");

        List <string> otherwater = new List <string>()
        {
            "Assorted Terrain 2_512_224",
            "Assorted Terrain 2_480_160",
            "Assorted Terrain 2_512_160",
            "Assorted Terrain 2_544_160"
        };

        foreach (var pos in locations)
        {
            map.Walls.SetTile(pos.Postion, tileman.GetTile(otherwater.RandomElement()));
        }
    }
Example #12
0
    static void AddTileObj(Vector3Int basepos, List <TileData> tileData, MapLoader map)
    {
        var tileman = SceneAsset.FindObjectOfType <TileManager>();

        foreach (var t in tileData)
        {
            switch (t.Layer)
            {
            case "Background":
                map.BackGround.SetTile(basepos + t.Postion, tileman.GetTile(t.TileName));
                break;

            case "Foreground":
                map.Foreground.SetTile(basepos + t.Postion, tileman.GetTile(t.TileName));
                break;

            case "Walls":
                map.Walls.SetTile(basepos + t.Postion, tileman.GetTile(t.TileName));
                break;
            }
        }
    }
Example #13
0
    static void GenerateMap()
    {
        var map = SceneAsset.FindObjectOfType <MapLoader>();

        map.ClearMap();
        var tileman = SceneAsset.FindObjectOfType <TileManager>();
        int size    = 100;

        for (int xdx = -size; xdx < size; xdx++)
        {
            for (int ydx = -size; ydx < size; ydx++)
            {
                map.BackGround.SetTile(new Vector3Int(xdx, ydx, 0), tileman.GetTile(terrain.RandomElement()));
            }
        }

        //for (int idx = 0; idx < 30; idx++)
        //{
        //    var element = tileobjects.RandomElement();

        //    var basepos = new Vector3Int(Random.Range(-size, size), Random.Range(-size, size), 0);
        //    foreach(var t in element)
        //    {
        //        switch(t.Layer)
        //        {
        //            case "Background":
        //                map.BackGround.SetTile(basepos + t.Postion, tileman.GetTile(t.TileName));
        //                break;
        //            case "Foreground":
        //                map.Foreground.SetTile(basepos + t.Postion, tileman.GetTile(t.TileName));
        //                break;
        //            case "Walls":
        //                map.Walls.SetTile(basepos + t.Postion, tileman.GetTile(t.TileName));
        //                break;
        //        }
        //    }
        //}
    }
Example #14
0
    static void ImportTiles()
    {
        var files       = Directory.GetFiles($"{FileLoader.ModPath}/{TileManager.TilePath}");
        var tilemanager = SceneAsset.FindObjectOfType <TileManager>();

        tilemanager.StartCoroutine(tilemanager.LoadTiles(true));


        foreach (var file in files)
        {
            if (Path.GetExtension(file) != ".png")
            {
                continue;
            }
            var filename = Path.GetFileNameWithoutExtension(file);


            var resourcePath = $"./Assets/Resources/TilesSpritesheets/{filename}.png";

            if (!File.Exists(resourcePath))
            {
                File.Copy(file, resourcePath);
            }


            AssetDatabase.ImportAsset(resourcePath, ImportAssetOptions.ForceUpdate);

            AssetDatabase.Refresh();

            var myTexture = AssetDatabase.LoadAssetAtPath <Texture2D>($"Assets/Resources/TilesSpritesheets/{filename}.png");

            string          path = AssetDatabase.GetAssetPath(myTexture);
            TextureImporter ti   = AssetImporter.GetAtPath(path) as TextureImporter;
            ti.isReadable          = true;
            ti.spritePixelsPerUnit = 32;
            ti.filterMode          = FilterMode.Point;
            ti.spriteImportMode    = SpriteImportMode.Multiple;
            List <SpriteMetaData> newData = new List <SpriteMetaData>();

            int SliceWidth  = 32;
            int SliceHeight = 32;

            for (int i = 0; i <= myTexture.width; i += SliceWidth)
            {
                for (int j = 0; j <= myTexture.height; j += SliceHeight)
                {
                    SpriteMetaData smd = new SpriteMetaData();
                    smd.pivot     = new Vector2(0.5f, 0.5f);
                    smd.alignment = 9;
                    smd.name      = $"{filename}_{i}_{j}";
                    smd.rect      = new Rect(i, j, SliceWidth, SliceHeight);

                    newData.Add(smd);
                }
            }

            ti.spritesheet = newData.ToArray();

            AssetDatabase.ImportAsset(path, ImportAssetOptions.ForceUpdate);
        }

        AssetDatabase.Refresh();
        return;
    }
Example #15
0
    static void LoadTilesIntoGame()
    {
        var tilemanager = SceneAsset.FindObjectOfType <TileManager>();

        tilemanager.StartCoroutine(tilemanager.LoadTiles(true));
    }
Example #16
0
    static void CreateEntities()
    {
        List <Vector3Int> locations = new List <Vector3Int>();
        var map = SceneAsset.FindObjectOfType <MapLoader>();

        map.Map.Entities = new List <EntityDefines>();


        var walls      = map.Walls.GetAllTileData().Select(x => x.Postion);
        var background = map.BackGround.GetAllTileData().Select(x => x.Postion);

        for (int idx = 0; idx < Random.Range(20, 25); idx++)
        {
            var rand = background.RandomElement();
            if (walls.Contains(rand))
            {
                idx--;
                continue;
            }

            var position = background.Where(x => new RectInt(rand.x - 10, rand.y - 10, 20, 20).Contains(new Vector2Int(x.x, x.y)));

            for (int jdx = 0; jdx < Random.Range(1, 5); jdx++)
            {
                var pos = position.RandomElement();
                if (walls.Contains(pos))
                {
                    jdx--;
                    continue;
                }
                locations.Add(pos);
            }
        }


        foreach (var loc in locations)
        {
            var entity = CreateEntity();
            entity.SpawnLocation = loc;
            map.Map.Entities.Add(entity);
        }


        var awalls = map.Walls.GetAllTileData().ToList();

        awalls.AddRange(map.BackGround.GetAllTileData());
        awalls.AddRange(map.Foreground.GetAllTileData());

        foreach (var w in awalls)
        {
            var entity  = GetClosestEntity(w.Postion, map.Map);
            var replace = Replaces.FirstOrDefault(x => x.corrupt == w.TileName);
            if (replace != null)
            {
                entity.OnDeath.ChangeTiles.Add(new TileData()
                {
                    Layer    = w.Layer,
                    Postion  = w.Postion,
                    TileName = replace.fix
                });
            }
        }
    }