You've already forked UniversalViewer
fixes
This commit is contained in:
6
Assets/Scripts/ModelViewerBase/Containers/IAnimated.cs
Normal file
6
Assets/Scripts/ModelViewerBase/Containers/IAnimated.cs
Normal file
@@ -0,0 +1,6 @@
|
||||
using UnityEngine;
|
||||
|
||||
public interface IAnimated
|
||||
{
|
||||
public Animator GetAnimator();
|
||||
}
|
||||
11
Assets/Scripts/ModelViewerBase/Containers/IAnimated.cs.meta
Normal file
11
Assets/Scripts/ModelViewerBase/Containers/IAnimated.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 14fe157a3aea9784d892f9bc75881dc9
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -169,7 +169,7 @@ public class ObjectContainer : MonoBehaviour, IKeyframeSetter
|
||||
public virtual void SetKeyframe(int frameNum = -1)
|
||||
{
|
||||
if (DoNotSave || !_setKeyframe) return;
|
||||
Debug.Log("Setting frame for " + name);
|
||||
//Debug.Log("Setting frame for " + name);
|
||||
//if (Frames.Count == 0) SetDefaultFrame();
|
||||
if (frameNum == -1) frameNum = TimelineController.Instance.CurrentFrame;
|
||||
|
||||
|
||||
@@ -11,187 +11,187 @@ using UnityEngine.Networking;
|
||||
|
||||
public class ModelViewerDownloader
|
||||
{
|
||||
public static string UrlBase = "";
|
||||
public static string SaveLocation = "/idbfs/ModelViewer/";
|
||||
// public static string UrlBase = "";
|
||||
// public static string SaveLocation = "/idbfs/ModelViewer/";
|
||||
|
||||
public static ModelViewerDownloader Instance;
|
||||
public bool SyncRequired;
|
||||
// public static ModelViewerDownloader Instance;
|
||||
// public bool SyncRequired;
|
||||
|
||||
public ModelViewerDownloader() : this(UrlBase, "/idbfs/ModelViewer/") { }
|
||||
// public ModelViewerDownloader() : this(UrlBase, "/idbfs/ModelViewer/") { }
|
||||
|
||||
public ModelViewerDownloader(string baseUrl, string saveLocation)
|
||||
{
|
||||
UrlBase = baseUrl;
|
||||
SaveLocation = saveLocation;
|
||||
ModelViewerMain.GetInstance().StartCoroutine(Loop());
|
||||
}
|
||||
// public ModelViewerDownloader(string baseUrl, string saveLocation)
|
||||
// {
|
||||
// UrlBase = baseUrl;
|
||||
// SaveLocation = saveLocation;
|
||||
// ModelViewerMain.GetInstance().StartCoroutine(Loop());
|
||||
// }
|
||||
|
||||
public class DownloadTask
|
||||
{
|
||||
public string Name;
|
||||
public bool Redownload = false;
|
||||
public bool Finished = false;
|
||||
public bool Success = false;
|
||||
public int Priority = 0;
|
||||
public string ResultText;
|
||||
public byte[] ResultBytes;
|
||||
public System.Action OnDownloadSuccess;
|
||||
// public class DownloadTask
|
||||
// {
|
||||
// public string Name;
|
||||
// public bool Redownload = false;
|
||||
// public bool Finished = false;
|
||||
// public bool Success = false;
|
||||
// public int Priority = 0;
|
||||
// public string ResultText;
|
||||
// public byte[] ResultBytes;
|
||||
// public System.Action OnDownloadSuccess;
|
||||
|
||||
public DownloadTask(string name, int priority, bool redownload)
|
||||
{
|
||||
Name = name;
|
||||
Priority = priority;
|
||||
Redownload = redownload;
|
||||
}
|
||||
}
|
||||
// public DownloadTask(string name, int priority, bool redownload)
|
||||
// {
|
||||
// Name = name;
|
||||
// Priority = priority;
|
||||
// Redownload = redownload;
|
||||
// }
|
||||
// }
|
||||
|
||||
private static List<DownloadTask> _downloadRunning = new List<DownloadTask>();
|
||||
private static List<DownloadTask> _downloadQueue = new List<DownloadTask>();
|
||||
// private static List<DownloadTask> _downloadRunning = new List<DownloadTask>();
|
||||
// private static List<DownloadTask> _downloadQueue = new List<DownloadTask>();
|
||||
|
||||
public IEnumerator Loop()
|
||||
{
|
||||
float lastSync = 5;
|
||||
while (true)
|
||||
{
|
||||
if(_downloadQueue.Count > 0)
|
||||
{
|
||||
_downloadRunning.AddRange(_downloadQueue);
|
||||
_downloadRunning = _downloadRunning.OrderByDescending(d=>d.Priority).ToList();
|
||||
_downloadQueue.Clear();
|
||||
}
|
||||
if(_downloadRunning.Count > 0)
|
||||
{
|
||||
var fileToDownload = _downloadRunning[0];
|
||||
_downloadRunning.RemoveAt(0);
|
||||
yield return DownloadFile(fileToDownload);
|
||||
if(!_downloadRunning.Any() && !_downloadQueue.Any())
|
||||
{
|
||||
SyncRequired = true;
|
||||
lastSync = 0;
|
||||
}
|
||||
}
|
||||
if(SyncRequired)
|
||||
{
|
||||
lastSync += Time.deltaTime;
|
||||
if(lastSync >= 5)
|
||||
{
|
||||
CommitChanges();
|
||||
}
|
||||
}
|
||||
yield return 0;
|
||||
}
|
||||
}
|
||||
// public IEnumerator Loop()
|
||||
// {
|
||||
// float lastSync = 5;
|
||||
// while (true)
|
||||
// {
|
||||
// if(_downloadQueue.Count > 0)
|
||||
// {
|
||||
// _downloadRunning.AddRange(_downloadQueue);
|
||||
// _downloadRunning = _downloadRunning.OrderByDescending(d=>d.Priority).ToList();
|
||||
// _downloadQueue.Clear();
|
||||
// }
|
||||
// if(_downloadRunning.Count > 0)
|
||||
// {
|
||||
// var fileToDownload = _downloadRunning[0];
|
||||
// _downloadRunning.RemoveAt(0);
|
||||
// yield return DownloadFile(fileToDownload);
|
||||
// if(!_downloadRunning.Any() && !_downloadQueue.Any())
|
||||
// {
|
||||
// SyncRequired = true;
|
||||
// lastSync = 0;
|
||||
// }
|
||||
// }
|
||||
// if(SyncRequired)
|
||||
// {
|
||||
// lastSync += Time.deltaTime;
|
||||
// if(lastSync >= 5)
|
||||
// {
|
||||
// CommitChanges();
|
||||
// }
|
||||
// }
|
||||
// yield return 0;
|
||||
// }
|
||||
// }
|
||||
|
||||
public static IEnumerator WaitForDownload(string name, int priority = 0, bool redownload = false, System.Action<string[]> lines = null, System.Action<byte[]> bytes = null, System.Action<string> text = null, System.Action onDownloadSuccess = null)
|
||||
{
|
||||
var task = _downloadQueue.Concat(_downloadRunning).FirstOrDefault(t => t.Name == name);
|
||||
// public static IEnumerator WaitForDownload(string name, int priority = 0, bool redownload = false, System.Action<string[]> lines = null, System.Action<byte[]> bytes = null, System.Action<string> text = null, System.Action onDownloadSuccess = null)
|
||||
// {
|
||||
// var task = _downloadQueue.Concat(_downloadRunning).FirstOrDefault(t => t.Name == name);
|
||||
|
||||
if(task == null)
|
||||
{
|
||||
task = new DownloadTask(name, priority, redownload);
|
||||
task.OnDownloadSuccess = onDownloadSuccess;
|
||||
_downloadQueue.Add(task);
|
||||
}
|
||||
// if(task == null)
|
||||
// {
|
||||
// task = new DownloadTask(name, priority, redownload);
|
||||
// task.OnDownloadSuccess = onDownloadSuccess;
|
||||
// _downloadQueue.Add(task);
|
||||
// }
|
||||
|
||||
while (!task.Finished)
|
||||
{
|
||||
yield return 0;
|
||||
}
|
||||
// while (!task.Finished)
|
||||
// {
|
||||
// yield return 0;
|
||||
// }
|
||||
|
||||
lines?.Invoke(task.ResultText.Split('\n').Select(s => s.Trim()).ToArray());
|
||||
bytes?.Invoke(task.ResultBytes);
|
||||
text?.Invoke(task.ResultText);
|
||||
}
|
||||
// lines?.Invoke(task.ResultText.Split('\n').Select(s => s.Trim()).ToArray());
|
||||
// bytes?.Invoke(task.ResultBytes);
|
||||
// text?.Invoke(task.ResultText);
|
||||
// }
|
||||
|
||||
private IEnumerator DownloadFile(DownloadTask task)
|
||||
{
|
||||
#if UNITY_WEBGL && !UNITY_EDITOR
|
||||
string fileSavePath = $"{SaveLocation}{task.Name}";
|
||||
#else
|
||||
string fileSavePath = Application.persistentDataPath + " /" + task.Name;
|
||||
#endif
|
||||
// private IEnumerator DownloadFile(DownloadTask task)
|
||||
// {
|
||||
//#if UNITY_WEBGL && !UNITY_EDITOR
|
||||
// string fileSavePath = $"{SaveLocation}{task.Name}";
|
||||
//#else
|
||||
// string fileSavePath = Application.persistentDataPath + " /" + task.Name;
|
||||
//#endif
|
||||
|
||||
if (!task.Redownload && LoadFromIdbfs(fileSavePath, out var data))
|
||||
{
|
||||
//Debug.Log("Loaded from " + fileSavePath);
|
||||
task.Success = true;
|
||||
task.ResultText = Encoding.UTF8.GetString(data);
|
||||
task.ResultBytes = data;
|
||||
task.Finished = true;
|
||||
yield break;
|
||||
}
|
||||
// if (!task.Redownload && LoadFromIdbfs(fileSavePath, out var data))
|
||||
// {
|
||||
// //Debug.Log("Loaded from " + fileSavePath);
|
||||
// task.Success = true;
|
||||
// task.ResultText = Encoding.UTF8.GetString(data);
|
||||
// task.ResultBytes = data;
|
||||
// task.Finished = true;
|
||||
// yield break;
|
||||
// }
|
||||
|
||||
string url = UrlBase + task.Name + (task.Redownload ? "?time=" + DateTime.Now.Ticks.ToString() : "");
|
||||
//var downloadPanel = KFKViewerUI.Instance.DownloadPanel;
|
||||
// string url = UrlBase + task.Name + (task.Redownload ? "?time=" + DateTime.Now.Ticks.ToString() : "");
|
||||
// //var downloadPanel = KFKViewerUI.Instance.DownloadPanel;
|
||||
|
||||
//Msg.Log(url);
|
||||
// //Msg.Log(url);
|
||||
|
||||
using (var www = UnityWebRequest.Get(url))
|
||||
{
|
||||
//downloadPanel.gameObject.SetActive(true);
|
||||
// using (var www = UnityWebRequest.Get(url))
|
||||
// {
|
||||
// //downloadPanel.gameObject.SetActive(true);
|
||||
|
||||
var operation = www.SendWebRequest();
|
||||
// var operation = www.SendWebRequest();
|
||||
|
||||
do
|
||||
{
|
||||
//downloadPanel.SetStatus(task.Name, www.downloadProgress);
|
||||
yield return null;
|
||||
}
|
||||
while (!operation.isDone);
|
||||
// do
|
||||
// {
|
||||
// //downloadPanel.SetStatus(task.Name, www.downloadProgress);
|
||||
// yield return null;
|
||||
// }
|
||||
// while (!operation.isDone);
|
||||
|
||||
if (www.result != UnityWebRequest.Result.Success)
|
||||
{
|
||||
Error.Log(Color.red, www.error);
|
||||
task.Success = false;
|
||||
task.ResultText = "";
|
||||
task.ResultBytes = new byte[0];
|
||||
}
|
||||
else
|
||||
{
|
||||
SaveToIdbfs(fileSavePath, www.downloadHandler.data);
|
||||
task.OnDownloadSuccess?.Invoke();
|
||||
task.Success = true;
|
||||
task.ResultText = www.downloadHandler.text;
|
||||
task.ResultBytes = www.downloadHandler.data;
|
||||
}
|
||||
}
|
||||
// if (www.result != UnityWebRequest.Result.Success)
|
||||
// {
|
||||
// Error.Log(Color.red, www.error);
|
||||
// task.Success = false;
|
||||
// task.ResultText = "";
|
||||
// task.ResultBytes = new byte[0];
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// SaveToIdbfs(fileSavePath, www.downloadHandler.data);
|
||||
// task.OnDownloadSuccess?.Invoke();
|
||||
// task.Success = true;
|
||||
// task.ResultText = www.downloadHandler.text;
|
||||
// task.ResultBytes = www.downloadHandler.data;
|
||||
// }
|
||||
// }
|
||||
|
||||
//downloadPanel.SetStatus(task.Name, 0);
|
||||
//downloadPanel.gameObject.SetActive(false);
|
||||
// //downloadPanel.SetStatus(task.Name, 0);
|
||||
// //downloadPanel.gameObject.SetActive(false);
|
||||
|
||||
task.Finished = true;
|
||||
}
|
||||
// task.Finished = true;
|
||||
// }
|
||||
|
||||
public static bool LoadFromIdbfs(string name, out byte[] data)
|
||||
{
|
||||
if(File.Exists(name))
|
||||
{
|
||||
data = File.ReadAllBytes(name);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
data = null;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
// public static bool LoadFromIdbfs(string name, out byte[] data)
|
||||
// {
|
||||
// if(File.Exists(name))
|
||||
// {
|
||||
// data = File.ReadAllBytes(name);
|
||||
// return true;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// data = null;
|
||||
// return false;
|
||||
// }
|
||||
// }
|
||||
|
||||
public static void SaveToIdbfs(string path, byte[] data)
|
||||
{
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(path));
|
||||
File.WriteAllBytes(path, data);
|
||||
//Debug.Log("Saved " + path);
|
||||
}
|
||||
// public static void SaveToIdbfs(string path, byte[] data)
|
||||
// {
|
||||
// Directory.CreateDirectory(Path.GetDirectoryName(path));
|
||||
// File.WriteAllBytes(path, data);
|
||||
// //Debug.Log("Saved " + path);
|
||||
// }
|
||||
|
||||
private static void CommitChanges()
|
||||
{
|
||||
Instance.SyncRequired = false;
|
||||
Debug.Log("Database Updated");
|
||||
#if UNITY_WEBGL && !UNITY_EDITOR
|
||||
SyncFiles();
|
||||
#endif
|
||||
}
|
||||
// private static void CommitChanges()
|
||||
// {
|
||||
// Instance.SyncRequired = false;
|
||||
// Debug.Log("Database Updated");
|
||||
//#if UNITY_WEBGL && !UNITY_EDITOR
|
||||
// SyncFiles();
|
||||
//#endif
|
||||
// }
|
||||
|
||||
[DllImport("__Internal")]
|
||||
private static extern void SyncFiles();
|
||||
// [DllImport("__Internal")]
|
||||
// private static extern void SyncFiles();
|
||||
}
|
||||
|
||||
@@ -26,6 +26,9 @@ public class ModelViewerInterface : MonoBehaviour
|
||||
public RectTransform Tooltip;
|
||||
public TMPro.TextMeshProUGUI TooltipText;
|
||||
|
||||
private Vector2 _previousResolution = Vector2.zero;
|
||||
private int _resolutionUpdateCountdown;
|
||||
|
||||
public static ModelViewerInterface GetInstance()
|
||||
{
|
||||
return _mainInstance;
|
||||
@@ -36,6 +39,29 @@ public class ModelViewerInterface : MonoBehaviour
|
||||
return _mainInstance as T;
|
||||
}
|
||||
|
||||
|
||||
protected void Update()
|
||||
{
|
||||
var resolution = new Vector2(Screen.width, Screen.height);
|
||||
if (resolution != _previousResolution)
|
||||
{
|
||||
_previousResolution = resolution;
|
||||
_resolutionUpdateCountdown = 10;
|
||||
}
|
||||
|
||||
if (_resolutionUpdateCountdown > 0)
|
||||
{
|
||||
if (--_resolutionUpdateCountdown == 0)
|
||||
{
|
||||
var draggables = GameObject.FindObjectsOfType<UIElementDragger>();
|
||||
foreach (var draggable in draggables)
|
||||
{
|
||||
draggable.transform.position = draggable.RecalculatePosition(draggable.transform.position);
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void SetTooltip(int index, string tooltip)
|
||||
{
|
||||
var tooltips = GetInstance().TooltipLabels;
|
||||
@@ -45,7 +71,6 @@ public class ModelViewerInterface : MonoBehaviour
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static void ToggleVisible(GameObject go)
|
||||
{
|
||||
ToggleVisible(go, false);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using static UnityEngine.Rendering.VirtualTexturing.Debugging;
|
||||
using UnityEngine.UI;
|
||||
|
||||
[RequireComponent(typeof(CanvasGroup))]
|
||||
public class UIElementDragger : MonoBehaviour, IDragHandler, IEndDragHandler, IPointerDownHandler, IPointerUpHandler
|
||||
@@ -48,12 +49,12 @@ public class UIElementDragger : MonoBehaviour, IDragHandler, IEndDragHandler, IP
|
||||
}
|
||||
}
|
||||
|
||||
private void OnEnable()
|
||||
private void Start()
|
||||
{
|
||||
var handle = HandlePosition.GetComponent<RectTransform>();
|
||||
transform.position = new Vector2(
|
||||
Mathf.Clamp(transform.position.x, 0, Screen.width - handle.rect.width),
|
||||
Mathf.Clamp(transform.position.y, handle.sizeDelta.y, Screen.height));
|
||||
if (Proxy == null)
|
||||
{
|
||||
transform.position = RecalculatePosition(transform.position);
|
||||
}
|
||||
}
|
||||
|
||||
public void SetProxyMode(UIDraggableProxy proxy)
|
||||
@@ -81,18 +82,19 @@ public class UIElementDragger : MonoBehaviour, IDragHandler, IEndDragHandler, IP
|
||||
}
|
||||
else
|
||||
{
|
||||
var canvas = ModelViewerInterface.GetInstance().MainCanvas;
|
||||
var proxyRect = Proxy.transform as RectTransform;
|
||||
var handleRect = HandlePosition.transform as RectTransform;
|
||||
var handleOffset = handleRect.sizeDelta.y * Vector3.up;
|
||||
var handleOffset = handleRect.sizeDelta.y * canvas.scaleFactor * Vector3.up;
|
||||
if (Proxy.GetComponentInParent<UIToolbar>().Layout == UIToolbar.LayoutMode.Vertical)
|
||||
{
|
||||
//anchor to top-right of button
|
||||
transform.position = proxyRect.position + proxyRect.sizeDelta.x * Vector3.right + handleOffset;
|
||||
transform.position = proxyRect.position + proxyRect.sizeDelta.x * canvas.scaleFactor * Vector3.right + handleOffset;
|
||||
}
|
||||
else
|
||||
{
|
||||
//anchor to bottom-left of button
|
||||
transform.position = proxyRect.position + proxyRect.sizeDelta.y * Vector3.up - handleOffset;
|
||||
transform.position = proxyRect.position + proxyRect.sizeDelta.y * canvas.scaleFactor * Vector3.up - handleOffset;
|
||||
}
|
||||
gameObject.SetActive(true);
|
||||
}
|
||||
@@ -126,11 +128,7 @@ public class UIElementDragger : MonoBehaviour, IDragHandler, IEndDragHandler, IP
|
||||
}
|
||||
case DragAction.Position:
|
||||
{
|
||||
var handle = HandlePosition.GetComponent<RectTransform>();
|
||||
|
||||
transform.position = new Vector2(
|
||||
Mathf.Clamp(Input.mousePosition.x + mouseOffset.x, 0, Screen.width - handle.rect.width),
|
||||
Mathf.Clamp(Input.mousePosition.y + mouseOffset.y, handle.sizeDelta.y, Screen.height));
|
||||
transform.position = RecalculatePosition((Vector2)Input.mousePosition + mouseOffset);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -184,4 +182,16 @@ public class UIElementDragger : MonoBehaviour, IDragHandler, IEndDragHandler, IP
|
||||
{
|
||||
OnEndDrag(null);
|
||||
}
|
||||
|
||||
public Vector2 RecalculatePosition(Vector2 pos)
|
||||
{
|
||||
var handle = HandlePosition.transform as RectTransform;
|
||||
var tsf = transform as RectTransform;
|
||||
var canvas = ModelViewerInterface.GetInstance().MainCanvas;
|
||||
|
||||
var xPos = Mathf.Clamp(pos.x, 0, Screen.width - tsf.sizeDelta.x * canvas.scaleFactor);
|
||||
var yPos = Mathf.Clamp(pos.y, handle.sizeDelta.y * canvas.scaleFactor, Screen.height);
|
||||
|
||||
return new Vector2 (xPos, yPos);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user