Created
November 29, 2017 21:43
-
-
Save santiihoyos/d3946e9010ef9a3e493786e0d29c122f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
using UnityEngine.SceneManagement; | |
using UnityEditor.SceneManagement; | |
using UnityEditor; | |
public class GeneraLadrillos : MonoBehaviour | |
{ | |
public GameObject PrefabLadrilloBase; | |
private Color32[] colores; | |
public Texture2D[] patrones; | |
public Vector2 posicionCreacion; | |
public void GeneraNiveles () | |
{ | |
//var gameScene = EditorSceneManager.GetActiveScene (); | |
for (int n = 0; n < patrones.Length; n++) { | |
//EditorSceneManager.OpenScene ("Assets/Scenes/Level" + (n+1).ToString () + ".unity", OpenSceneMode.Additive); | |
var escena = EditorSceneManager.NewScene (NewSceneSetup.EmptyScene, NewSceneMode.Additive); | |
EditorSceneManager.SetActiveScene (escena); | |
colores = patrones [n].GetPixels32 (); | |
int count = 0; | |
float altura = PrefabLadrilloBase.GetComponent<SpriteRenderer> ().bounds.size.y; | |
float anchura = PrefabLadrilloBase.GetComponent<SpriteRenderer> ().bounds.size.x; | |
for (int i = 0; i < patrones [n].height; i++) { | |
for (int j = 0; j < patrones [n].width; j++) { | |
if (colores [count] != Color.white) { | |
PrefabLadrilloBase.GetComponent<SpriteRenderer> ().color = colores [count]; | |
GameObject nuevo = Instantiate (PrefabLadrilloBase, new Vector3 ((j * anchura) + posicionCreacion.x, (i * altura) + posicionCreacion.y, 0), Quaternion.identity); | |
nuevo.tag = "ladrillo"; | |
nuevo.name = "cuadro " + i + "_" + j; | |
} | |
count++; | |
} | |
} | |
var path = "Assets/Scenes/Level" + (n + 1).ToString () + ".unity"; | |
EditorSceneManager.SaveScene (escena, path); | |
var newEscenas = new List<EditorBuildSettingsScene> (); | |
newEscenas.AddRange (EditorBuildSettings.scenes); | |
if (!newEscenas.Exists (t => t.path == path)) { | |
newEscenas.Add (new EditorBuildSettingsScene (path, true)); | |
} | |
EditorBuildSettings.scenes = newEscenas.ToArray (); | |
EditorSceneManager.UnloadSceneAsync (escena); | |
} | |
//EditorSceneManager.SetActiveScene (gameScene); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment