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
@@ -0,0 +1,48 @@
using System;
using UnityEngine;
namespace RuntimeGizmos
{
public struct AxisInfo
{
public Vector3 pivot;
public Vector3 xDirection;
public Vector3 yDirection;
public Vector3 zDirection;
public void Set(Transform target, Vector3 pivot, TransformSpace space)
{
if(space == TransformSpace.Global)
{
xDirection = Vector3.right;
yDirection = Vector3.up;
zDirection = Vector3.forward;
}
else if(space == TransformSpace.Local)
{
xDirection = target.right;
yDirection = target.up;
zDirection = target.forward;
}
this.pivot = pivot;
}
public Vector3 GetXAxisEnd(float size)
{
return pivot + (xDirection * size);
}
public Vector3 GetYAxisEnd(float size)
{
return pivot + (yDirection * size);
}
public Vector3 GetZAxisEnd(float size)
{
return pivot + (zDirection * size);
}
public Vector3 GetAxisEnd(Vector3 direction, float size)
{
return pivot + (direction * size);
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 0703255fec9cd45458a07800813b3487
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,30 @@
using System;
using System.Collections.Generic;
using UnityEngine;
namespace RuntimeGizmos
{
public class AxisVectors
{
public List<Vector3> x = new List<Vector3>();
public List<Vector3> y = new List<Vector3>();
public List<Vector3> z = new List<Vector3>();
public List<Vector3> all = new List<Vector3>();
public void Add(AxisVectors axisVectors)
{
x.AddRange(axisVectors.x);
y.AddRange(axisVectors.y);
z.AddRange(axisVectors.z);
all.AddRange(axisVectors.all);
}
public void Clear()
{
x.Clear();
y.Clear();
z.Clear();
all.Clear();
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 75383c8255c26e14bbdffbc4c4630463
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 13734b144f60b3f43bc71e1771ca85ca
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,113 @@
using System;
using CommandUndoRedo;
using UnityEngine;
using System.Collections.Generic;
namespace RuntimeGizmos
{
public abstract class SelectCommand : ICommand
{
protected Transform target;
protected TransformGizmo transformGizmo;
public SelectCommand(TransformGizmo transformGizmo, Transform target)
{
this.transformGizmo = transformGizmo;
this.target = target;
}
public abstract void Execute();
public abstract void UnExecute();
}
public class AddTargetCommand : SelectCommand
{
List<Transform> targetRoots = new List<Transform>();
public AddTargetCommand(TransformGizmo transformGizmo, Transform target, List<Transform> targetRoots) : base(transformGizmo, target)
{
//Since we might have had a child selected and then selected the parent, the child would have been removed from the selected,
//so we store all the targetRoots before we add so that if we undo we can properly have the children selected again.
this.targetRoots.AddRange(targetRoots);
}
public override void Execute()
{
transformGizmo.AddTarget(target, false);
}
public override void UnExecute()
{
transformGizmo.RemoveTarget(target, false);
for(int i = 0; i < targetRoots.Count; i++)
{
transformGizmo.AddTarget(targetRoots[i], false);
}
}
}
public class RemoveTargetCommand : SelectCommand
{
public RemoveTargetCommand(TransformGizmo transformGizmo, Transform target) : base(transformGizmo, target) {}
public override void Execute()
{
transformGizmo.RemoveTarget(target, false);
}
public override void UnExecute()
{
transformGizmo.AddTarget(target, false);
}
}
public class ClearTargetsCommand : SelectCommand
{
List<Transform> targetRoots = new List<Transform>();
public ClearTargetsCommand(TransformGizmo transformGizmo, List<Transform> targetRoots) : base(transformGizmo, null)
{
this.targetRoots.AddRange(targetRoots);
}
public override void Execute()
{
transformGizmo.ClearTargets(false);
}
public override void UnExecute()
{
for(int i = 0; i < targetRoots.Count; i++)
{
transformGizmo.AddTarget(targetRoots[i], false);
}
}
}
public class ClearAndAddTargetCommand : SelectCommand
{
List<Transform> targetRoots = new List<Transform>();
public ClearAndAddTargetCommand(TransformGizmo transformGizmo, Transform target, List<Transform> targetRoots) : base(transformGizmo, target)
{
this.targetRoots.AddRange(targetRoots);
}
public override void Execute()
{
transformGizmo.ClearTargets(false);
transformGizmo.AddTarget(target, false);
}
public override void UnExecute()
{
transformGizmo.RemoveTarget(target, false);
for(int i = 0; i < targetRoots.Count; i++)
{
transformGizmo.AddTarget(targetRoots[i], false);
}
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 0049ee060d2e7ed4d94301c1c6d74154
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,53 @@
using System;
using CommandUndoRedo;
using UnityEngine;
namespace RuntimeGizmos
{
public class TransformCommand : ICommand
{
TransformValues newValues;
TransformValues oldValues;
Transform transform;
TransformGizmo transformGizmo;
public TransformCommand(TransformGizmo transformGizmo, Transform transform)
{
this.transformGizmo = transformGizmo;
this.transform = transform;
oldValues = new TransformValues() {position=transform.position, rotation=transform.rotation, scale=transform.localScale};
}
public void StoreNewTransformValues()
{
newValues = new TransformValues() {position=transform.position, rotation=transform.rotation, scale=transform.localScale};
}
public void Execute()
{
transform.position = newValues.position;
transform.rotation = newValues.rotation;
transform.localScale = newValues.scale;
transformGizmo.SetPivotPoint();
}
public void UnExecute()
{
transform.position = oldValues.position;
transform.rotation = oldValues.rotation;
transform.localScale = oldValues.scale;
transformGizmo.SetPivotPoint();
}
struct TransformValues
{
public Vector3 position;
public Quaternion rotation;
public Vector3 scale;
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: d257cdf8c9d53a4459c0c1187ac05feb
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,18 @@
namespace RuntimeGizmos
{
public enum TransformSpace {Global, Local}
public enum TransformType {Move, Rotate, Scale /*, RectTool*/, All}
public enum TransformPivot {Pivot, Center}
public enum Axis {None, X, Y, Z, Any}
//CenterType.All is the center of the current object mesh or pivot if not mesh and all its childrens mesh or pivot if no mesh.
// CenterType.All might give different results than unity I think because unity only counts empty gameobjects a little bit, as if they have less weight.
//CenterType.Solo is the center of the current objects mesh or pivot if no mesh.
//Unity seems to use colliders first to use to find how much weight the object has or something to decide how much it effects the center,
//but for now we only look at the Renderer.bounds.center, so expect some differences between unity.
public enum CenterType {All, Solo}
//ScaleType.FromPoint acts as if you are using a parent transform as your new pivot and transforming that parent instead of the child.
//ScaleType.FromPointOffset acts as if you are scaling based on a point that is offset from the actual pivot. Its similar to unity editor scaling in Center pivot mode (though a little inaccurate if object is skewed)
public enum ScaleType {FromPoint, FromPointOffset}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: cf981dc491f04c440b6c6731531f2a60
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,17 @@
using System;
using UnityEngine;
namespace RuntimeGizmos
{
public struct IntersectPoints
{
public Vector3 first;
public Vector3 second;
public IntersectPoints(Vector3 first, Vector3 second)
{
this.first = first;
this.second = second;
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 160db4dc48cd871468057690b209f902
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,35 @@
using System;
using UnityEngine;
namespace RuntimeGizmos
{
public struct Square
{
public Vector3 bottomLeft;
public Vector3 bottomRight;
public Vector3 topLeft;
public Vector3 topRight;
public Vector3 this[int index]
{
get
{
switch (index)
{
case 0:
return this.bottomLeft;
case 1:
return this.topLeft;
case 2:
return this.topRight;
case 3:
return this.bottomRight;
case 4:
return this.bottomLeft; //so we wrap around back to start
default:
return Vector3.zero;
}
}
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 9bbbbd13e719be64a845006bb088471f
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,12 @@
using System;
using UnityEngine;
namespace RuntimeGizmos
{
public class TargetInfo
{
public Vector3 centerPivotPoint;
public Vector3 previousPosition;
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: af153c5bfa29c074096e5c8845ba8fb6
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: