private static void TakeStageScreenshot(string textureFilePath, Camera stagedCamera, GameObject stagedAsset) { RenderTexture rt = new RenderTexture(textureWidth, textureHeight, 0, RenderTextureFormat.ARGB32); RenderTexture.active = rt; stagedCamera.targetTexture = rt; Texture2D screenShot = new Texture2D(textureWidth, textureHeight, TextureFormat.ARGB32, false); stagedCamera.Render(); screenShot.ReadPixels(new Rect(0, 0, textureWidth, textureHeight), 0, 0); for (int x = 0; x < textureWidth; x++) { for (int y = 0; y < textureHeight; y++) { var pixel = screenShot.GetPixel(x, y); if (pixel.r == Color.magenta.r && pixel.g == Color.magenta.g && pixel.b == Color.magenta.b) { screenShot.SetPixel(x, y, new Color(1.0f, 1.0f, 1.0f, 0.0f)); } } } screenShot.alphaIsTransparency = true; screenShot.Apply(); var bytes = screenShot.EncodeToPNG(); RenderTexture.active = null; EditorWindow.DestroyImmediate(screenShot); File.WriteAllBytes(textureFilePath, bytes); stagedCamera.targetTexture = null; RenderTexture.active = null; }
public static void CleanUpRender3DAssets() { AssetDatabase.Refresh(); var temp = GameObject.Find(APGlobals.CameraRender3D); if (temp) { EditorWindow.DestroyImmediate(temp); } temp = GameObject.Find(APGlobals.StageRender3D); if (temp) { EditorWindow.DestroyImmediate(temp); } temp = GameObject.Find(APGlobals.LightMainRender3D); if (temp) { EditorWindow.DestroyImmediate(temp); } temp = GameObject.Find(APGlobals.LightSubRender3D); if (temp) { EditorWindow.DestroyImmediate(temp); } temp = GameObject.Find(APGlobals.LightSunRender3D); if (temp) { EditorWindow.DestroyImmediate(temp); } }
/// <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); }
private static void Open() { if (m_Instance != null) { EditorWindow.DestroyImmediate(m_Instance); } EditorApplication.isPlaying = true; m_Instance = EditorWindow.GetWindow <TerrainMakerEditorWindow>("地形生成器"); }
static private void OpenWindow() { if (null != sInstance) { EditorWindow.DestroyImmediate(sInstance); //sInstance.Close(); sInstance = null; } sInstance = EditorWindow.GetWindow <BindingWindow>("绑定窗口 Binding Window", typeof(EditorWindow).Assembly.GetType("UnityEditor.InspectorWindow")); }
void ForceClose() { if (_closing) { return; } _closing = true; Close(); EditorWindow.DestroyImmediate(this); }
List <string> GetUseInDirect(string str, string key) { // Debug.Log("Direct:"+str); List <string> strs = new List <string>(); string[] fs = Directory.GetFiles(str); foreach (string s in fs) { // Debug.Log("file:"+s); if (s.IndexOf(".prefab") != -1 && s.IndexOf(".meta") == -1) { int start = s.LastIndexOf('/') + 1; int len = s.LastIndexOf(".prefab") - start; string name = s.Substring(start, len); UnityEngine.Object obj = Resources.Load(name); //GameObject.Instantiate(Resources.Load(name)) as GameObject; if (obj != null) { GameObject go = GameObject.Instantiate(obj) as GameObject; if (go != null) { // go.transform.parent = NGUIEditorTools.SelectedRoot(true).transform; SetChildrenActive(go, true); if (CheckLanguageInPrefab(go, key)) { strs.Add(s); } // Object.Destroy(go,0.0f); // go.transform.parent = null; EditorWindow.DestroyImmediate(go); } } } } string[] dirs = Directory.GetDirectories(str); foreach (string s in dirs) { if (s.IndexOf(".svn") == -1) { List <string> tem = GetUseInDirect(s, key); foreach (string ss in tem) { strs.Add(ss); } } } return(strs); }
public static void ImportCode(Type t) { if (t.BaseType != typeof(UFWindow)) { throw new Exception("Specified type is not derived from 'UFWindow'! - " + t.Name); } current = new UFProject(); current.Namespace = t.Namespace; current.ClassName = t.Name; var window = EditorWindow.CreateInstance(t) as UFWindow; current.Controls.AddRange(window.Controls); current.Controls.ForEach(child => child.RefleshHierarchy()); EditorWindow.DestroyImmediate(window); }
public static Texture2D CreateTextureFromCamera(APData assetData, ref bool hasMadeAnIconRenderAsset) { string fixedName = assetData.name.Replace('/', '_'); fixedName = fixedName.Replace('.', '_'); var textureFilePath = CreateFileDirectory(fixedName); var foundScreenShot = FindTakenScreenshot(fixedName, textureFilePath); if (foundScreenShot) { return(foundScreenShot); } else { hasMadeAnIconRenderAsset = true; var stagedContainer = CreateStage(); var stagedCamera = CreateStageCamera(stagedContainer); var stagedAsset = CreateStagedAsset(assetData, stagedContainer); CreateStageLightMain(stagedContainer); CreateStageLightSub(stagedContainer); CreateStageLightSun(stagedContainer); FocusStageCameraOnAsset(stagedCamera, stagedAsset, stagedContainer); TakeStageScreenshot(textureFilePath, stagedCamera, stagedAsset); AssetDatabase.ImportAsset(textureFilePath); EditorWindow.DestroyImmediate(stagedAsset); return(null); } }
/// <summary> /// Actualiza un mapa dado su path /// </summary> /// <param name="Path">Path del mapa (scene)</param> public void updateMap(Map aux) { GameObject MapObj = GameObject.Find("Map"); GameObject [] List1 = GameObject.FindGameObjectsWithTag("RPG-MAPOBJECT"); GameObject[] List2 = GameObject.FindGameObjectsWithTag("RPG-CORE"); if (this.Data.Width < aux.Data.Width || this.Data.Heigth < aux.Data.Heigth) { if (this.Data.Width < aux.Data.Width) { aux.Data.Width = this.Data.Width; } if (this.Data.Heigth < aux.Data.Heigth) { aux.Data.Heigth = this.Data.Heigth; } foreach (var i in List1) { Transform position = i.GetComponent <Transform>(); if ((position.localPosition.x > this.Data.Width - 1) || position.localPosition.y > this.Data.Heigth - 1) { DestroyImmediate(i); } } foreach (var i in List2) { Transform position = i.GetComponent <Transform>(); if (position.localPosition.x > this.Data.Width - 1 || position.localPosition.y > this.Data.Heigth - 1) { DestroyImmediate(i); } } } if (this.Data.Width > aux.Data.Width) { 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 int x = aux.Data.Width; for (int i = x; i < this.Data.Width; i++) { for (int j = 0; j < aux.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")); } } aux.Data.Width = this.Data.Width; } if (this.Data.Heigth > aux.Data.Heigth) { 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 int y = aux.Data.Heigth; for (int i = 0; i < aux.Data.Width; i++) { for (int j = y; j < this.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")); } } } if (this.Data.Heigth > aux.Data.Heigth && this.Data.Width > aux.Data.Width) { 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 Vector2 position = new Vector2(this.Data.Heigth - 1, this.Data.Width - 1); GameObject clone = new GameObject(); if ((this.Data.Width - 1 + this.Data.Heigth - 1) % 2 == 0) { clone = EditorWindow.Instantiate(prefab, position, Quaternion.identity) as GameObject; // Agrega un objeto nuevo a la scene. } else { clone = EditorWindow.Instantiate(prefab2, position, Quaternion.identity) as GameObject; } clone.tag = "RPG-CORE"; clone.transform.parent = MapObj.transform; EditorWindow.DestroyImmediate(GameObject.Find("New Game Object")); } EditorWindow.DestroyImmediate(GameObject.Find("New Game Object")); 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)(this.Data.Width - 1) / 2, (float)(this.Data.Heigth - 1) / 2, -10); // Posiciona la camara en el centro del mapa DestroyImmediate(GameObject.Find("BackgroundAudio")); if (this.Data.Background != null) { Audio audio = new Audio("BackgroundAudio"); audio.CreateAudioSource(this.Data.Background); audio.gameobject.transform.parent = MapObj.transform; } EditorApplication.SaveScene(); }