Created
May 28, 2016 14:09
-
-
Save danhanfry/cd22c17b87bc0c3fe4d6f413164e3c59 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; | |
using System.Collections; | |
using System.IO; | |
using UnityEditor; | |
using UnityEngine; | |
using UnityEngine.UI; | |
public class PluginGenerarMenu : EditorWindow { | |
public static GameObject Carrousel { get; private set; } | |
public static RectTransform CarrouselRect { get; private set; } | |
public static Sprite urlAnimal; | |
[MenuItem("funciones/crearMenu")] | |
static void create() { | |
string path = "/Resources"; | |
bool newLine = true; | |
float scaleImg = 5; | |
float sizeReal = 100 * scaleImg; | |
float xMargen = 200; | |
float yMargen = 200; | |
Carrousel = GameObject.Find("Carrousel"); | |
CarrouselRect = Carrousel.GetComponent<RectTransform>(); | |
float width = CarrouselRect.sizeDelta.x; | |
float height = CarrouselRect.sizeDelta.y; | |
float numItems = (float)Math.Floor(width / sizeReal); | |
xMargen = (width - (numItems * sizeReal)) / (numItems + 1); | |
float xInit = (width / 2 - (sizeReal / 2) - xMargen) * -1; | |
float yInit = height / 2 - sizeReal / 2; | |
float xChange = xInit; | |
float yChange = yInit; | |
string[] fileEntries = Directory.GetFiles(Application.dataPath + path, "*.png"); | |
float numFiles = fileEntries.Length; | |
float index = 0; | |
foreach (string fileDir in fileEntries) | |
{ | |
index++; | |
//Debug.Log(xChange + " - " + index); | |
string fileName = Path.GetFileNameWithoutExtension(fileDir); | |
GameObject go = new GameObject(fileName); | |
go.gameObject.transform.parent = Carrousel.transform; | |
go.transform.position = new Vector2(0, 0); | |
Image goImage = go.AddComponent<Image>(); | |
goImage.sprite = Resources.Load<Sprite>(fileName); | |
goImage.preserveAspect = true; | |
go.GetComponent<RectTransform>().localScale = new Vector2(scaleImg, scaleImg); | |
go.GetComponent<RectTransform>().anchoredPosition = new Vector2(xChange, yChange); | |
xChange = xChange + sizeReal + xMargen; | |
if(newLine && index >= numFiles / 2 ) | |
{ | |
xChange = xInit; | |
yChange = yChange - sizeReal; | |
newLine = false; | |
} | |
} | |
} | |
static void getMargen(float width, int numItem) | |
{ | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment