mirror of
https://github.com/maxartz15/TextureCombiner.git
synced 2025-06-27 12:46:05 +02:00
Init.
P4 -> GitHub sync.
This commit is contained in:
72
Assets/Scripts/TextureHandlers/TextureHandlerWeb.cs
Normal file
72
Assets/Scripts/TextureHandlers/TextureHandlerWeb.cs
Normal file
@ -0,0 +1,72 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
#if UNITY_WEBGL
|
||||
using System.Text;
|
||||
using System.Runtime.InteropServices;
|
||||
#endif
|
||||
|
||||
namespace TextureCombiner
|
||||
{
|
||||
public class TextureHandlerWeb : TextureHandler
|
||||
{
|
||||
#if UNITY_WEBGL
|
||||
protected override void OnEnable()
|
||||
{
|
||||
base.OnEnable();
|
||||
}
|
||||
|
||||
protected override void OnDisable()
|
||||
{
|
||||
base.OnDisable();
|
||||
}
|
||||
|
||||
protected override void Load()
|
||||
{
|
||||
UploadFile(this.gameObject.name, "OnLoadTexturesWWW", ".png, .jpg, .jpeg", true);
|
||||
}
|
||||
|
||||
public void OnLoadTexturesWWW(string path)
|
||||
{
|
||||
string[] paths = path.Split(',');
|
||||
StartCoroutine(LoadTexturesWWW(paths));
|
||||
}
|
||||
|
||||
public IEnumerator LoadTexturesWWW(string[] paths)
|
||||
{
|
||||
if (paths.Length != 0)
|
||||
{
|
||||
foreach (string p in paths)
|
||||
{
|
||||
Debug.Log(p);
|
||||
|
||||
// Load Image.
|
||||
var loader = new WWW(p);
|
||||
yield return loader;
|
||||
m_textureCombiner.LoadTextureSlot(loader.texture);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void OnSaveTextureWWW()
|
||||
{
|
||||
Debug.Log("OnSaveTextureWWW");
|
||||
}
|
||||
|
||||
[DllImport("__Internal")]
|
||||
private static extern void UploadFile(string gameObjectName, string methodName, string filter, bool multiple);
|
||||
[DllImport("__Internal")]
|
||||
private static extern void DownloadFile(string gameObjectName, string methodName, string filename, byte[] byteArray, int byteArraySize);
|
||||
|
||||
protected override void Save(string name)
|
||||
{
|
||||
base.Save(name);
|
||||
}
|
||||
|
||||
protected override void SaveTexture(string path, byte[] bytes)
|
||||
{
|
||||
DownloadFile(this.gameObject.name, "OnSaveTextureWWW", path, bytes, bytes.Length);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
11
Assets/Scripts/TextureHandlers/TextureHandlerWeb.cs.meta
Normal file
11
Assets/Scripts/TextureHandlers/TextureHandlerWeb.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 978cb2b8bd47605408384d0375fe2e82
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
114
Assets/Scripts/TextureHandlers/TextureHandlerWin.cs
Normal file
114
Assets/Scripts/TextureHandlers/TextureHandlerWin.cs
Normal file
@ -0,0 +1,114 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
#if UNITY_STANDALONE_WIN
|
||||
using B83.Win32;
|
||||
#endif
|
||||
#if UNITY_STANDALONE
|
||||
using SFB;
|
||||
#endif
|
||||
|
||||
namespace TextureCombiner
|
||||
{
|
||||
public class TextureHandlerWin : TextureHandler
|
||||
{
|
||||
#if UNITY_STANDALONE
|
||||
protected override void OnEnable()
|
||||
{
|
||||
#if UNITY_STANDALONE_WIN && !UNITY_EDITOR
|
||||
UnityDragAndDropHook.InstallHook();
|
||||
UnityDragAndDropHook.OnDroppedFiles += LoadDropPaths;
|
||||
#endif
|
||||
|
||||
base.OnEnable();
|
||||
}
|
||||
|
||||
protected override void OnDisable()
|
||||
{
|
||||
#if UNITY_STANDALONE_WIN && !UNITY_EDITOR
|
||||
UnityDragAndDropHook.OnDroppedFiles -= LoadDropPaths;
|
||||
UnityDragAndDropHook.UninstallHook();
|
||||
#endif
|
||||
|
||||
base.OnDisable();
|
||||
}
|
||||
|
||||
protected override void Load()
|
||||
{
|
||||
// Open file with filter
|
||||
var extensions = new[]
|
||||
{
|
||||
new ExtensionFilter("Image Files", "png", "jpg", "jpeg" )
|
||||
};
|
||||
|
||||
StandaloneFileBrowser.OpenFilePanelAsync("Open File", "", extensions, true, LoadPaths);
|
||||
}
|
||||
|
||||
#if UNITY_STANDALONE_WIN && !UNITY_EDITOR
|
||||
private void LoadDropPaths(List<string> paths, POINT aPos)
|
||||
{
|
||||
List<string> outPaths = new List<string>();
|
||||
|
||||
foreach (string p in paths)
|
||||
{
|
||||
var fi = new System.IO.FileInfo(p);
|
||||
var ext = fi.Extension.ToLower();
|
||||
if (ext == ".png" || ext == ".jpg" || ext == ".jpeg")
|
||||
{
|
||||
outPaths.Add(p);
|
||||
}
|
||||
}
|
||||
|
||||
if(outPaths.Count > 0)
|
||||
{
|
||||
LoadPaths(outPaths.ToArray());
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
private void LoadPaths(string[] paths)
|
||||
{
|
||||
if(paths.Length != 0)
|
||||
{
|
||||
LoadTextures(paths);
|
||||
}
|
||||
}
|
||||
|
||||
private void LoadTextures(string[] paths)
|
||||
{
|
||||
if(paths.Length != 0)
|
||||
{
|
||||
foreach (string p in paths)
|
||||
{
|
||||
Debug.Log(p);
|
||||
|
||||
// Load Image.
|
||||
var bytes = System.IO.File.ReadAllBytes(p);
|
||||
Texture2D texture = new Texture2D(2, 2);
|
||||
texture.hideFlags = HideFlags.HideAndDontSave;
|
||||
texture.LoadImage(bytes);
|
||||
texture.Apply();
|
||||
|
||||
m_textureCombiner.LoadTextureSlot(texture);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected override void Save(string name)
|
||||
{
|
||||
// Open file with filter
|
||||
var extensions = new[]
|
||||
{
|
||||
new ExtensionFilter("Image Files", "png")
|
||||
};
|
||||
|
||||
StandaloneFileBrowser.SaveFilePanelAsync("Save file", "", name, extensions, base.Save);
|
||||
}
|
||||
|
||||
protected override void SaveTexture(string path, byte[] bytes)
|
||||
{
|
||||
System.IO.File.WriteAllBytes(path, bytes);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
11
Assets/Scripts/TextureHandlers/TextureHandlerWin.cs.meta
Normal file
11
Assets/Scripts/TextureHandlers/TextureHandlerWin.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1a52e2fdc38fe1f47ba34b6f5818afca
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Reference in New Issue
Block a user