public bool GetFileResolution() { if (!TC.FileExists(path)) { return(false); } long length = TC.GetFileLength(path); GetResolutionFromLength(length); return(true); }
void Open() { TC_Settings settings = TC_Settings.instance; string folder = settings.lastPath; if (!folder.Contains(Application.dataPath)) { folder = ""; } if (folder == "") { folder = Application.dataPath + TC.installPath.Replace("Assets", "") + "/Examples/Presets/TerrainLayer"; } string path = EditorUtility.OpenFilePanel("Open TerrainComposer2 project", folder, "prefab"); if (path.Length != 0) { settings.lastPath = TC.GetPath(path); string filePath = TC.GetAssetDatabasePath(path); if (TC.FileExists(filePath)) { GameObject go = Instantiate(AssetDatabase.LoadAssetAtPath(filePath, typeof(GameObject))) as GameObject; if (go != null) { go.transform.hideFlags = HideFlags.HideInInspector; TC_TerrainLayer terrainLayer = go.GetComponent <TC_TerrainLayer>(); if (terrainLayer != null) { go.transform.parent = TC_Generate.instance.transform.parent; DestroyImmediate(TC_Area2D.current.terrainLayer.gameObject); TC_Area2D.current.terrainLayer = terrainLayer; DebugMode(); TC.AddMessage(TC.GetFileName(path) + " is loaded succesfully."); } else { TC.AddMessage("This is not a TerrainLayer prefab."); DestroyImmediate(go); } } } else { TC.AddMessage("Can't find path."); } } }
public void LoadRawImage(string path) { this.path = path; string fullPath = Application.dataPath.Replace("Assets", "/") + path; // Debug.Log(fullPath); if (tex != null) { return; } #if UNITY_EDITOR if (!isResourcesFolder) { if (!TC.FileExists(fullPath)) { return; } } #endif TC_Reporter.Log("Load Raw file " + fullPath); // Debug.Log(bytes.Length); byte[] bytes = null; if (isResourcesFolder) { // Debug.Log("LoadRawImage " + path); TextAsset textAsset = Resources.Load <TextAsset>(path); if (textAsset != null) { bytes = textAsset.bytes; } else { Debug.Log("Can't find file"); } } else { #if !UNITY_WEBPLAYER bytes = File.ReadAllBytes(fullPath); #else // TC.AddMessage("You are in Webplayer build mode, loading from disk is protected in this mode and stamp textures don't work.\nThis will be fixed.\n\nFor now another build mode in needed.", 0, 5); WWW request = new WWW("file:///" + fullPath); while (!request.isDone) { } if (request.error != null) { TC.AddMessage(request.error); } bytes = request.bytes; #endif } if (bytes == null) { return; } if (bytes.Length == 0) { return; } GetResolutionFromLength(bytes.Length); tex = new Texture2D(resolution.x, resolution.y, TextureFormat.R16, false); tex.hideFlags = HideFlags.DontSave; tex.LoadRawTextureData(bytes); tex.Apply(); // For use of mipmap //rt = new RenderTexture(resolution.x, resolution.y, 0, RenderTextureFormat.RFloat, RenderTextureReadWrite.Linear); //rt.useMipMap = true; //rt.hideFlags = HideFlags.DontSave; //rt.Create(); // Graphics.Blit(tex2, rt); // Debug.Log("Load"); }