Pose mode preparation.

Pose serialization, deserialization (no face)
UI handle system
This commit is contained in:
Katboi01
2023-12-14 01:42:30 +01:00
parent 28549bd653
commit f928a802d7
102 changed files with 8678 additions and 45 deletions
+47
View File
@@ -0,0 +1,47 @@
using UnityEngine;
using UnityEngine.EventSystems;
public class UIElementDragger : EventTrigger
{
private bool dragging;
public Transform alsoDrag;
public Vector3 alsoDragOffset = Vector3.zero;
private void Start()
{
alsoDrag = transform.parent.GetChild(0);
if (alsoDrag)
{
alsoDragOffset = transform.position - alsoDrag.position;
}
}
public void Update()
{
if (dragging)
{
transform.position = new Vector2(Mathf.Clamp(Input.mousePosition.x, 10, Screen.width-10), Mathf.Clamp(Input.mousePosition.y, 10, Screen.height-10));
if (alsoDrag)
{
alsoDrag.position = transform.position - alsoDragOffset;
}
}
else
{
transform.position = new Vector2(Mathf.Clamp(transform.position.x, 10, Screen.width - 10), Mathf.Clamp(transform.position.y, 10, Screen.height - 10));
if (alsoDrag)
{
alsoDrag.position = transform.position - alsoDragOffset;
}
}
}
public override void OnPointerDown(PointerEventData eventData)
{
dragging = true;
}
public override void OnPointerUp(PointerEventData eventData)
{
dragging = false;
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 770f9310a8e01724fb9582052237af3d
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
+99
View File
@@ -0,0 +1,99 @@
using Newtonsoft.Json;
using System;
using System.IO;
using UnityEngine;
using UnityEngine.UI;
public class UIPoseContainer : MonoBehaviour
{
public PoseData PoseData;
public TMPro.TMP_InputField
NameLabel,
DescriptionLabel;
public TMPro.TMP_Text
InfoLabel;
[SerializeField]
private Button
_btnSave,
_btnLoad,
_btnDelete;
public static UIPoseContainer Create(PoseData data)
{
var poseContainer = Instantiate(UmaViewerUI.Instance.PoseManager.Pfb_PoseContainer, UmaViewerUI.Instance.PoseManager.SavedPoseList.content);
poseContainer.Init(data);
return poseContainer;
}
public void Init(PoseData data)
{
PoseData = data;
NameLabel.text = data.Name;
DescriptionLabel.text = data.Description;
InfoLabel.text = $"Version: {data.ViewerVersion}\nCharacter: {data.Character}\nSave date: {data.Date}";
}
public void Save()
{
UmaContainerCharacter container = UmaViewerBuilder.Instance.CurrentUMAContainer;
if (container == null) return;
var poseData = new PoseData();
poseData.Name = NameLabel.text;
poseData.Date = DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss");
poseData.Character = container.name;
poseData.Description = DescriptionLabel.text;
poseData.ViewerVersion = Application.version;
poseData.Bones = container.SaveBones();
string fullpath = $"{Application.dataPath}/../Poses/{poseData.Name}.umaPose";
fullpath = Path.GetFullPath(fullpath);
try
{
Directory.CreateDirectory(Application.dataPath + "/../Poses");
File.WriteAllText(fullpath, JsonConvert.SerializeObject(poseData));
UmaViewerUI.Instance.ShowMessage($"Saved pose: {fullpath}", UIMessageType.Success);
//Only replace the data if everything succeeded
Init(poseData);
}
catch (Exception e)
{
UmaViewerUI.Instance.ShowMessage(e.Message, UIMessageType.Error);
}
}
public void Load()
{
UmaViewerUI.Instance.PoseManager.SetPoseMode(true);
UmaContainerCharacter container = UmaViewerBuilder.Instance.CurrentUMAContainer;
if (container == null) return;
container.LoadBones(PoseData);
}
public void Delete()
{
Destroy(gameObject);
string fullpath = $"{Application.dataPath}/../Poses/{PoseData.Name}.umaPose";
fullpath = Path.GetFullPath(fullpath);
if(File.Exists(fullpath))
{
File.Delete(fullpath);
}
UmaViewerUI.Instance.ShowMessage($"Deleted pose: {fullpath}", UIMessageType.Success);
}
}
+11
View File
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: e1c176a293fb01e4886a4456e855e23f
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: