Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEditor;
- using UnityEngine;
- using System.IO;
- using System.Collections;
- using System.Collections.Generic;
- using System.Runtime.Serialization.Formatters.Binary;
- public class Editorfiller_TowerUVs : EditorWindow {
- public GameObject Towermodel;
- private Vector2 scrollview1 = Vector2.zero;
- private int ain,bin,cin,din,ein,fin = 0;
- private string dateiname = "";
- private GUIStyle gsAlterQuest = new GUIStyle();
- [System.Serializable]
- public class UVs{
- public float toplx;
- public float toprx;
- public float lowlx;
- public float lowrx;
- public float toply;
- public float topry;
- public float lowly;
- public float lowry;
- public int toplid;
- public int toprid;
- public int lowlid;
- public int lowrid;
- public UVs(){
- toplx = 0.0f;
- toprx = 0.0f;
- lowlx = 0.0f;
- lowrx = 0.0f;
- toply = 0.0f;
- topry = 0.0f;
- lowly = 0.0f;
- lowry = 0.0f;
- toplid = 0;
- toprid = 0;
- lowlid = 0;
- lowrid = 0;
- }
- }
- public List<UVs> UVSet = new List<UVs>();
- [MenuItem ("BDC Editors/UV Getter")]
- public static void ShowWindow () {
- EditorWindow.GetWindow(typeof(Editorfiller_TowerUVs));
- }
- // Use this for initialization
- void OnGUI(){
- gsAlterQuest.normal.background = MakeTex(1, 1, new Color(1.0f, 1.0f, 1.0f, 0.1f));
- Towermodel = EditorGUILayout.ObjectField(Towermodel, typeof(GameObject), true) as GameObject;
- GUILayout.BeginHorizontal();
- GUILayout.Label("Dateiname (ohne Endung): ");
- dateiname = GUILayout.TextField(dateiname);
- GUILayout.EndHorizontal();
- GUILayout.BeginHorizontal();
- GUILayout.Label("Vertice pro Reihe: ");
- ein = EditorGUILayout.IntField(ein);
- GUILayout.EndHorizontal();
- GUILayout.Label("Listengröße: " + UVSet.Count);
- scrollview1 = GUILayout.BeginScrollView(scrollview1);
- for(ain=0; ain<UVSet.Count; ain++){
- GUILayout.BeginHorizontal(gsAlterQuest);
- GUILayout.Label("Quad ID: " + ain);
- GUILayout.BeginVertical();
- GUILayout.Label("UV TopL: " + UVSet[ain].toplid + " >> " + UVSet[ain].toplx + "/" + UVSet[ain].toply);
- GUILayout.Label("UV LowL: " + UVSet[ain].lowlid + " >> " + UVSet[ain].lowlx + "/" + UVSet[ain].lowly);
- GUILayout.EndVertical();
- GUILayout.BeginVertical();
- GUILayout.Label("UV TopR: " + UVSet[ain].toprid + " >> " + UVSet[ain].toprx + "/" + UVSet[ain].topry);
- GUILayout.Label("UV LowR: " + UVSet[ain].lowrid + " >> " + UVSet[ain].lowrx + "/" + UVSet[ain].lowry);
- GUILayout.EndVertical();
- GUILayout.EndHorizontal();
- GUILayout.Space(4);
- }
- GUILayout.EndScrollView();
- if(GUILayout.Button("Saving")){
- Saveing(dateiname + ".dat");
- }
- if(GUILayout.Button("Loading")){
- UVSet = Loading(dateiname + ".dat");
- }
- if(GUILayout.Button("Clearing")){
- UVSet = new List<UVs>();
- cin = 0;
- din = 0;
- fin = 1;
- for(bin=0; bin<Towermodel.GetComponent<MeshFilter>().sharedMesh.vertexCount/4; bin++){
- UVSet.Add(new UVs());
- if(UVSet[bin] != null){
- UVSet[bin].toplid = cin;
- din = cin+ein;
- cin += 1;
- UVSet[bin].toprid = cin;
- UVSet[bin].lowlid = din;
- UVSet[bin].lowrid = din+1;
- fin += 1;
- if(fin == ein){
- cin += 1;
- fin = 1;
- }
- }
- }
- }
- if(GUILayout.Button("Set Null Room")){
- for(bin=0; bin<UVSet.Count; bin++){
- if(UVSet[bin] != null){
- UVSet[bin].toplx = 0.0f;
- UVSet[bin].toply = 1.0f;
- UVSet[bin].toprx = 0.0625f;
- UVSet[bin].topry = 1.0f;
- UVSet[bin].lowlx = 0.0f;
- UVSet[bin].lowly = 1.0f - 0.0390625f;
- UVSet[bin].lowrx = 0.0625f;
- UVSet[bin].lowry = 1.0f - 0.0390625f;
- }
- Towermodel.GetComponent<MeshFilter>().sharedMesh.uv[UVSet[bin].toplid].x = UVSet[bin].toplx;
- Towermodel.GetComponent<MeshFilter>().sharedMesh.uv[UVSet[bin].toplid].y = UVSet[bin].toply;
- Towermodel.GetComponent<MeshFilter>().sharedMesh.uv[UVSet[bin].toprid].x = UVSet[bin].toprx;
- Towermodel.GetComponent<MeshFilter>().sharedMesh.uv[UVSet[bin].toprid].y = UVSet[bin].topry;
- Towermodel.GetComponent<MeshFilter>().sharedMesh.uv[UVSet[bin].lowlid].x = UVSet[bin].lowlx;
- Towermodel.GetComponent<MeshFilter>().sharedMesh.uv[UVSet[bin].lowlid].y = UVSet[bin].lowly;
- Towermodel.GetComponent<MeshFilter>().mesh.uv[UVSet[bin].lowrid].x = UVSet[bin].lowrx;
- Towermodel.GetComponent<MeshFilter>().sharedMesh.uv[UVSet[bin].lowrid].y = UVSet[bin].lowry;
- Debug.Log("Changed Room: " + bin);
- }
- }
- }
- private Texture2D MakeTex(int width, int height, Color col)
- {
- Color[] pix = new Color[width*height];
- for(int i = 0; i < pix.Length; i++)
- pix[i] = col;
- Texture2D result = new Texture2D(width, height);
- result.SetPixels(pix);
- result.Apply();
- return result;
- }
- private void Saveing(string filename){
- BinaryFormatter formatter = new BinaryFormatter();
- using (FileStream fs = new FileStream(filename, FileMode.OpenOrCreate))
- {
- formatter.Serialize(fs, UVSet);
- fs.Close();
- }
- Debug.LogError("UVs GESPEICHERT");
- }
- private List<UVs> Loading(string filename)
- {
- BinaryFormatter formatter = new BinaryFormatter();
- using (FileStream fs = new FileStream(filename, FileMode.Open))
- {
- List<UVs> result = formatter.Deserialize(fs) as List<UVs>;
- fs.Close();
- return result;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement