You've already forked UniversalViewer
DanMachi:
-compatibility improvements Core: -simplified object and keyframe serialization -complicated assetbundle loading
This commit is contained in:
@@ -10,22 +10,31 @@ using System.Collections.Generic;
|
||||
using UnityEngine.ResourceManagement.ResourceLocations;
|
||||
using System.IO;
|
||||
using UnityEngine.UI;
|
||||
using static UnityEngine.EventSystems.EventTrigger;
|
||||
using System.ComponentModel;
|
||||
|
||||
public class AssetLibrary : MonoBehaviour
|
||||
{
|
||||
protected static AssetLibrary _mainInstance;
|
||||
public ResourceLocationMap AddressableResourceMap;
|
||||
public List<Shader> Shaders;
|
||||
public string LocalFilesPath => ModelViewerSettings.Get("AssetsPath");
|
||||
public string LocalFilesPath;
|
||||
private List<string> _addressableKeys;
|
||||
|
||||
public Dictionary<string, AssetBundle> LoadedAssets = new Dictionary<string, AssetBundle>();
|
||||
|
||||
public Transform UIAssetList => ModelViewerInterface.GetInstance().CanvasContainer.AssetsList.content;
|
||||
|
||||
protected virtual void Awake()
|
||||
{
|
||||
_mainInstance = this;
|
||||
}
|
||||
|
||||
public static AssetLibrary GetInstance()
|
||||
{
|
||||
return _mainInstance;
|
||||
}
|
||||
|
||||
public static T GetInstance<T>() where T : AssetLibrary
|
||||
{
|
||||
return _mainInstance as T;
|
||||
@@ -141,7 +150,7 @@ public class AssetLibrary : MonoBehaviour
|
||||
return bundle;
|
||||
}
|
||||
|
||||
public void UnloadAssets(List<string> paths)
|
||||
public static void UnloadAssets(List<string> paths)
|
||||
{
|
||||
for (int i = 0; i < paths.Count; i++)
|
||||
{
|
||||
@@ -149,12 +158,30 @@ public class AssetLibrary : MonoBehaviour
|
||||
}
|
||||
}
|
||||
|
||||
public void UnloadAsset(string path)
|
||||
public static void UnloadAsset(string path)
|
||||
{
|
||||
if (LoadedAssets.ContainsKey(path))
|
||||
var loadedAssets = _mainInstance.LoadedAssets;
|
||||
if (loadedAssets.ContainsKey(path))
|
||||
{
|
||||
LoadedAssets[path].Unload(false);
|
||||
LoadedAssets.Remove(path);
|
||||
loadedAssets[path].Unload(false);
|
||||
loadedAssets.Remove(path);
|
||||
}
|
||||
}
|
||||
|
||||
public void SetAssetList(List<string[]> loadedAssets)
|
||||
{
|
||||
for(int i = UIAssetList.childCount - 1; i >= 0; i--)
|
||||
{
|
||||
Destroy(UIAssetList.GetChild(i).gameObject);
|
||||
}
|
||||
|
||||
if (loadedAssets == null) return;
|
||||
|
||||
foreach(var entry in loadedAssets)
|
||||
{
|
||||
var button = Instantiate(SharedResources.Instance.Button, UIAssetList);
|
||||
button.GetComponentInChildren<TMPro.TMP_Text>().text = entry[0];
|
||||
button.onClick.AddListener(() => { System.Diagnostics.Process.Start("explorer.exe", "/select," + Path.GetFullPath(entry[1])); });
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -43,9 +43,12 @@ public class CameraOrbit : MonoBehaviour
|
||||
UpdateImmediate();
|
||||
}
|
||||
|
||||
public void UpdateImmediate()
|
||||
public void UpdateImmediate(bool forceUpdate = false)
|
||||
{
|
||||
if (HandleManager.InteractionInProgress || _settings.CameraLock) return;
|
||||
if(!forceUpdate)
|
||||
{
|
||||
if (HandleManager.InteractionInProgress || _settings.CameraLock) return;
|
||||
}
|
||||
|
||||
switch (_settings.CameraMode)
|
||||
{
|
||||
|
||||
16
Assets/Scripts/ModelViewerBase/CanvasContainer.cs
Normal file
16
Assets/Scripts/ModelViewerBase/CanvasContainer.cs
Normal file
@@ -0,0 +1,16 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class CanvasContainer : MonoBehaviour
|
||||
{
|
||||
public ScrollRect AssetsList;
|
||||
|
||||
public Canvas MainCanvas;
|
||||
public Transform DynamicPanels;
|
||||
public ProgressBar ProgressBar;
|
||||
public ScrollRect SelectedHandlesPanel;
|
||||
public UIToolbar SelectedObjectToolbar;
|
||||
public RectTransform Tooltip;
|
||||
public TMPro.TextMeshProUGUI TooltipText;
|
||||
public UISaveLoadPanel SaveLoadPanel;
|
||||
}
|
||||
11
Assets/Scripts/ModelViewerBase/CanvasContainer.cs.meta
Normal file
11
Assets/Scripts/ModelViewerBase/CanvasContainer.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 265c12dc907bec741b02a46de5c5f561
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,20 +1,16 @@
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
using System.Linq;
|
||||
|
||||
public class CameraContainer: ObjectContainer
|
||||
{
|
||||
protected override System.Type _serializeType => typeof(CameraContainerSerializable);
|
||||
protected override System.Type _keyframeType => typeof(KeyframeDataCamera);
|
||||
|
||||
public CameraOrbit Camera;
|
||||
public KeyframeDataCamera LastPosition;
|
||||
public LineRenderer LineRenderer;
|
||||
|
||||
public CameraSettings Settings;
|
||||
|
||||
protected override void Start()
|
||||
{
|
||||
//Set default keyframe in custom ModelViewerMain
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (!LineRenderer.enabled) return;
|
||||
@@ -63,22 +59,6 @@ public class CameraContainer: ObjectContainer
|
||||
return inverse.MultiplyPoint3x4(pos);
|
||||
}
|
||||
|
||||
public override ObjectContainerSerializable Serialize()
|
||||
{
|
||||
var serialized = new CameraContainerSerializable(this);
|
||||
return serialized;
|
||||
}
|
||||
|
||||
public override KeyframeData SerializeFrame()
|
||||
{
|
||||
return new KeyframeDataCamera(this);
|
||||
}
|
||||
|
||||
public override void Deserialize(ObjectContainerSerializable serialized)
|
||||
{
|
||||
DeserializeFrames(serialized);
|
||||
}
|
||||
|
||||
public override void Lerp(KeyframeData frame1, KeyframeData frame2, float amount)
|
||||
{
|
||||
var tsf = frame1 as KeyframeDataCamera;
|
||||
@@ -103,14 +83,6 @@ public class CameraContainer: ObjectContainer
|
||||
}
|
||||
}
|
||||
|
||||
public override void Select()
|
||||
{
|
||||
}
|
||||
|
||||
public override void Deselect()
|
||||
{
|
||||
}
|
||||
|
||||
public override void PastePose(KeyframeData frame, PoseLoadOptions pasteParams = null)
|
||||
{
|
||||
var keyframe = frame as KeyframeDataCamera;
|
||||
@@ -121,10 +93,12 @@ public class CameraContainer: ObjectContainer
|
||||
//if (Camera.lookRotation.x < -90) Camera.lookRotation.x += 360;
|
||||
//lookRotation.x = lookRotation.x - 360;
|
||||
|
||||
Debug.Log(keyframe.CameraLock);
|
||||
|
||||
using (new KeyframeToggleContext(this))
|
||||
{
|
||||
Settings.DropdownCameraMode.value = keyframe.CameraMode;
|
||||
//Settings.ToggleCameraLock.isOn = keyframe.CameraLock;
|
||||
Settings.ToggleCameraLock.isOn = keyframe.CameraLock;
|
||||
Settings.SliderFov.value = keyframe.Fov;
|
||||
Settings.SliderCamDist.value = keyframe.CamDist;
|
||||
Settings.SliderCamHeight.value = keyframe.CamHeight;
|
||||
@@ -132,12 +106,13 @@ public class CameraContainer: ObjectContainer
|
||||
Settings.SliderCamAngle.value = keyframe.CamAngle;
|
||||
}
|
||||
|
||||
Camera.UpdateImmediate();
|
||||
Camera.UpdateImmediate(true);
|
||||
}
|
||||
|
||||
public override void Destroy()
|
||||
{
|
||||
//Do not destroy cameras
|
||||
Debug.Log("Clearing camera");
|
||||
Frames.Clear();
|
||||
SetDefaultFrame();
|
||||
}
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
using Newtonsoft.Json;
|
||||
@@ -6,6 +5,9 @@ using System.Collections.Generic;
|
||||
|
||||
public class ObjectContainer : MonoBehaviour, IKeyframeSetter
|
||||
{
|
||||
protected virtual System.Type _serializeType => typeof(ObjectContainerSerializable);
|
||||
protected virtual System.Type _keyframeType => typeof(KeyframeData);
|
||||
|
||||
[JsonIgnore] public bool DoNotSave;
|
||||
public int ModelId;
|
||||
public string GUID = "";
|
||||
@@ -16,6 +18,7 @@ public class ObjectContainer : MonoBehaviour, IKeyframeSetter
|
||||
public Dictionary<SkinnedMeshRenderer, List<MorphHelper>> Morphs = new Dictionary<SkinnedMeshRenderer, List<MorphHelper>>();
|
||||
public List<FrameContent> Frames = new List<FrameContent>();
|
||||
public List<GameObject> InstantiatedObjects = new List<GameObject>();
|
||||
public List<AssetBundleEntry> LoadedAssets = new List<AssetBundleEntry>();
|
||||
protected bool _setKeyframe = true;
|
||||
protected bool _applicationQuitting = false;
|
||||
|
||||
@@ -36,9 +39,9 @@ public class ObjectContainer : MonoBehaviour, IKeyframeSetter
|
||||
if (ModelViewerMain.GetInstance() == null) return;
|
||||
if (DoNotSave) return;
|
||||
|
||||
if (Frames.Count == 0)
|
||||
if(Frames.Count == 0)
|
||||
{
|
||||
SetKeyframe();
|
||||
SetDefaultFrame();
|
||||
}
|
||||
|
||||
ModelViewerMain.RegisterObject(this);
|
||||
@@ -63,17 +66,12 @@ public class ObjectContainer : MonoBehaviour, IKeyframeSetter
|
||||
|
||||
public virtual ObjectContainerSerializable Serialize()
|
||||
{
|
||||
return new ObjectContainerSerializable(this);
|
||||
return ObjectContainerSerializable.Serialize(_serializeType, this);
|
||||
}
|
||||
|
||||
public virtual KeyframeData SerializeFrame()
|
||||
{
|
||||
return new KeyframeData(this);
|
||||
}
|
||||
|
||||
public virtual void Deserialize(ObjectContainerSerializable serialized)
|
||||
{
|
||||
throw new NotImplementedException(GetType().FullName);
|
||||
return KeyframeData.Serialize(_keyframeType, this);
|
||||
}
|
||||
|
||||
protected virtual void OnDestroy()
|
||||
@@ -104,8 +102,6 @@ public class ObjectContainer : MonoBehaviour, IKeyframeSetter
|
||||
{
|
||||
switch (this)
|
||||
{
|
||||
case SceneContainer _:
|
||||
return DataType.Scene;
|
||||
case CameraContainer _:
|
||||
return DataType.Camera;
|
||||
default:
|
||||
@@ -195,6 +191,7 @@ public class ObjectContainer : MonoBehaviour, IKeyframeSetter
|
||||
|
||||
public void SetDefaultFrame()
|
||||
{
|
||||
Debug.Log("Setting default frames for " + name);
|
||||
Frames = new List<FrameContent>()
|
||||
{
|
||||
new FrameContent(0).SetObjectData(SerializeFrame())
|
||||
@@ -229,12 +226,11 @@ public class ObjectContainer : MonoBehaviour, IKeyframeSetter
|
||||
|
||||
public virtual void Deselect()
|
||||
{
|
||||
throw new NotImplementedException(this.GetType().FullName);
|
||||
}
|
||||
|
||||
public virtual void Select()
|
||||
{
|
||||
throw new NotImplementedException(this.GetType().FullName);
|
||||
AssetLibrary.GetInstance().SetAssetList(LoadedAssets.Select(a=> new string[] {a.Name, a.FilePath}).ToList());
|
||||
}
|
||||
|
||||
public virtual void Destroy()
|
||||
|
||||
@@ -1,6 +1,12 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
public interface ISerializableContainer
|
||||
{
|
||||
public abstract ObjectContainerSerializable Serialize();
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
public class ObjectContainerSerializable
|
||||
{
|
||||
@@ -23,4 +29,15 @@ public class ObjectContainerSerializable
|
||||
this.GUID = source.GUID;
|
||||
this.Frames = source.Frames.Select(frame => new FrameContent(frame)).ToList();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Call type's constructor with container as parameter
|
||||
/// </summary>
|
||||
/// <param name="type">Must derive from ObjectContainer</param>
|
||||
/// <param name="container">Type must accept it as the only constructor parameter</param>
|
||||
/// <returns></returns>
|
||||
public static ObjectContainerSerializable Serialize(Type type, ObjectContainer container)
|
||||
{
|
||||
return Activator.CreateInstance(type, new object[] { container }) as ObjectContainerSerializable;
|
||||
}
|
||||
}
|
||||
@@ -2,11 +2,10 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
|
||||
public class SceneContainer : ObjectContainer
|
||||
[System.Serializable]
|
||||
public class SceneContainer
|
||||
{
|
||||
public CameraContainer MainCameraOrbit;
|
||||
public CameraContainer WorkCameraOrbit;
|
||||
|
||||
public string GUID;
|
||||
public List<ObjectContainer> AllObjects = new List<ObjectContainer>();
|
||||
|
||||
public List<T> Objects<T>() where T : ObjectContainer
|
||||
@@ -14,9 +13,11 @@ public class SceneContainer : ObjectContainer
|
||||
return AllObjects.Cast<T>().ToList();
|
||||
}
|
||||
|
||||
public static SceneContainer Create<T>(ModelViewerMain main) where T : SceneContainer
|
||||
public SceneContainer() { }
|
||||
|
||||
public static SceneContainer Create<T>(ModelViewerMain main) where T : SceneContainer, new()
|
||||
{
|
||||
var container = new GameObject("Scene").AddComponent<T>();
|
||||
var container = new T();
|
||||
container.Init(main);
|
||||
return container;
|
||||
}
|
||||
@@ -24,26 +25,22 @@ public class SceneContainer : ObjectContainer
|
||||
public virtual void Init(ModelViewerMain main)
|
||||
{
|
||||
GUID = "scene";
|
||||
MainCameraOrbit = main.MainCameraOrbit;
|
||||
WorkCameraOrbit = main.WorkCameraOrbit;
|
||||
SetDefaultFrame();
|
||||
AllObjects.Add(MainCameraOrbit);
|
||||
if (!AllObjects.Contains(main.MainCameraOrbit)) { AllObjects.Add(main.MainCameraOrbit); }
|
||||
}
|
||||
|
||||
public override ObjectContainerSerializable Serialize()
|
||||
public virtual SceneSerializable Serialize()
|
||||
{
|
||||
return new SceneSerializable(this);
|
||||
}
|
||||
|
||||
protected override void OnDestroy()
|
||||
public virtual void Destroy()
|
||||
{
|
||||
if (_applicationQuitting) return;
|
||||
|
||||
for (int i = AllObjects.Count - 1; i >= 0; i--)
|
||||
{
|
||||
var obj = AllObjects[i];
|
||||
if (obj == this) continue;
|
||||
obj.Destroy();
|
||||
}
|
||||
|
||||
AllObjects.Clear();
|
||||
}
|
||||
}
|
||||
@@ -5,10 +5,12 @@ using System.Linq;
|
||||
using UnityEngine;
|
||||
|
||||
[Serializable]
|
||||
public class SceneSerializable : ObjectContainerSerializable
|
||||
public class SceneSerializable
|
||||
{
|
||||
public string GUID;
|
||||
public string Version;
|
||||
public string Date;
|
||||
public string Filename;
|
||||
public TimelineControllerSerializable Timeline;
|
||||
public List<ObjectContainerSerializable> Objects = new List<ObjectContainerSerializable>();
|
||||
|
||||
@@ -19,11 +21,9 @@ public class SceneSerializable : ObjectContainerSerializable
|
||||
this.Version = Application.version;
|
||||
this.Date = DateTime.Now.ToString("yyyy-MM-dd HH:mm", CultureInfo.InvariantCulture); ;
|
||||
this.Timeline = new TimelineControllerSerializable(TimelineController.Instance);
|
||||
this.Frames = scene.Frames.Select(f => new FrameContent(f)).ToList();
|
||||
foreach (var obj in scene.AllObjects)
|
||||
{
|
||||
if (obj != scene)
|
||||
Objects.Add(obj.Serialize());
|
||||
Objects.Add(obj.Serialize());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,23 +21,49 @@ public class ModelBuilder : MonoBehaviour
|
||||
_mainInstance = this;
|
||||
}
|
||||
|
||||
public virtual IEnumerator SpawnSerialized(ObjectContainerSerializable oc, Action<GameObject> callback = null)
|
||||
public ObjectContainer SpawnAsset(string assetPath)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
return SpawnAsset(AssetTypes.Unknown, assetPath);
|
||||
}
|
||||
|
||||
public IEnumerator SpawnAsset(string assetPath, Action<ObjectContainer> callback = null)
|
||||
public virtual ObjectContainer SpawnAsset(Enum assetType, string assetPath)
|
||||
{
|
||||
yield return SpawnAsset(AssetTypes.Unknown, assetPath, callback);
|
||||
if (this.GetType() == typeof(ModelBuilder)) throw new NotImplementedException();
|
||||
|
||||
ModelViewerMain.GetInstance().PrepareForLoad();
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public virtual IEnumerator SpawnAsset(Enum assetType, string assetPath, Action<ObjectContainer> callback = null)
|
||||
public IEnumerator SpawnAssetCoroutine(string assetPath, Action<ObjectContainer> callback = null)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
yield return SpawnAssetCoroutine(AssetTypes.Unknown, assetPath, callback);
|
||||
}
|
||||
|
||||
public virtual IEnumerator SpawnAsset(AssetSpawnData data, Action<ObjectContainer> callback = null)
|
||||
public virtual IEnumerator SpawnAssetCoroutine(Enum assetType, string assetPath, Action<ObjectContainer> callback = null)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
if(this.GetType() == typeof(ModelBuilder)) throw new NotImplementedException();
|
||||
|
||||
ModelViewerMain.GetInstance().PrepareForLoad();
|
||||
|
||||
yield break;
|
||||
}
|
||||
|
||||
public virtual ObjectContainer SpawnSerialized(ObjectContainerSerializable oc)
|
||||
{
|
||||
if (this.GetType() == typeof(ModelBuilder)) throw new NotImplementedException();
|
||||
|
||||
ModelViewerMain.GetInstance().PrepareForLoad();
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public virtual IEnumerator SpawnSerializedCoroutine(ObjectContainerSerializable oc, Action<ObjectContainer> callback = null)
|
||||
{
|
||||
if (this.GetType() == typeof(ModelBuilder)) throw new NotImplementedException();
|
||||
|
||||
ModelViewerMain.GetInstance().PrepareForLoad();
|
||||
|
||||
yield break;
|
||||
}
|
||||
}
|
||||
@@ -7,24 +7,23 @@ public class ModelViewerInterface : MonoBehaviour
|
||||
{
|
||||
public static ModelViewerInterface _mainInstance;
|
||||
|
||||
public Transform DynamicPanels;
|
||||
public TMPro.TMP_Text[] TooltipLabels;
|
||||
|
||||
public ScrollRect ScenePresetToggle;
|
||||
public ScrollRect PosePresetToggle;
|
||||
public ScrollRect SelectedHandlesPanel;
|
||||
|
||||
public UISaveLoadPanel SaveLoadPanel;
|
||||
public ProgressBar ProgressBar;
|
||||
|
||||
public Canvas MainCanvas;
|
||||
|
||||
public RectTransform Tooltip;
|
||||
public TMPro.TextMeshProUGUI TooltipText;
|
||||
[Header("Required")]
|
||||
public CanvasContainer CanvasContainer;
|
||||
|
||||
private Vector2 _previousResolution = Vector2.zero;
|
||||
private int _resolutionUpdateCountdown;
|
||||
|
||||
public Canvas MainCanvas => CanvasContainer.MainCanvas;
|
||||
public RectTransform Tooltip => CanvasContainer.Tooltip;
|
||||
public ProgressBar ProgressBar => CanvasContainer.ProgressBar;
|
||||
public Transform DynamicPanels => CanvasContainer.DynamicPanels;
|
||||
public UISaveLoadPanel SaveLoadPanel => CanvasContainer.SaveLoadPanel;
|
||||
public TMPro.TextMeshProUGUI TooltipText => CanvasContainer.TooltipText;
|
||||
public ScrollRect SelectedHandlesPanel => CanvasContainer.SelectedHandlesPanel;
|
||||
public UIToolbar SelectedObjectToolbar => CanvasContainer.SelectedObjectToolbar;
|
||||
|
||||
public static ModelViewerInterface GetInstance()
|
||||
{
|
||||
return _mainInstance;
|
||||
@@ -58,7 +57,17 @@ public class ModelViewerInterface : MonoBehaviour
|
||||
{
|
||||
draggable.transform.position = draggable.RecalculatePosition(draggable.transform.position);
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Tooltip.position = Input.mousePosition;
|
||||
if (string.IsNullOrEmpty(TooltipText.text) && Tooltip.gameObject.activeSelf)
|
||||
{
|
||||
Tooltip.gameObject.SetActive(false);
|
||||
}
|
||||
else if (!string.IsNullOrEmpty(TooltipText.text) && !Tooltip.gameObject.activeSelf)
|
||||
{
|
||||
Tooltip.gameObject.SetActive(true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
@@ -9,11 +8,11 @@ public class ModelViewerMain : MonoBehaviour
|
||||
{
|
||||
protected static ModelViewerMain _mainInstance;
|
||||
|
||||
[SerializeField]
|
||||
public CameraContainer
|
||||
MainCameraOrbit,
|
||||
WorkCameraOrbit;
|
||||
[Header("Required")]
|
||||
public CameraContainer MainCameraOrbit;
|
||||
public CameraContainer WorkCameraOrbit;
|
||||
|
||||
[Header("Runtime")]
|
||||
public OperationMode Mode;
|
||||
public SceneContainer CurrentScene;
|
||||
public ObjectContainer SelectedObject;
|
||||
@@ -51,34 +50,42 @@ public class ModelViewerMain : MonoBehaviour
|
||||
CurrentScene = SceneContainer.Create<SceneContainer>(this);
|
||||
}
|
||||
|
||||
if (!MainCameraOrbit.Frames.Any())
|
||||
MainCameraOrbit.SetDefaultFrame();
|
||||
|
||||
_mainInstance = this;
|
||||
}
|
||||
|
||||
public CameraOrbit GetCamera()
|
||||
{
|
||||
return CurrentScene.MainCameraOrbit.Camera;
|
||||
return MainCameraOrbit.Camera;
|
||||
}
|
||||
|
||||
public CameraContainer GetCameraHandler()
|
||||
{
|
||||
if (!CurrentScene.MainCameraOrbit.LineRenderer.enabled)
|
||||
return CurrentScene.MainCameraOrbit;
|
||||
if (!MainCameraOrbit.LineRenderer.enabled)
|
||||
return MainCameraOrbit;
|
||||
else
|
||||
return CurrentScene.WorkCameraOrbit;
|
||||
return WorkCameraOrbit;
|
||||
}
|
||||
|
||||
public static void RegisterObject(ObjectContainer container)
|
||||
{
|
||||
GetInstance().CurrentScene.AllObjects.Add(container);
|
||||
if (!GetInstance().CurrentScene.AllObjects.Contains(container))
|
||||
{
|
||||
GetInstance().CurrentScene.AllObjects.Add(container);
|
||||
}
|
||||
var selector = UITimelineObjectEntry.Create(container);
|
||||
container.InstantiatedObjects.Add(selector.gameObject);
|
||||
}
|
||||
|
||||
public static void UnregisterObject(ObjectContainer container)
|
||||
{
|
||||
GetInstance().CurrentScene.AllObjects.Remove(container);
|
||||
GetInstance().SelectionRemove(container);
|
||||
var instance = GetInstance();
|
||||
instance.CurrentScene.AllObjects.Remove(container);
|
||||
instance.SelectionRemove(container);
|
||||
|
||||
if (instance.SelectedObject == container)
|
||||
{
|
||||
instance.SelectObject(null);
|
||||
}
|
||||
}
|
||||
|
||||
public T GetSelectedObject<T>() where T: ObjectContainer
|
||||
@@ -102,14 +109,6 @@ public class ModelViewerMain : MonoBehaviour
|
||||
TimelineController.UpdateTimeline();
|
||||
}
|
||||
|
||||
public void PrepareForLoad()
|
||||
{
|
||||
if (Mode == OperationMode.Single)
|
||||
{
|
||||
EmptyScene<SceneContainer>();
|
||||
}
|
||||
}
|
||||
|
||||
public void SelectionAdd(ObjectContainer container)
|
||||
{
|
||||
if (container == null) return;
|
||||
@@ -153,9 +152,23 @@ public class ModelViewerMain : MonoBehaviour
|
||||
SelectedObjects.Clear();
|
||||
}
|
||||
|
||||
public void EmptyScene<T>() where T : SceneContainer
|
||||
public void PrepareForLoad()
|
||||
{
|
||||
CurrentScene.Destroy();
|
||||
if (Mode == OperationMode.Single)
|
||||
{
|
||||
EmptySceneDefault();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary> Replace with custom type if game requires it </summary>
|
||||
public virtual void EmptySceneDefault()
|
||||
{
|
||||
EmptyScene<SceneContainer>();
|
||||
}
|
||||
|
||||
public void EmptyScene<T>() where T : SceneContainer, new()
|
||||
{
|
||||
CurrentScene?.Destroy();
|
||||
CurrentScene = SceneContainer.Create<T>(this);
|
||||
|
||||
ModelViewerMain.GetInstance().SelectionClear();
|
||||
@@ -164,12 +177,33 @@ public class ModelViewerMain : MonoBehaviour
|
||||
|
||||
public SceneSerializable SaveScene()
|
||||
{
|
||||
return CurrentScene.Serialize() as SceneSerializable;
|
||||
return CurrentScene.Serialize();
|
||||
}
|
||||
|
||||
public virtual IEnumerator LoadScene(SceneSerializable bc)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
EmptySceneDefault();
|
||||
ObjectContainerSerializable cameraFrameData = null;
|
||||
|
||||
foreach (var c in bc.Objects)
|
||||
{
|
||||
if (c.GUID == "cameraOrbit")
|
||||
{
|
||||
cameraFrameData = c;
|
||||
}
|
||||
else
|
||||
{
|
||||
yield return ModelBuilder.GetInstance().SpawnSerializedCoroutine(c);
|
||||
}
|
||||
}
|
||||
|
||||
//deserialize camera last
|
||||
yield return 0;
|
||||
MainCameraOrbit.DeserializeFrames(cameraFrameData);
|
||||
bc.Timeline.Deserialize(TimelineController.Instance);
|
||||
TimelineController.SetCurrentFrame(TimelineController.Instance.CurrentFrame);
|
||||
|
||||
//CurrentScene.AllObjects[1].PastePose(CurrentScene.AllObjects[1].Frames[0].ObjectData, PoseLoadOptions.All());
|
||||
}
|
||||
|
||||
protected void AutoSaveUpdate()
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using UnityEngine;
|
||||
using static ModelViewerSettings;
|
||||
|
||||
public class ModelViewerSettings
|
||||
{
|
||||
@@ -59,7 +57,7 @@ public class ModelViewerSettings
|
||||
var settings = Instance;
|
||||
if (!settings.Settings.ContainsKey(key))
|
||||
{
|
||||
settings.Settings[key] = defaultSetting;
|
||||
Set(key, defaultSetting, true);
|
||||
}
|
||||
return settings.Settings[key].Value;
|
||||
}
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
using System;
|
||||
|
||||
[System.Serializable]
|
||||
public class KeyframeData
|
||||
{
|
||||
@@ -23,4 +25,15 @@ public class KeyframeData
|
||||
copy.Root = copy.Root.LerpWith(target.Root, amount);
|
||||
return copy;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Call type's constructor with container as parameter
|
||||
/// </summary>
|
||||
/// <param name="type">Must derive from KeyframeData</param>
|
||||
/// <param name="container">Type must accept it as the only constructor parameter</param>
|
||||
/// <returns></returns>
|
||||
public static KeyframeData Serialize(Type type, ObjectContainer container)
|
||||
{
|
||||
return Activator.CreateInstance(type, new object[] { container }) as KeyframeData;
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public partial class SharedResources : MonoBehaviour
|
||||
{
|
||||
@@ -20,6 +21,7 @@ public partial class SharedResources : MonoBehaviour
|
||||
public MorphPanel MorphPanel ;
|
||||
public GameObject ModelIcon ;
|
||||
public GameObject Handle ;
|
||||
public Button Button ;
|
||||
|
||||
protected void Awake()
|
||||
{
|
||||
|
||||
@@ -9,6 +9,13 @@ public class ExtendedDropdown : MonoBehaviour
|
||||
[SerializeField] private TMPro.TMP_Dropdown _dropdown;
|
||||
public UnityEvent<int> OnValueChangedEvent;
|
||||
public List<TMPro.TMP_Dropdown.OptionData> options => _dropdown.options;
|
||||
public int value
|
||||
{
|
||||
get { return _dropdown.value; }
|
||||
set { _dropdown.value = value; }
|
||||
}
|
||||
|
||||
[Header("Hotkeys")]
|
||||
public KeyCode PreviousKey = KeyCode.None;
|
||||
public KeyCode NextKey = KeyCode.None;
|
||||
|
||||
|
||||
@@ -1,31 +1,29 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using static SerializableBone;
|
||||
|
||||
namespace KF3.UI.Panels
|
||||
public class HandleSettingsPanel : MonoBehaviour
|
||||
{
|
||||
public class HandleSettingsPanel : MonoBehaviour
|
||||
{
|
||||
public ScrollRect HandleVisibilityToggles;
|
||||
public ScrollRect HandleVisibilityToggles;
|
||||
public List<BoneTags> AvailableTags = new List<BoneTags>();
|
||||
|
||||
private void Start()
|
||||
private void Start()
|
||||
{
|
||||
var handleManager = HandleManager.Instance;
|
||||
foreach (BoneTags en in AvailableTags)
|
||||
{
|
||||
var handleManager = HandleManager.Instance;
|
||||
foreach (BoneTags en in Enum.GetValues(typeof(BoneTags)))
|
||||
var handle = SliderPanel.CreateToggle(en.ToString(), handleManager.EnabledHandles.Contains(en), HandleVisibilityToggles.content, (value)=>
|
||||
{
|
||||
var handle = SliderPanel.CreateToggle(en.ToString(), handleManager.EnabledHandles.Contains(en), HandleVisibilityToggles.content, (value)=>
|
||||
if (value)
|
||||
{
|
||||
if (value)
|
||||
{
|
||||
handleManager.EnabledHandles.Add(en);
|
||||
}
|
||||
else
|
||||
{
|
||||
handleManager.EnabledHandles.Remove(en);
|
||||
}
|
||||
});
|
||||
}
|
||||
handleManager.EnabledHandles.Add(en);
|
||||
}
|
||||
else
|
||||
{
|
||||
handleManager.EnabledHandles.Remove(en);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,11 @@ public class MorphPanel : MonoBehaviour
|
||||
|
||||
public void Init(List<string> categories)
|
||||
{
|
||||
for(int i = _categoryPanels.childCount-1; i >= 0; i--)
|
||||
{
|
||||
Destroy(_categoryPanels.GetChild(i).gameObject);
|
||||
}
|
||||
|
||||
Categories.Clear();
|
||||
foreach (var category in categories)
|
||||
{
|
||||
@@ -25,8 +30,8 @@ public class MorphPanel : MonoBehaviour
|
||||
}
|
||||
}
|
||||
|
||||
public void CreateMorph(string category, ObjectContainer container, SkinnedMeshRenderer meshRenderer, int index, string displayName)
|
||||
public SliderPanel CreateMorph(string category, ObjectContainer container, SkinnedMeshRenderer meshRenderer, int index, string displayName)
|
||||
{
|
||||
SliderPanel.CreateMorph(container, meshRenderer, index, displayName, this.Categories[category].Content);
|
||||
return SliderPanel.CreateMorph(container, meshRenderer, index, displayName, this.Categories[category].Content);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,10 +8,11 @@ public class SliderPanel : MonoBehaviour
|
||||
public static SliderPanel Prefab;
|
||||
|
||||
public Slider Slider;
|
||||
//public UICallbacks ToggleCallbacks;
|
||||
public TMPro.TMP_Text Text;
|
||||
public Toggle Toggle;
|
||||
public float DefaultValue;
|
||||
public MorphHelper MorphHelper;
|
||||
|
||||
public float value {
|
||||
get { return Slider.value; }
|
||||
set { Slider.value = value; }
|
||||
@@ -39,15 +40,10 @@ public class SliderPanel : MonoBehaviour
|
||||
{
|
||||
SliderPanel panel = Instantiate(SharedResources.Instance.SliderPanel, parent);
|
||||
|
||||
var helper = new MorphHelper(meshRenderer, meshRenderer.sharedMesh.GetBlendShapeName(index), panel.Slider);
|
||||
if (container.Morphs.ContainsKey(meshRenderer))
|
||||
container.Morphs[meshRenderer].Add(helper);
|
||||
else
|
||||
container.Morphs.Add(meshRenderer, new List<MorphHelper>() { helper });
|
||||
|
||||
panel.MorphHelper = new MorphHelper(meshRenderer, meshRenderer.sharedMesh.GetBlendShapeName(index), panel.Slider);
|
||||
panel.Text.text = displayName;
|
||||
panel.Slider.value = meshRenderer.GetBlendShapeWeight(index);
|
||||
panel.SetOnValueChanged((value) => {helper.UpdateMorph(value);});
|
||||
panel.SetOnValueChanged((value) => {panel.MorphHelper.UpdateMorph(value);});
|
||||
panel.SetOnRelease((value) => { container.SetKeyframe(); });
|
||||
panel.SetOnRightClick(null);
|
||||
return panel;
|
||||
|
||||
@@ -96,13 +96,15 @@ public class TimelineController : MonoBehaviour
|
||||
{
|
||||
var main = ModelViewerMain.GetInstance();
|
||||
Instance.CurrentFrame = frameIndex;
|
||||
//Debug.Log(frameIndex);
|
||||
|
||||
Debug.Log("Setting frame to: " + frameIndex);
|
||||
|
||||
foreach (var container in main.CurrentScene.AllObjects)
|
||||
{
|
||||
container.GetClosestFrames(frameIndex, out var previousFrame, out var nextFrame);
|
||||
var blendAmount = previousFrame == nextFrame? 0 : 1 - (float)(nextFrame.FrameNum - frameIndex) / (nextFrame.FrameNum - previousFrame.FrameNum);
|
||||
|
||||
Debug.Log($"Setting {container.name} to frame {previousFrame.FrameNum}({nextFrame.FrameNum})");
|
||||
container.Lerp(previousFrame.ObjectData, nextFrame.ObjectData, blendAmount);
|
||||
}
|
||||
UpdateTimeline();
|
||||
|
||||
@@ -6,19 +6,39 @@ using UnityEngine.EventSystems;
|
||||
|
||||
public class UICallbacks : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler
|
||||
{
|
||||
private bool _isHovering;
|
||||
private bool _hoverActionActivated;
|
||||
private float _hoveredTime;
|
||||
private float _timeBeforeHoverActivate = 1.5f;
|
||||
public UnityEvent MouseHover;
|
||||
public UnityEvent MouseHoverEnd;
|
||||
|
||||
public void OnPointerEnter(PointerEventData eventData)
|
||||
{
|
||||
MouseHover.Invoke();
|
||||
_hoverActionActivated = false;
|
||||
_isHovering = true;
|
||||
_hoveredTime = 0;
|
||||
}
|
||||
|
||||
public void OnPointerExit(PointerEventData eventData)
|
||||
{
|
||||
_isHovering = false;
|
||||
MouseHoverEnd.Invoke();
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (_isHovering && !_hoverActionActivated)
|
||||
{
|
||||
_hoveredTime += Time.deltaTime;
|
||||
if (_hoveredTime >= _timeBeforeHoverActivate)
|
||||
{
|
||||
_hoverActionActivated = true;
|
||||
MouseHover.Invoke();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void SetTooltipText(string text)
|
||||
{
|
||||
ModelViewerInterface.GetInstance().Tooltip.SetAsLastSibling();
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class UIDraggableProxy : MonoBehaviour, IEndDragHandler, IDragHandler
|
||||
{
|
||||
|
||||
@@ -27,7 +27,7 @@ public class UIElementDragger : MonoBehaviour, IDragHandler, IEndDragHandler, IP
|
||||
private CanvasGroup _canvasGroup;
|
||||
|
||||
public DragAction LastDragAction;
|
||||
|
||||
|
||||
public enum DragAction
|
||||
{
|
||||
None,
|
||||
|
||||
@@ -11,7 +11,7 @@ public class UIPoseContainer : MonoBehaviour
|
||||
public KeyframeData KeyframeData;
|
||||
public TMPro.TMP_InputField NameLabel;
|
||||
|
||||
static ModelViewerInterface UI => ModelViewerInterface.GetInstance();
|
||||
static UISaveLoadPanel SaveLoadPanel => ModelViewerInterface.GetInstance().CanvasContainer.SaveLoadPanel;
|
||||
static ModelViewerMain Main => ModelViewerMain.GetInstance();
|
||||
|
||||
public static UIPoseContainer CreateNew(string poseName, KeyframeData poseData, bool forceOverride)
|
||||
@@ -23,7 +23,7 @@ public class UIPoseContainer : MonoBehaviour
|
||||
return null;
|
||||
}
|
||||
|
||||
if (UI.SaveLoadPanel.GetPoseByName(poseName, out var savedPose))
|
||||
if (SaveLoadPanel.GetPoseByName(poseName, out var savedPose))
|
||||
{
|
||||
if (!forceOverride)
|
||||
{
|
||||
@@ -33,8 +33,8 @@ public class UIPoseContainer : MonoBehaviour
|
||||
}
|
||||
else
|
||||
{
|
||||
savedPose = Instantiate(SharedResources.Instance.UIPoseContainer, UI.PosePresetToggle.content);
|
||||
UI.SaveLoadPanel.AddPose(savedPose);
|
||||
savedPose = Instantiate(SharedResources.Instance.UIPoseContainer, SaveLoadPanel.ScrollPose.content);
|
||||
SaveLoadPanel.AddPose(savedPose);
|
||||
}
|
||||
|
||||
savedPose.Init(poseName, poseData);
|
||||
@@ -54,16 +54,16 @@ public class UIPoseContainer : MonoBehaviour
|
||||
{
|
||||
var poseName = NameLabel.text;
|
||||
|
||||
if (UI.SaveLoadPanel.GetPoseByName(poseName, out var savedPose))
|
||||
if (SaveLoadPanel.GetPoseByName(poseName, out var savedPose))
|
||||
{
|
||||
Error.Log(Color.red, "Preset with this name already exists");
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
savedPose = Instantiate(SharedResources.Instance.UIPoseContainer, UI.PosePresetToggle.content);
|
||||
savedPose = Instantiate(SharedResources.Instance.UIPoseContainer, SaveLoadPanel.ScrollPose.content);
|
||||
savedPose.NameLabel.text = poseName;
|
||||
UI.SaveLoadPanel.AddPose(savedPose);
|
||||
SaveLoadPanel.AddPose(savedPose);
|
||||
}
|
||||
|
||||
savedPose.Save();
|
||||
@@ -75,12 +75,12 @@ public class UIPoseContainer : MonoBehaviour
|
||||
|
||||
var poseData = Main.SelectedObject.SerializeFrame();
|
||||
string poseName = NameLabel.text;
|
||||
string fileName = Path.GetFullPath(Path.Combine(Settings.SavePoseDirectory, $"{poseName}.pose"));
|
||||
string fileName = Path.GetFullPath(Path.Combine(UISaveLoadPanel.SavePoseDirectory, $"{poseName}.pose"));
|
||||
|
||||
try
|
||||
{
|
||||
var settings = new JsonSerializerSettings() { TypeNameHandling = TypeNameHandling.Auto, DefaultValueHandling = DefaultValueHandling.Ignore };
|
||||
var json = JsonConvert.SerializeObject(poseData, Formatting.Indented, settings);
|
||||
var json = JsonConvert.SerializeObject(poseData, typeof(KeyframeData), Formatting.Indented, settings);
|
||||
File.WriteAllText(fileName, json);
|
||||
Error.Log(Color.green, $"Pose saved to {fileName}");
|
||||
}
|
||||
@@ -121,7 +121,7 @@ public class UIPoseContainer : MonoBehaviour
|
||||
{
|
||||
Destroy(this.gameObject);
|
||||
|
||||
string path = Path.GetFullPath(Path.Combine(Settings.SavePoseDirectory, $"{PoseName}.pose"));
|
||||
string path = Path.GetFullPath(Path.Combine(UISaveLoadPanel.SavePoseDirectory, $"{NameLabel.text}.pose"));
|
||||
if (File.Exists(path))
|
||||
File.Delete(path);
|
||||
|
||||
|
||||
@@ -19,6 +19,15 @@ public class UISaveLoadPanel : MonoBehaviour
|
||||
public List<UISceneContainer> ScenePresetEntries = new List<UISceneContainer>();
|
||||
public List<UIPoseContainer> PosePresetEntries = new List<UIPoseContainer>();
|
||||
|
||||
public static string SavePoseDirectory => ModelViewerSettings.Get("SavePoseDirectory", new ModelViewerSettings.Setting(Application.dataPath + "/../Poses/", ModelViewerSettings.SettingType.FolderPath));
|
||||
public static string SaveSceneDirectory => ModelViewerSettings.Get("SaveSceneDirectory", new ModelViewerSettings.Setting(Application.dataPath + "/../Scenes/", ModelViewerSettings.SettingType.FolderPath));
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
InitPoses();
|
||||
InitScenes();
|
||||
}
|
||||
|
||||
public void AddPose(UIPoseContainer pose)
|
||||
{
|
||||
PosePresetEntries.Add(pose);
|
||||
@@ -45,6 +54,11 @@ public class UISaveLoadPanel : MonoBehaviour
|
||||
ScrollPose.gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
public void OnDeleteButton()
|
||||
{
|
||||
ModelViewerMain.GetInstance().EmptySceneDefault();
|
||||
}
|
||||
|
||||
public bool GetPoseByName(string name, out UIPoseContainer pose)
|
||||
{
|
||||
pose = PosePresetEntries.FirstOrDefault(p => p.PoseName == name);
|
||||
@@ -57,15 +71,13 @@ public class UISaveLoadPanel : MonoBehaviour
|
||||
return scene != null;
|
||||
}
|
||||
|
||||
public void Init()
|
||||
{
|
||||
InitPoses();
|
||||
InitScenes();
|
||||
}
|
||||
|
||||
private void InitPoses()
|
||||
{
|
||||
string path = Settings.SavePoseDirectory;
|
||||
string path = SavePoseDirectory;
|
||||
if(!Directory.Exists(path))
|
||||
{
|
||||
Directory.CreateDirectory(path);
|
||||
}
|
||||
|
||||
foreach (var fileName in Directory.GetFiles(path).Where(f => f.EndsWith(".pose")))
|
||||
{
|
||||
@@ -86,7 +98,11 @@ public class UISaveLoadPanel : MonoBehaviour
|
||||
|
||||
private void InitScenes()
|
||||
{
|
||||
string path = Settings.SaveSceneDirectory;
|
||||
string path = SaveSceneDirectory;
|
||||
if (!Directory.Exists(path))
|
||||
{
|
||||
Directory.CreateDirectory(path);
|
||||
}
|
||||
List<SceneSerializable> scenes = new List<SceneSerializable>();
|
||||
|
||||
foreach (var fileName in Directory.GetFiles(path).Where(f => f.EndsWith(".scene")))
|
||||
|
||||
@@ -11,7 +11,7 @@ public class UISceneContainer : MonoBehaviour
|
||||
public TMPro.TMP_Text DateLabel;
|
||||
public TMPro.TMP_Text VersionLabel;
|
||||
|
||||
static ModelViewerInterface UI => ModelViewerInterface.GetInstance();
|
||||
static UISaveLoadPanel SaveLoadPanel => ModelViewerInterface.GetInstance().CanvasContainer.SaveLoadPanel;
|
||||
static ModelViewerMain Main => ModelViewerMain.GetInstance();
|
||||
|
||||
public static UISceneContainer CreateNew(SceneSerializable sceneData, bool forceOverride)
|
||||
@@ -23,7 +23,7 @@ public class UISceneContainer : MonoBehaviour
|
||||
return null;
|
||||
}
|
||||
|
||||
if (UI.SaveLoadPanel.GetSceneByName(sceneData.Filename, out var savedScene))
|
||||
if (SaveLoadPanel.GetSceneByName(sceneData.Filename, out var savedScene))
|
||||
{
|
||||
if (!forceOverride)
|
||||
{
|
||||
@@ -33,8 +33,8 @@ public class UISceneContainer : MonoBehaviour
|
||||
}
|
||||
else
|
||||
{
|
||||
savedScene = Instantiate(SharedResources.Instance.UISceneContainer, UI.ScenePresetToggle.content);
|
||||
UI.SaveLoadPanel.AddScene(savedScene);
|
||||
savedScene = Instantiate(SharedResources.Instance.UISceneContainer, SaveLoadPanel.ScrollScene.content);
|
||||
SaveLoadPanel.AddScene(savedScene);
|
||||
}
|
||||
|
||||
savedScene.Init(sceneData);
|
||||
@@ -56,16 +56,16 @@ public class UISceneContainer : MonoBehaviour
|
||||
{
|
||||
var sceneName = NameLabel.text;
|
||||
|
||||
if (UI.SaveLoadPanel.GetSceneByName(sceneName, out var savedScene))
|
||||
if (SaveLoadPanel.GetSceneByName(sceneName, out var savedScene))
|
||||
{
|
||||
Error.Log(Color.red, "Preset with this name already exists");
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
savedScene = Instantiate(SharedResources.Instance.UISceneContainer, UI.ScenePresetToggle.content);
|
||||
savedScene = Instantiate(SharedResources.Instance.UISceneContainer, SaveLoadPanel.ScrollScene.content);
|
||||
savedScene.NameLabel.text = sceneName;
|
||||
UI.SaveLoadPanel.AddScene(savedScene);
|
||||
SaveLoadPanel.AddScene(savedScene);
|
||||
}
|
||||
|
||||
savedScene.Save();
|
||||
@@ -80,12 +80,12 @@ public class UISceneContainer : MonoBehaviour
|
||||
|
||||
var sceneData = Main.SaveScene();
|
||||
sceneData.Filename = NameLabel.text;
|
||||
string fileName = Path.GetFullPath(Path.Combine(Settings.SaveSceneDirectory, $"{sceneData.Filename}.scene"));
|
||||
string fileName = Path.GetFullPath(Path.Combine(UISaveLoadPanel.SaveSceneDirectory, $"{sceneData.Filename}.scene"));
|
||||
|
||||
try
|
||||
{
|
||||
var settings = new JsonSerializerSettings() { TypeNameHandling = TypeNameHandling.Auto, DefaultValueHandling = DefaultValueHandling.Ignore };
|
||||
var json = JsonConvert.SerializeObject(sceneData, Formatting.Indented, settings);
|
||||
var json = JsonConvert.SerializeObject(sceneData, typeof(SceneSerializable), Formatting.Indented, settings);
|
||||
File.WriteAllText(fileName, json);
|
||||
if (!silenceMessage)
|
||||
{
|
||||
@@ -110,7 +110,7 @@ public class UISceneContainer : MonoBehaviour
|
||||
{
|
||||
Destroy(this.gameObject);
|
||||
|
||||
string path = Path.GetFullPath(Path.Combine(Settings.SaveSceneDirectory, $"{SceneData.Filename}.scene"));
|
||||
string path = Path.GetFullPath(Path.Combine(UISaveLoadPanel.SaveSceneDirectory, $"{SceneData.Filename}.scene"));
|
||||
if (File.Exists(path))
|
||||
File.Delete(path);
|
||||
|
||||
|
||||
@@ -21,8 +21,6 @@ public class UISettingsPanel : MonoBehaviour
|
||||
|
||||
public void UpdateSettings(ModelViewerSettings settings)
|
||||
{
|
||||
Debug.Log("Updating");
|
||||
|
||||
for(int i = Content.childCount -1; i >= 0; i--)
|
||||
{
|
||||
Destroy(Content.GetChild(i).gameObject);
|
||||
|
||||
Reference in New Issue
Block a user