You've already forked UniversalViewer
Initial files
This commit is contained in:
48
Assets/Scripts/RuntimeGizmo/Objects/AxisInfo.cs
Normal file
48
Assets/Scripts/RuntimeGizmo/Objects/AxisInfo.cs
Normal file
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/RuntimeGizmo/Objects/AxisInfo.cs.meta
Normal file
11
Assets/Scripts/RuntimeGizmo/Objects/AxisInfo.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2ec66d53373599d4ab10d3431047ef79
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
30
Assets/Scripts/RuntimeGizmo/Objects/AxisVectors.cs
Normal file
30
Assets/Scripts/RuntimeGizmo/Objects/AxisVectors.cs
Normal file
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/RuntimeGizmo/Objects/AxisVectors.cs.meta
Normal file
11
Assets/Scripts/RuntimeGizmo/Objects/AxisVectors.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f9e4b8aaecb7ef247af05f25f8cc1649
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
Assets/Scripts/RuntimeGizmo/Objects/Commands.meta
Normal file
8
Assets/Scripts/RuntimeGizmo/Objects/Commands.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9e2c721722062344292b56166e9ca74f
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,36 @@
|
||||
using RuntimeGizmos;
|
||||
using UnityEngine;
|
||||
|
||||
public class HandleTransformCommand : TransformCommand
|
||||
{
|
||||
protected UIHandle _handle;
|
||||
protected int _frame;
|
||||
|
||||
public HandleTransformCommand(TransformGizmo transformGizmo, Transform transform) : base(transformGizmo, transform.GetComponent<UIHandle>().Target)
|
||||
{
|
||||
_frame = TimelineController.Instance.CurrentFrame;
|
||||
_handle = transform.GetComponent<UIHandle>();
|
||||
}
|
||||
|
||||
public HandleTransformCommand(TransformGizmo transformGizmo, HandleUndoData data) : base(transformGizmo, data.NewPosition)
|
||||
{
|
||||
_frame = TimelineController.Instance.CurrentFrame;
|
||||
_handle = data.Handle;
|
||||
oldValues = new TransformValues() { position = data.OldPosition.Position, rotation = Quaternion.Euler(data.OldPosition.Rotation), scale = data.OldPosition.Scale };
|
||||
newValues = new TransformValues() { position = transform.position, rotation = transform.rotation, scale = transform.localScale };
|
||||
}
|
||||
|
||||
public override void Execute()
|
||||
{
|
||||
TimelineController.SetCurrentFrame(_frame);
|
||||
base.Execute();
|
||||
_handle.Owner.SetKeyframe();
|
||||
}
|
||||
|
||||
public override void UnExecute()
|
||||
{
|
||||
TimelineController.SetCurrentFrame(_frame);
|
||||
base.UnExecute();
|
||||
_handle.Owner.SetKeyframe();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9b6522c7e3fe81b46a7a6678202ebdc0
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
113
Assets/Scripts/RuntimeGizmo/Objects/Commands/SelectCommand.cs
Normal file
113
Assets/Scripts/RuntimeGizmo/Objects/Commands/SelectCommand.cs
Normal file
@@ -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: 0c7e15ab509fd7e468b6efb165919591
|
||||
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
|
||||
{
|
||||
protected TransformValues newValues;
|
||||
protected TransformValues oldValues;
|
||||
|
||||
protected Transform transform;
|
||||
protected 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 virtual void StoreNewTransformValues()
|
||||
{
|
||||
newValues = new TransformValues() {position=transform.position, rotation=transform.rotation, scale=transform.localScale};
|
||||
}
|
||||
|
||||
public virtual void Execute()
|
||||
{
|
||||
transform.position = newValues.position;
|
||||
transform.rotation = newValues.rotation;
|
||||
transform.localScale = newValues.scale;
|
||||
|
||||
transformGizmo.SetPivotPoint();
|
||||
}
|
||||
|
||||
public virtual void UnExecute()
|
||||
{
|
||||
transform.position = oldValues.position;
|
||||
transform.rotation = oldValues.rotation;
|
||||
transform.localScale = oldValues.scale;
|
||||
|
||||
transformGizmo.SetPivotPoint();
|
||||
}
|
||||
|
||||
protected struct TransformValues
|
||||
{
|
||||
public Vector3 position;
|
||||
public Quaternion rotation;
|
||||
public Vector3 scale;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a8e7983a7bcbf194e9a14d9a1df46550
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
18
Assets/Scripts/RuntimeGizmo/Objects/Enums.cs
Normal file
18
Assets/Scripts/RuntimeGizmo/Objects/Enums.cs
Normal file
@@ -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}
|
||||
}
|
||||
11
Assets/Scripts/RuntimeGizmo/Objects/Enums.cs.meta
Normal file
11
Assets/Scripts/RuntimeGizmo/Objects/Enums.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 388fd9676e2322a4388b0aa95d1a374d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
17
Assets/Scripts/RuntimeGizmo/Objects/IntersectPoints.cs
Normal file
17
Assets/Scripts/RuntimeGizmo/Objects/IntersectPoints.cs
Normal file
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/RuntimeGizmo/Objects/IntersectPoints.cs.meta
Normal file
11
Assets/Scripts/RuntimeGizmo/Objects/IntersectPoints.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2d7d8ea3106f9a14cbc78642dea5d872
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
35
Assets/Scripts/RuntimeGizmo/Objects/Square.cs
Normal file
35
Assets/Scripts/RuntimeGizmo/Objects/Square.cs
Normal file
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/RuntimeGizmo/Objects/Square.cs.meta
Normal file
11
Assets/Scripts/RuntimeGizmo/Objects/Square.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: be40d501bcc089144871442884346a5c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
12
Assets/Scripts/RuntimeGizmo/Objects/TargetInfo.cs
Normal file
12
Assets/Scripts/RuntimeGizmo/Objects/TargetInfo.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace RuntimeGizmos
|
||||
{
|
||||
public class TargetInfo
|
||||
{
|
||||
public Vector3 centerPivotPoint;
|
||||
|
||||
public Vector3 previousPosition;
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/RuntimeGizmo/Objects/TargetInfo.cs.meta
Normal file
11
Assets/Scripts/RuntimeGizmo/Objects/TargetInfo.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 68eadfa5b46280f4081728bdb528dffd
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user