mirror of
https://gitgud.io/AbstractConcept/rimworld-animation-studio.git
synced 2024-08-15 00:43:27 +00:00
Bug fixes (issues #1, 2, 3 and 6)
This commit is contained in:
parent
6b44db7400
commit
518a912ef1
156 changed files with 352 additions and 625 deletions
|
@ -77,14 +77,16 @@ namespace RimWorldAnimationStudio
|
|||
if (siblingIndex != null && siblingCount != null && MoveAnimationTimeline(siblingIndex.Value, delta))
|
||||
{
|
||||
//siblingIndex = Mathf.Clamp(siblingCount.Value + delta, 0, siblingCount.Value - 1);
|
||||
transform.SetSiblingIndex(transform.GetSiblingIndex() + delta);
|
||||
//transform.SetSiblingIndex(transform.GetSiblingIndex() + delta);
|
||||
AnimationController.Instance.ResetAnimationTimeline();
|
||||
AnimationController.Instance.InitializeAnimationTimeline();
|
||||
}
|
||||
}
|
||||
|
||||
public bool MoveAnimationTimeline(int startIndex, int delta)
|
||||
{
|
||||
if (startIndex + delta < 0 || startIndex + delta >= Workspace.animationDef.animationStages[Workspace.stageID].animationClips.Count)
|
||||
{ return false; }
|
||||
{ Debug.Log("Cannot move animation timeline - movement would exceed bounds"); return false; }
|
||||
|
||||
Actor actor = Workspace.animationDef.actors[startIndex];
|
||||
Workspace.animationDef.actors[startIndex] = Workspace.animationDef.actors[startIndex + delta];
|
||||
|
|
|
@ -23,6 +23,7 @@ namespace RimWorldAnimationStudio
|
|||
|
||||
private PawnAnimationClip clip;
|
||||
private PawnKeyframe keyframe;
|
||||
private float dragTimeStart = -1f;
|
||||
|
||||
public void Initialize(AnimationTimeline timeline, int actorID, int keyframeID)
|
||||
{
|
||||
|
@ -47,7 +48,7 @@ namespace RimWorldAnimationStudio
|
|||
keyframe.atTick = (int)value;
|
||||
clip.BuildSimpleCurves();
|
||||
|
||||
AnimationController.Instance.stageTick = keyframe.atTick.Value;
|
||||
//AnimationController.Instance.stageTick = keyframe.atTick.Value;
|
||||
|
||||
timeline.InitiateUpdateOfGhostFrames();
|
||||
}
|
||||
|
@ -104,9 +105,11 @@ namespace RimWorldAnimationStudio
|
|||
|
||||
public void OnBeginDrag(PointerEventData eventData)
|
||||
{
|
||||
AnimationController.Instance.stageTick = keyframe.atTick.Value;
|
||||
//AnimationController.Instance.stageTick = keyframe.atTick.Value;
|
||||
Workspace.actorID = actorID;
|
||||
Workspace.keyframeID = keyframeID;
|
||||
|
||||
dragTimeStart = Time.unscaledTime;
|
||||
}
|
||||
|
||||
public override void OnDrag(PointerEventData eventData)
|
||||
|
@ -114,9 +117,12 @@ namespace RimWorldAnimationStudio
|
|||
if (keyframe.atTick == 1)
|
||||
{ value = 1; return; }
|
||||
|
||||
if (Time.unscaledTime - dragTimeStart < 0.05f) return;
|
||||
|
||||
interactable = true;
|
||||
base.OnDrag(eventData);
|
||||
|
||||
AnimationController.Instance.stageTick = keyframe.atTick.Value;
|
||||
//AnimationController.Instance.stageTick = keyframe.atTick.Value;
|
||||
Workspace.actorID = actorID;
|
||||
}
|
||||
|
||||
|
@ -125,6 +131,7 @@ namespace RimWorldAnimationStudio
|
|||
if (keyframe.atTick == 1)
|
||||
{ value = 1; return; }
|
||||
|
||||
interactable = false;
|
||||
Workspace.Instance.RecordEvent("Keyframe tick");
|
||||
}
|
||||
|
||||
|
|
|
@ -459,7 +459,10 @@ namespace RimWorldAnimationStudio
|
|||
}
|
||||
|
||||
animationClipLengthField.text = newStageWindowSize.ToString();
|
||||
|
||||
Workspace.animationDef.animationStages[Workspace.stageID].stageWindowSize = newStageWindowSize;
|
||||
Workspace.animationDef.animationStages[Workspace.stageID].playTimeTicks = newStageWindowSize * int.Parse(cyclesNormalField.text);
|
||||
Workspace.animationDef.animationStages[Workspace.stageID].playTimeTicksQuick = newStageWindowSize * int.Parse(cyclesFastField.text);
|
||||
|
||||
Workspace.Instance.RecordEvent("Stage length");
|
||||
}
|
||||
|
@ -487,6 +490,7 @@ namespace RimWorldAnimationStudio
|
|||
if (int.TryParse(cyclesNormalField.text, out int cycles))
|
||||
{
|
||||
cycles = cycles <= 0 ? 1 : cycles;
|
||||
cyclesNormalField.text = cycles.ToString();
|
||||
|
||||
Workspace.animationDef.animationStages[Workspace.stageID].playTimeTicks = cycles * Workspace.StageWindowSize;
|
||||
Workspace.animationDef.animationStages[Workspace.stageID].isLooping = cycles > 1;
|
||||
|
|
|
@ -1,8 +0,0 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 5992c02152ca3114bb1120d7350ac998
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -1,13 +0,0 @@
|
|||
using System;
|
||||
|
||||
namespace SFB {
|
||||
public interface IStandaloneFileBrowser {
|
||||
string[] OpenFilePanel(string title, string directory, ExtensionFilter[] extensions, bool multiselect);
|
||||
string[] OpenFolderPanel(string title, string directory, bool multiselect);
|
||||
string SaveFilePanel(string title, string directory, string defaultName, ExtensionFilter[] extensions);
|
||||
|
||||
void OpenFilePanelAsync(string title, string directory, ExtensionFilter[] extensions, bool multiselect, Action<string[]> cb);
|
||||
void OpenFolderPanelAsync(string title, string directory, bool multiselect, Action<string[]> cb);
|
||||
void SaveFilePanelAsync(string title, string directory, string defaultName, ExtensionFilter[] extensions, Action<string> cb);
|
||||
}
|
||||
}
|
|
@ -1,12 +0,0 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 7609f7b6787a54496aa41a3053fcc76a
|
||||
timeCreated: 1483902788
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -1,153 +0,0 @@
|
|||
using System;
|
||||
|
||||
namespace SFB {
|
||||
public struct ExtensionFilter {
|
||||
public string Name;
|
||||
public string[] Extensions;
|
||||
|
||||
public ExtensionFilter(string filterName, params string[] filterExtensions) {
|
||||
Name = filterName;
|
||||
Extensions = filterExtensions;
|
||||
}
|
||||
}
|
||||
|
||||
public class StandaloneFileBrowser {
|
||||
private static IStandaloneFileBrowser _platformWrapper = null;
|
||||
|
||||
static StandaloneFileBrowser() {
|
||||
#if UNITY_STANDALONE_OSX
|
||||
_platformWrapper = new StandaloneFileBrowserMac();
|
||||
#elif UNITY_STANDALONE_WIN
|
||||
_platformWrapper = new StandaloneFileBrowserWindows();
|
||||
#elif UNITY_STANDALONE_LINUX
|
||||
_platformWrapper = new StandaloneFileBrowserLinux();
|
||||
#elif UNITY_EDITOR
|
||||
_platformWrapper = new StandaloneFileBrowserEditor();
|
||||
#endif
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Native open file dialog
|
||||
/// </summary>
|
||||
/// <param name="title">Dialog title</param>
|
||||
/// <param name="directory">Root directory</param>
|
||||
/// <param name="extension">Allowed extension</param>
|
||||
/// <param name="multiselect">Allow multiple file selection</param>
|
||||
/// <returns>Returns array of chosen paths. Zero length array when cancelled</returns>
|
||||
public static string[] OpenFilePanel(string title, string directory, string extension, bool multiselect) {
|
||||
var extensions = string.IsNullOrEmpty(extension) ? null : new [] { new ExtensionFilter("", extension) };
|
||||
return OpenFilePanel(title, directory, extensions, multiselect);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Native open file dialog
|
||||
/// </summary>
|
||||
/// <param name="title">Dialog title</param>
|
||||
/// <param name="directory">Root directory</param>
|
||||
/// <param name="extensions">List of extension filters. Filter Example: new ExtensionFilter("Image Files", "jpg", "png")</param>
|
||||
/// <param name="multiselect">Allow multiple file selection</param>
|
||||
/// <returns>Returns array of chosen paths. Zero length array when cancelled</returns>
|
||||
public static string[] OpenFilePanel(string title, string directory, ExtensionFilter[] extensions, bool multiselect) {
|
||||
return _platformWrapper.OpenFilePanel(title, directory, extensions, multiselect);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Native open file dialog async
|
||||
/// </summary>
|
||||
/// <param name="title">Dialog title</param>
|
||||
/// <param name="directory">Root directory</param>
|
||||
/// <param name="extension">Allowed extension</param>
|
||||
/// <param name="multiselect">Allow multiple file selection</param>
|
||||
/// <param name="cb">Callback")</param>
|
||||
public static void OpenFilePanelAsync(string title, string directory, string extension, bool multiselect, Action<string[]> cb) {
|
||||
var extensions = string.IsNullOrEmpty(extension) ? null : new [] { new ExtensionFilter("", extension) };
|
||||
OpenFilePanelAsync(title, directory, extensions, multiselect, cb);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Native open file dialog async
|
||||
/// </summary>
|
||||
/// <param name="title">Dialog title</param>
|
||||
/// <param name="directory">Root directory</param>
|
||||
/// <param name="extensions">List of extension filters. Filter Example: new ExtensionFilter("Image Files", "jpg", "png")</param>
|
||||
/// <param name="multiselect">Allow multiple file selection</param>
|
||||
/// <param name="cb">Callback")</param>
|
||||
public static void OpenFilePanelAsync(string title, string directory, ExtensionFilter[] extensions, bool multiselect, Action<string[]> cb) {
|
||||
_platformWrapper.OpenFilePanelAsync(title, directory, extensions, multiselect, cb);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Native open folder dialog
|
||||
/// NOTE: Multiple folder selection doesn't supported on Windows
|
||||
/// </summary>
|
||||
/// <param name="title"></param>
|
||||
/// <param name="directory">Root directory</param>
|
||||
/// <param name="multiselect"></param>
|
||||
/// <returns>Returns array of chosen paths. Zero length array when cancelled</returns>
|
||||
public static string[] OpenFolderPanel(string title, string directory, bool multiselect) {
|
||||
return _platformWrapper.OpenFolderPanel(title, directory, multiselect);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Native open folder dialog async
|
||||
/// NOTE: Multiple folder selection doesn't supported on Windows
|
||||
/// </summary>
|
||||
/// <param name="title"></param>
|
||||
/// <param name="directory">Root directory</param>
|
||||
/// <param name="multiselect"></param>
|
||||
/// <param name="cb">Callback")</param>
|
||||
public static void OpenFolderPanelAsync(string title, string directory, bool multiselect, Action<string[]> cb) {
|
||||
_platformWrapper.OpenFolderPanelAsync(title, directory, multiselect, cb);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Native save file dialog
|
||||
/// </summary>
|
||||
/// <param name="title">Dialog title</param>
|
||||
/// <param name="directory">Root directory</param>
|
||||
/// <param name="defaultName">Default file name</param>
|
||||
/// <param name="extension">File extension</param>
|
||||
/// <returns>Returns chosen path. Empty string when cancelled</returns>
|
||||
public static string SaveFilePanel(string title, string directory, string defaultName , string extension) {
|
||||
var extensions = string.IsNullOrEmpty(extension) ? null : new [] { new ExtensionFilter("", extension) };
|
||||
return SaveFilePanel(title, directory, defaultName, extensions);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Native save file dialog
|
||||
/// </summary>
|
||||
/// <param name="title">Dialog title</param>
|
||||
/// <param name="directory">Root directory</param>
|
||||
/// <param name="defaultName">Default file name</param>
|
||||
/// <param name="extensions">List of extension filters. Filter Example: new ExtensionFilter("Image Files", "jpg", "png")</param>
|
||||
/// <returns>Returns chosen path. Empty string when cancelled</returns>
|
||||
public static string SaveFilePanel(string title, string directory, string defaultName, ExtensionFilter[] extensions) {
|
||||
return _platformWrapper.SaveFilePanel(title, directory, defaultName, extensions);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Native save file dialog async
|
||||
/// </summary>
|
||||
/// <param name="title">Dialog title</param>
|
||||
/// <param name="directory">Root directory</param>
|
||||
/// <param name="defaultName">Default file name</param>
|
||||
/// <param name="extension">File extension</param>
|
||||
/// <param name="cb">Callback")</param>
|
||||
public static void SaveFilePanelAsync(string title, string directory, string defaultName , string extension, Action<string> cb) {
|
||||
var extensions = string.IsNullOrEmpty(extension) ? null : new [] { new ExtensionFilter("", extension) };
|
||||
SaveFilePanelAsync(title, directory, defaultName, extensions, cb);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Native save file dialog async
|
||||
/// </summary>
|
||||
/// <param name="title">Dialog title</param>
|
||||
/// <param name="directory">Root directory</param>
|
||||
/// <param name="defaultName">Default file name</param>
|
||||
/// <param name="extensions">List of extension filters. Filter Example: new ExtensionFilter("Image Files", "jpg", "png")</param>
|
||||
/// <param name="cb">Callback")</param>
|
||||
public static void SaveFilePanelAsync(string title, string directory, string defaultName, ExtensionFilter[] extensions, Action<string> cb) {
|
||||
_platformWrapper.SaveFilePanelAsync(title, directory, defaultName, extensions, cb);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,12 +0,0 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 3c708be74128e4ced9b79eaaf80e8443
|
||||
timeCreated: 1483902788
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -1,56 +0,0 @@
|
|||
#if UNITY_EDITOR
|
||||
|
||||
using System;
|
||||
using UnityEditor;
|
||||
|
||||
namespace SFB {
|
||||
public class StandaloneFileBrowserEditor : IStandaloneFileBrowser {
|
||||
public string[] OpenFilePanel(string title, string directory, ExtensionFilter[] extensions, bool multiselect) {
|
||||
string path = "";
|
||||
|
||||
if (extensions == null) {
|
||||
path = EditorUtility.OpenFilePanel(title, directory, "");
|
||||
}
|
||||
else {
|
||||
path = EditorUtility.OpenFilePanelWithFilters(title, directory, GetFilterFromFileExtensionList(extensions));
|
||||
}
|
||||
|
||||
return string.IsNullOrEmpty(path) ? new string[0] : new[] { path };
|
||||
}
|
||||
|
||||
public void OpenFilePanelAsync(string title, string directory, ExtensionFilter[] extensions, bool multiselect, Action<string[]> cb) {
|
||||
cb.Invoke(OpenFilePanel(title, directory, extensions, multiselect));
|
||||
}
|
||||
|
||||
public string[] OpenFolderPanel(string title, string directory, bool multiselect) {
|
||||
var path = EditorUtility.OpenFolderPanel(title, directory, "");
|
||||
return string.IsNullOrEmpty(path) ? new string[0] : new[] {path};
|
||||
}
|
||||
|
||||
public void OpenFolderPanelAsync(string title, string directory, bool multiselect, Action<string[]> cb) {
|
||||
cb.Invoke(OpenFolderPanel(title, directory, multiselect));
|
||||
}
|
||||
|
||||
public string SaveFilePanel(string title, string directory, string defaultName, ExtensionFilter[] extensions) {
|
||||
var ext = extensions != null ? extensions[0].Extensions[0] : "";
|
||||
var name = string.IsNullOrEmpty(ext) ? defaultName : defaultName + "." + ext;
|
||||
return EditorUtility.SaveFilePanel(title, directory, name, ext);
|
||||
}
|
||||
|
||||
public void SaveFilePanelAsync(string title, string directory, string defaultName, ExtensionFilter[] extensions, Action<string> cb) {
|
||||
cb.Invoke(SaveFilePanel(title, directory, defaultName, extensions));
|
||||
}
|
||||
|
||||
// EditorUtility.OpenFilePanelWithFilters extension filter format
|
||||
private static string[] GetFilterFromFileExtensionList(ExtensionFilter[] extensions) {
|
||||
var filters = new string[extensions.Length * 2];
|
||||
for (int i = 0; i < extensions.Length; i++) {
|
||||
filters[(i * 2)] = extensions[i].Name;
|
||||
filters[(i * 2) + 1] = string.Join(",", extensions[i].Extensions);
|
||||
}
|
||||
return filters;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
|
@ -1,12 +0,0 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 2650af8de2cda46b99b1bc7cf5d30ca5
|
||||
timeCreated: 1483902788
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -1,115 +0,0 @@
|
|||
#if UNITY_STANDALONE_LINUX
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Runtime.InteropServices;
|
||||
using UnityEngine;
|
||||
|
||||
namespace SFB {
|
||||
|
||||
public class StandaloneFileBrowserLinux : IStandaloneFileBrowser {
|
||||
|
||||
private static Action<string[]> _openFileCb;
|
||||
private static Action<string[]> _openFolderCb;
|
||||
private static Action<string> _saveFileCb;
|
||||
|
||||
[UnmanagedFunctionPointer(CallingConvention.StdCall)]
|
||||
public delegate void AsyncCallback(string path);
|
||||
|
||||
[DllImport("StandaloneFileBrowser")]
|
||||
private static extern void DialogInit();
|
||||
[DllImport("StandaloneFileBrowser")]
|
||||
private static extern IntPtr DialogOpenFilePanel(string title, string directory, string extension, bool multiselect);
|
||||
[DllImport("StandaloneFileBrowser")]
|
||||
private static extern void DialogOpenFilePanelAsync(string title, string directory, string extension, bool multiselect, AsyncCallback callback);
|
||||
[DllImport("StandaloneFileBrowser")]
|
||||
private static extern IntPtr DialogOpenFolderPanel(string title, string directory, bool multiselect);
|
||||
[DllImport("StandaloneFileBrowser")]
|
||||
private static extern void DialogOpenFolderPanelAsync(string title, string directory, bool multiselect, AsyncCallback callback);
|
||||
[DllImport("StandaloneFileBrowser")]
|
||||
private static extern IntPtr DialogSaveFilePanel(string title, string directory, string defaultName, string extension);
|
||||
[DllImport("StandaloneFileBrowser")]
|
||||
private static extern void DialogSaveFilePanelAsync(string title, string directory, string defaultName, string extension, AsyncCallback callback);
|
||||
|
||||
public StandaloneFileBrowserLinux()
|
||||
{
|
||||
DialogInit();
|
||||
}
|
||||
|
||||
public string[] OpenFilePanel(string title, string directory, ExtensionFilter[] extensions, bool multiselect) {
|
||||
var paths = Marshal.PtrToStringAnsi(DialogOpenFilePanel(
|
||||
title,
|
||||
directory,
|
||||
GetFilterFromFileExtensionList(extensions),
|
||||
multiselect));
|
||||
return paths.Split((char)28);
|
||||
}
|
||||
|
||||
public void OpenFilePanelAsync(string title, string directory, ExtensionFilter[] extensions, bool multiselect, Action<string[]> cb) {
|
||||
_openFileCb = cb;
|
||||
DialogOpenFilePanelAsync(
|
||||
title,
|
||||
directory,
|
||||
GetFilterFromFileExtensionList(extensions),
|
||||
multiselect,
|
||||
(string result) => { _openFileCb.Invoke(result.Split((char)28)); });
|
||||
}
|
||||
|
||||
public string[] OpenFolderPanel(string title, string directory, bool multiselect) {
|
||||
var paths = Marshal.PtrToStringAnsi(DialogOpenFolderPanel(
|
||||
title,
|
||||
directory,
|
||||
multiselect));
|
||||
return paths.Split((char)28);
|
||||
}
|
||||
|
||||
public void OpenFolderPanelAsync(string title, string directory, bool multiselect, Action<string[]> cb) {
|
||||
_openFolderCb = cb;
|
||||
DialogOpenFolderPanelAsync(
|
||||
title,
|
||||
directory,
|
||||
multiselect,
|
||||
(string result) => { _openFolderCb.Invoke(result.Split((char)28)); });
|
||||
}
|
||||
|
||||
public string SaveFilePanel(string title, string directory, string defaultName, ExtensionFilter[] extensions) {
|
||||
return Marshal.PtrToStringAnsi(DialogSaveFilePanel(
|
||||
title,
|
||||
directory,
|
||||
defaultName,
|
||||
GetFilterFromFileExtensionList(extensions)));
|
||||
}
|
||||
|
||||
public void SaveFilePanelAsync(string title, string directory, string defaultName, ExtensionFilter[] extensions, Action<string> cb) {
|
||||
_saveFileCb = cb;
|
||||
DialogSaveFilePanelAsync(
|
||||
title,
|
||||
directory,
|
||||
defaultName,
|
||||
GetFilterFromFileExtensionList(extensions),
|
||||
(string result) => { _saveFileCb.Invoke(result); });
|
||||
}
|
||||
|
||||
private static string GetFilterFromFileExtensionList(ExtensionFilter[] extensions) {
|
||||
if (extensions == null) {
|
||||
return "";
|
||||
}
|
||||
|
||||
var filterString = "";
|
||||
foreach (var filter in extensions) {
|
||||
filterString += filter.Name + ";";
|
||||
|
||||
foreach (var ext in filter.Extensions) {
|
||||
filterString += ext + ",";
|
||||
}
|
||||
|
||||
filterString = filterString.Remove(filterString.Length - 1);
|
||||
filterString += "|";
|
||||
}
|
||||
filterString = filterString.Remove(filterString.Length - 1);
|
||||
return filterString;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
|
@ -1,3 +0,0 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 5d3a668018554b8a89c3fe12de72b60c
|
||||
timeCreated: 1538067919
|
|
@ -1,119 +0,0 @@
|
|||
#if UNITY_STANDALONE_OSX
|
||||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace SFB {
|
||||
public class StandaloneFileBrowserMac : IStandaloneFileBrowser {
|
||||
private static Action<string[]> _openFileCb;
|
||||
private static Action<string[]> _openFolderCb;
|
||||
private static Action<string> _saveFileCb;
|
||||
|
||||
[UnmanagedFunctionPointer(CallingConvention.StdCall)]
|
||||
public delegate void AsyncCallback(string path);
|
||||
|
||||
[AOT.MonoPInvokeCallback(typeof(AsyncCallback))]
|
||||
private static void openFileCb(string result) {
|
||||
_openFileCb.Invoke(result.Split((char)28));
|
||||
}
|
||||
|
||||
[AOT.MonoPInvokeCallback(typeof(AsyncCallback))]
|
||||
private static void openFolderCb(string result) {
|
||||
_openFolderCb.Invoke(result.Split((char)28));
|
||||
}
|
||||
|
||||
[AOT.MonoPInvokeCallback(typeof(AsyncCallback))]
|
||||
private static void saveFileCb(string result) {
|
||||
_saveFileCb.Invoke(result);
|
||||
}
|
||||
|
||||
[DllImport("StandaloneFileBrowser")]
|
||||
private static extern IntPtr DialogOpenFilePanel(string title, string directory, string extension, bool multiselect);
|
||||
[DllImport("StandaloneFileBrowser")]
|
||||
private static extern void DialogOpenFilePanelAsync(string title, string directory, string extension, bool multiselect, AsyncCallback callback);
|
||||
[DllImport("StandaloneFileBrowser")]
|
||||
private static extern IntPtr DialogOpenFolderPanel(string title, string directory, bool multiselect);
|
||||
[DllImport("StandaloneFileBrowser")]
|
||||
private static extern void DialogOpenFolderPanelAsync(string title, string directory, bool multiselect, AsyncCallback callback);
|
||||
[DllImport("StandaloneFileBrowser")]
|
||||
private static extern IntPtr DialogSaveFilePanel(string title, string directory, string defaultName, string extension);
|
||||
[DllImport("StandaloneFileBrowser")]
|
||||
private static extern void DialogSaveFilePanelAsync(string title, string directory, string defaultName, string extension, AsyncCallback callback);
|
||||
|
||||
public string[] OpenFilePanel(string title, string directory, ExtensionFilter[] extensions, bool multiselect) {
|
||||
var paths = Marshal.PtrToStringAnsi(DialogOpenFilePanel(
|
||||
title,
|
||||
directory,
|
||||
GetFilterFromFileExtensionList(extensions),
|
||||
multiselect));
|
||||
return paths.Split((char)28);
|
||||
}
|
||||
|
||||
public void OpenFilePanelAsync(string title, string directory, ExtensionFilter[] extensions, bool multiselect, Action<string[]> cb) {
|
||||
_openFileCb = cb;
|
||||
DialogOpenFilePanelAsync(
|
||||
title,
|
||||
directory,
|
||||
GetFilterFromFileExtensionList(extensions),
|
||||
multiselect,
|
||||
openFileCb);
|
||||
}
|
||||
|
||||
public string[] OpenFolderPanel(string title, string directory, bool multiselect) {
|
||||
var paths = Marshal.PtrToStringAnsi(DialogOpenFolderPanel(
|
||||
title,
|
||||
directory,
|
||||
multiselect));
|
||||
return paths.Split((char)28);
|
||||
}
|
||||
|
||||
public void OpenFolderPanelAsync(string title, string directory, bool multiselect, Action<string[]> cb) {
|
||||
_openFolderCb = cb;
|
||||
DialogOpenFolderPanelAsync(
|
||||
title,
|
||||
directory,
|
||||
multiselect,
|
||||
openFolderCb);
|
||||
}
|
||||
|
||||
public string SaveFilePanel(string title, string directory, string defaultName, ExtensionFilter[] extensions) {
|
||||
return Marshal.PtrToStringAnsi(DialogSaveFilePanel(
|
||||
title,
|
||||
directory,
|
||||
defaultName,
|
||||
GetFilterFromFileExtensionList(extensions)));
|
||||
}
|
||||
|
||||
public void SaveFilePanelAsync(string title, string directory, string defaultName, ExtensionFilter[] extensions, Action<string> cb) {
|
||||
_saveFileCb = cb;
|
||||
DialogSaveFilePanelAsync(
|
||||
title,
|
||||
directory,
|
||||
defaultName,
|
||||
GetFilterFromFileExtensionList(extensions),
|
||||
saveFileCb);
|
||||
}
|
||||
|
||||
private static string GetFilterFromFileExtensionList(ExtensionFilter[] extensions) {
|
||||
if (extensions == null) {
|
||||
return "";
|
||||
}
|
||||
|
||||
var filterString = "";
|
||||
foreach (var filter in extensions) {
|
||||
filterString += filter.Name + ";";
|
||||
|
||||
foreach (var ext in filter.Extensions) {
|
||||
filterString += ext + ",";
|
||||
}
|
||||
|
||||
filterString = filterString.Remove(filterString.Length - 1);
|
||||
filterString += "|";
|
||||
}
|
||||
filterString = filterString.Remove(filterString.Length - 1);
|
||||
return filterString;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
|
@ -1,12 +0,0 @@
|
|||
fileFormatVersion: 2
|
||||
guid: bcb49ddb0ed5644fda9c3b055cafa27a
|
||||
timeCreated: 1483902788
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -1,137 +0,0 @@
|
|||
#if UNITY_STANDALONE_WIN
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Windows.Forms;
|
||||
using System.Runtime.InteropServices;
|
||||
using Ookii.Dialogs;
|
||||
|
||||
namespace SFB {
|
||||
// For fullscreen support
|
||||
// - WindowWrapper class and GetActiveWindow() are required for modal file dialog.
|
||||
// - "PlayerSettings/Visible In Background" should be enabled, otherwise when file dialog opened app window minimizes automatically.
|
||||
|
||||
public class WindowWrapper : IWin32Window {
|
||||
private IntPtr _hwnd;
|
||||
public WindowWrapper(IntPtr handle) { _hwnd = handle; }
|
||||
public IntPtr Handle { get { return _hwnd; } }
|
||||
}
|
||||
|
||||
public class StandaloneFileBrowserWindows : IStandaloneFileBrowser {
|
||||
[DllImport("user32.dll")]
|
||||
private static extern IntPtr GetActiveWindow();
|
||||
|
||||
public string[] OpenFilePanel(string title, string directory, ExtensionFilter[] extensions, bool multiselect) {
|
||||
var fd = new VistaOpenFileDialog();
|
||||
fd.Title = title;
|
||||
if (extensions != null) {
|
||||
fd.Filter = GetFilterFromFileExtensionList(extensions);
|
||||
fd.FilterIndex = 1;
|
||||
}
|
||||
else {
|
||||
fd.Filter = string.Empty;
|
||||
}
|
||||
fd.Multiselect = multiselect;
|
||||
if (!string.IsNullOrEmpty(directory)) {
|
||||
fd.FileName = GetDirectoryPath(directory);
|
||||
}
|
||||
var res = fd.ShowDialog(new WindowWrapper(GetActiveWindow()));
|
||||
var filenames = res == DialogResult.OK ? fd.FileNames : new string[0];
|
||||
fd.Dispose();
|
||||
return filenames;
|
||||
}
|
||||
|
||||
public void OpenFilePanelAsync(string title, string directory, ExtensionFilter[] extensions, bool multiselect, Action<string[]> cb) {
|
||||
cb.Invoke(OpenFilePanel(title, directory, extensions, multiselect));
|
||||
}
|
||||
|
||||
public string[] OpenFolderPanel(string title, string directory, bool multiselect) {
|
||||
var fd = new VistaFolderBrowserDialog();
|
||||
fd.Description = title;
|
||||
if (!string.IsNullOrEmpty(directory)) {
|
||||
fd.SelectedPath = GetDirectoryPath(directory);
|
||||
}
|
||||
var res = fd.ShowDialog(new WindowWrapper(GetActiveWindow()));
|
||||
var filenames = res == DialogResult.OK ? new []{ fd.SelectedPath } : new string[0];
|
||||
fd.Dispose();
|
||||
return filenames;
|
||||
}
|
||||
|
||||
public void OpenFolderPanelAsync(string title, string directory, bool multiselect, Action<string[]> cb) {
|
||||
cb.Invoke(OpenFolderPanel(title, directory, multiselect));
|
||||
}
|
||||
|
||||
public string SaveFilePanel(string title, string directory, string defaultName, ExtensionFilter[] extensions) {
|
||||
var fd = new VistaSaveFileDialog();
|
||||
fd.Title = title;
|
||||
|
||||
var finalFilename = "";
|
||||
|
||||
if (!string.IsNullOrEmpty(directory)) {
|
||||
finalFilename = GetDirectoryPath(directory);
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(defaultName)) {
|
||||
finalFilename += defaultName;
|
||||
}
|
||||
|
||||
fd.FileName = finalFilename;
|
||||
if (extensions != null) {
|
||||
fd.Filter = GetFilterFromFileExtensionList(extensions);
|
||||
fd.FilterIndex = 1;
|
||||
fd.DefaultExt = extensions[0].Extensions[0];
|
||||
fd.AddExtension = true;
|
||||
}
|
||||
else {
|
||||
fd.DefaultExt = string.Empty;
|
||||
fd.Filter = string.Empty;
|
||||
fd.AddExtension = false;
|
||||
}
|
||||
var res = fd.ShowDialog(new WindowWrapper(GetActiveWindow()));
|
||||
var filename = res == DialogResult.OK ? fd.FileName : "";
|
||||
fd.Dispose();
|
||||
return filename;
|
||||
}
|
||||
|
||||
public void SaveFilePanelAsync(string title, string directory, string defaultName, ExtensionFilter[] extensions, Action<string> cb) {
|
||||
cb.Invoke(SaveFilePanel(title, directory, defaultName, extensions));
|
||||
}
|
||||
|
||||
// .NET Framework FileDialog Filter format
|
||||
// https://msdn.microsoft.com/en-us/library/microsoft.win32.filedialog.filter
|
||||
private static string GetFilterFromFileExtensionList(ExtensionFilter[] extensions) {
|
||||
var filterString = "";
|
||||
foreach (var filter in extensions) {
|
||||
filterString += filter.Name + "(";
|
||||
|
||||
foreach (var ext in filter.Extensions) {
|
||||
filterString += "*." + ext + ",";
|
||||
}
|
||||
|
||||
filterString = filterString.Remove(filterString.Length - 1);
|
||||
filterString += ") |";
|
||||
|
||||
foreach (var ext in filter.Extensions) {
|
||||
filterString += "*." + ext + "; ";
|
||||
}
|
||||
|
||||
filterString += "|";
|
||||
}
|
||||
filterString = filterString.Remove(filterString.Length - 1);
|
||||
return filterString;
|
||||
}
|
||||
|
||||
private static string GetDirectoryPath(string directory) {
|
||||
var directoryPath = Path.GetFullPath(directory);
|
||||
if (!directoryPath.EndsWith("\\")) {
|
||||
directoryPath += "\\";
|
||||
}
|
||||
if (Path.GetPathRoot(directoryPath) == directoryPath) {
|
||||
return directory;
|
||||
}
|
||||
return Path.GetDirectoryName(directoryPath) + Path.DirectorySeparatorChar;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
|
@ -1,12 +0,0 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 194e247414a78461d83ae606c1b96917
|
||||
timeCreated: 1483902788
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -5,6 +5,7 @@ using System.Text;
|
|||
using System.Threading.Tasks;
|
||||
using System.IO;
|
||||
using System.Xml.Serialization;
|
||||
using UnityEngine;
|
||||
|
||||
namespace RimWorldAnimationStudio
|
||||
{
|
||||
|
@ -12,11 +13,15 @@ namespace RimWorldAnimationStudio
|
|||
{
|
||||
public static T ReadXML<T>(string path)
|
||||
{
|
||||
Debug.Log("Reading data from " + path);
|
||||
|
||||
using (StreamReader stringReader = new StreamReader(path))
|
||||
{
|
||||
XmlSerializer serializer = new XmlSerializer(typeof(T));
|
||||
var data = (T)serializer.Deserialize(stringReader);
|
||||
|
||||
return (T)serializer.Deserialize(stringReader);
|
||||
Debug.Log("Read successful");
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -25,6 +30,8 @@ namespace RimWorldAnimationStudio
|
|||
if (obj == null || path == null || path == "")
|
||||
{ return; }
|
||||
|
||||
Debug.Log("Saving data to " + path);
|
||||
|
||||
XmlSerializer writer = new XmlSerializer(typeof(T));
|
||||
XmlSerializerNamespaces nameSpaces = new XmlSerializerNamespaces();
|
||||
nameSpaces.Add("", "");
|
||||
|
@ -32,6 +39,8 @@ namespace RimWorldAnimationStudio
|
|||
FileStream file = File.Create(path);
|
||||
writer.Serialize(file, obj, nameSpaces);
|
||||
file.Close();
|
||||
|
||||
Debug.Log("Saving successful");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue