Пример #1
0
    /// <summary>
    /// Crea un mapa dado su ancho, alto y nombre.
    /// </summary>
    public void CreateMap()
    {
        EditorApplication.NewScene();         // Crea una scene nueva.
        GameObject MapObj = new GameObject("Map");

        Camera.main.transform.parent        = MapObj.transform;
        Camera.main.orthographicSize        = 5;                                                                           // Ajusta el tamaño de la camara ( la cantidad de espacio que va enfocar)
        Camera.main.transform.localPosition = new Vector3((float)(Data.Width - 1) / 2, (float)(Data.Heigth - 1) / 2, -10); // Posiciona la camara en el centro del mapa
        Camera.main.backgroundColor         = Color.black;
        Camera.main.gameObject.AddComponent <MainCamera>();
        UnityEngine.Object prefab  = AssetDatabase.LoadAssetAtPath(@"Assets/Resources/Tile/DefaultTile1.prefab", typeof(GameObject)); // Carga el prefab que esta por defecto para crear el mapa
        UnityEngine.Object prefab2 = AssetDatabase.LoadAssetAtPath(@"Assets/Resources/Tile/DefaultTile2.prefab", typeof(GameObject)); // Carga el prefab que esta por defecto para crear el mapa
        for (int i = 0; i < Data.Width; i++)
        {
            for (int j = 0; j < Data.Heigth; j++)
            {
                Vector2    position = new Vector2(i, j);
                GameObject clone    = new GameObject();

                if ((i + j) % 2 == 0)
                {
                    clone = EditorWindow.Instantiate(prefab, position, Quaternion.identity) as GameObject;                     // Agrega un objeto nuevo a la scene.
                }
                else
                {
                    clone = EditorWindow.Instantiate(prefab2, new Vector3(i, j, 0f), Quaternion.identity) as GameObject;
                }
                clone.tag = "RPG-CORE";
                clone.transform.parent = MapObj.transform;
                EditorWindow.DestroyImmediate(GameObject.Find("New Game Object"));
            }
        }
        GameObject settings = new GameObject("Settings");

        settings.AddComponent <Map>();

        if (this.Data.Background != null)
        {
            Audio audio = new Audio("BackgroundAudio");
            audio.CreateAudioSource(this.Data.Background);
            audio.gameobject.transform.parent = MapObj.transform;
        }

        Map x = settings.GetComponent <Map>();

        x.Name        = x.Data.Name = this.Data.Name;
        x.Data.Width  = this.Data.Width;
        x.Data.Heigth = this.Data.Heigth;
        x.Icon        = AssetDatabase.LoadAssetAtPath <Sprite>("Assets/TurnBaseRPG-Creator/RPG-Sprites/MapIcon.png");
        x.Id          = Guid.NewGuid().ToString();
        string returnPath = "Assets/Resources/Maps/" + x.Id + ".unity";

        x.Data.MapPath = returnPath;
        PrefabUtility.CreatePrefab("Assets/Resources/Maps/" + x.Id + ".prefab", x.gameObject);
        DestroyImmediate(settings);
        EditorApplication.SaveScene(returnPath);// Guarda la scene.
        Constant.AddSceneToBuild(returnPath);
    }
Пример #2
0
    /// <summary>
    /// Crea la escena del battlemap
    /// </summary>
    /// <param name="troop">Tropa que contiene el battlemap</param>
    public static void CreateTroopScene(Troop troop)
    {
        EditorApplication.NewScene(); // Crea una scene nueva.
        var battlemap = new GameObject("BattleMap");

        Camera.main.transform.parent = battlemap.transform;
        Camera.main.orthographic     = true;
        Camera.main.backgroundColor  = Color.black;
        Camera.main.gameObject.AddComponent <MainCamera>();
        Camera.main.orthographicSize = 6.95f; // Ajusta el tamaño de la camara ( la cantidad de espacio que va enfocar)
        Camera.main.rect             = new Rect(0, 0, 1, 1.4f);
        Camera.main.orthographicSize = 222.12f;

        var bm = new GameObject("BattleManager").AddComponent <BattleManager>();

        bm.transform.parent = battlemap.transform;
        UnityEngine.Object [] BattlePrefabs = Resources.LoadAll("BattleMap", typeof(GameObject));
        foreach (var i in BattlePrefabs)
        {
            GameObject x = Instantiate(i as GameObject);
            x.name = i.name;

            if (i.name == "Selector" || i.name == "Battle")
            {
                x.transform.SetParent(battlemap.transform);
                continue;
            }
            if (i.name != "BattleMenu")
            {
                x.transform.SetParent(battlemap.transform);
                x.GetComponent <Canvas>().worldCamera = Camera.main;
                x.GetComponent <Canvas>().renderMode  = RenderMode.ScreenSpaceCamera;
            }
            else
            {
                x.transform.SetParent(battlemap.transform);
                x.transform.FindChild("Canvas").gameObject.GetComponent <Canvas>().worldCamera = Camera.main;
                x.transform.FindChild("Canvas").gameObject.GetComponent <Canvas>().renderMode  = RenderMode.ScreenSpaceCamera;
            }
        }
        Vector2 backgroundSize = CreateBackground("Bottom", troop.BackgroundBottom, 0, battlemap);

        CreateBackground("Top", troop.BackgroundTop, 1, battlemap);
        foreach (var enemy in troop.Enemies)
        {
            GameObject gobj = new GameObject(enemy.Data.ActorName);
            gobj.tag = "RPG-ENEMY";
            var enemyScene = gobj.AddComponent <Enemy>();
            enemyScene.BattleEnemy = enemy;

            var sprite = gobj.AddComponent <SpriteRenderer>();
            sprite.sprite           = enemy.Data.Image;
            sprite.sortingLayerName = "Actors";
            gobj.transform.parent   = battlemap.transform;
        }

        Audio audio = new Audio("BackgroundAudio");

        audio.CreateAudioSource(troop.Background);
        audio.gameobject.transform.parent = battlemap.transform;
        EditorApplication.SaveScene("Assets/Resources/BattleMap/" + troop.Id + ".unity", true);// Guarda la scene.
        Constant.AddSceneToBuild("Assets/Resources/BattleMap/" + troop.Id + ".unity");
    }