You've already forked UniversalViewer
Initial files
This commit is contained in:
8
Assets/Scripts/RuntimeGizmo/Custom.meta
Normal file
8
Assets/Scripts/RuntimeGizmo/Custom.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 60a1866c7bc5fdd4ba1f43e6608af33e
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
228
Assets/Scripts/RuntimeGizmo/Custom/TransformGizmoCustomGizmo.cs
Normal file
228
Assets/Scripts/RuntimeGizmo/Custom/TransformGizmoCustomGizmo.cs
Normal file
@@ -0,0 +1,228 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace RuntimeGizmos
|
||||
{
|
||||
//Currently doesnt really handle TransformType.All
|
||||
public class TransformGizmoCustomGizmo : MonoBehaviour
|
||||
{
|
||||
public bool autoFindTransformGizmo = true;
|
||||
public TransformGizmo transformGizmo;
|
||||
|
||||
public CustomTransformGizmos customTranslationGizmos = new CustomTransformGizmos();
|
||||
public CustomTransformGizmos customRotationGizmos = new CustomTransformGizmos();
|
||||
public CustomTransformGizmos customScaleGizmos = new CustomTransformGizmos();
|
||||
|
||||
public bool scaleBasedOnDistance = true;
|
||||
public float scaleMultiplier = .4f;
|
||||
|
||||
public int gizmoLayer = 2; //2 is the ignoreRaycast layer. Set to whatever you want.
|
||||
|
||||
LayerMask mask;
|
||||
|
||||
void Awake()
|
||||
{
|
||||
if(transformGizmo == null && autoFindTransformGizmo)
|
||||
{
|
||||
transformGizmo = GameObject.FindObjectOfType<TransformGizmo>();
|
||||
}
|
||||
|
||||
transformGizmo.manuallyHandleGizmo = true;
|
||||
|
||||
//Since we are using a mesh, rotating can get weird due to how the rotation method works,
|
||||
//so we use a different rotation method that will let us rotate by acting like our custom rotation gizmo is a wheel.
|
||||
//Can still give weird results depending on camera angle, but I think its more understanding for the user as to why its messing up.
|
||||
transformGizmo.circularRotationMethod = true;
|
||||
|
||||
mask = LayerMask.GetMask(LayerMask.LayerToName(gizmoLayer));
|
||||
|
||||
customTranslationGizmos.Init(gizmoLayer);
|
||||
customRotationGizmos.Init(gizmoLayer);
|
||||
customScaleGizmos.Init(gizmoLayer);
|
||||
}
|
||||
|
||||
void OnEnable()
|
||||
{
|
||||
transformGizmo.onCheckForSelectedAxis += CheckForSelectedAxis;
|
||||
transformGizmo.onDrawCustomGizmo += OnDrawCustomGizmos;
|
||||
}
|
||||
void OnDisable()
|
||||
{
|
||||
transformGizmo.onCheckForSelectedAxis -= CheckForSelectedAxis;
|
||||
transformGizmo.onDrawCustomGizmo -= OnDrawCustomGizmos;
|
||||
}
|
||||
|
||||
void CheckForSelectedAxis()
|
||||
{
|
||||
ShowProperGizmoType();
|
||||
|
||||
if(Input.GetMouseButtonDown(0))
|
||||
{
|
||||
RaycastHit hitInfo;
|
||||
if(Physics.Raycast(transformGizmo.myCamera.ScreenPointToRay(Input.mousePosition), out hitInfo, Mathf.Infinity, mask))
|
||||
{
|
||||
Axis selectedAxis = Axis.None;
|
||||
TransformType type = transformGizmo.transformType;
|
||||
|
||||
if(selectedAxis == Axis.None && transformGizmo.TransformTypeContains(TransformType.Move))
|
||||
{
|
||||
selectedAxis = customTranslationGizmos.GetSelectedAxis(hitInfo.collider);
|
||||
type = TransformType.Move;
|
||||
}
|
||||
if(selectedAxis == Axis.None && transformGizmo.TransformTypeContains(TransformType.Rotate))
|
||||
{
|
||||
selectedAxis = customRotationGizmos.GetSelectedAxis(hitInfo.collider);
|
||||
type = TransformType.Rotate;
|
||||
}
|
||||
if(selectedAxis == Axis.None && transformGizmo.TransformTypeContains(TransformType.Scale))
|
||||
{
|
||||
selectedAxis = customScaleGizmos.GetSelectedAxis(hitInfo.collider);
|
||||
type = TransformType.Scale;
|
||||
}
|
||||
|
||||
transformGizmo.SetTranslatingAxis(type, selectedAxis);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void OnDrawCustomGizmos()
|
||||
{
|
||||
if(transformGizmo.TranslatingTypeContains(TransformType.Move)) DrawCustomGizmo(customTranslationGizmos);
|
||||
if(transformGizmo.TranslatingTypeContains(TransformType.Rotate)) DrawCustomGizmo(customRotationGizmos);
|
||||
if(transformGizmo.TranslatingTypeContains(TransformType.Scale)) DrawCustomGizmo(customScaleGizmos);
|
||||
}
|
||||
|
||||
void DrawCustomGizmo(CustomTransformGizmos customGizmo)
|
||||
{
|
||||
AxisInfo axisInfo = transformGizmo.GetAxisInfo();
|
||||
customGizmo.SetAxis(axisInfo);
|
||||
customGizmo.SetPosition(transformGizmo.pivotPoint);
|
||||
|
||||
Vector4 totalScaleMultiplier = Vector4.one;
|
||||
if(scaleBasedOnDistance)
|
||||
{
|
||||
totalScaleMultiplier.w *= (scaleMultiplier * transformGizmo.GetDistanceMultiplier());
|
||||
}
|
||||
|
||||
if(transformGizmo.transformingType == TransformType.Scale)
|
||||
{
|
||||
float totalScaleAmount = 1f + transformGizmo.totalScaleAmount;
|
||||
if(transformGizmo.translatingAxis == Axis.Any) totalScaleMultiplier += (Vector4.one * totalScaleAmount);
|
||||
else if(transformGizmo.translatingAxis == Axis.X) totalScaleMultiplier.x *= totalScaleAmount;
|
||||
else if(transformGizmo.translatingAxis == Axis.Y) totalScaleMultiplier.y *= totalScaleAmount;
|
||||
else if(transformGizmo.translatingAxis == Axis.Z) totalScaleMultiplier.z *= totalScaleAmount;
|
||||
}
|
||||
|
||||
customGizmo.ScaleMultiply(totalScaleMultiplier);
|
||||
}
|
||||
|
||||
void ShowProperGizmoType()
|
||||
{
|
||||
bool hasSelection = transformGizmo.mainTargetRoot != null;
|
||||
customTranslationGizmos.SetEnable(hasSelection && transformGizmo.TranslatingTypeContains(TransformType.Move));
|
||||
customRotationGizmos.SetEnable(hasSelection && transformGizmo.TranslatingTypeContains(TransformType.Rotate));
|
||||
customScaleGizmos.SetEnable(hasSelection && transformGizmo.TranslatingTypeContains(TransformType.Scale));
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class CustomTransformGizmos
|
||||
{
|
||||
public Transform xAxisGizmo;
|
||||
public Transform yAxisGizmo;
|
||||
public Transform zAxisGizmo;
|
||||
public Transform anyAxisGizmo;
|
||||
|
||||
Collider xAxisGizmoCollider;
|
||||
Collider yAxisGizmoCollider;
|
||||
Collider zAxisGizmoCollider;
|
||||
Collider anyAxisGizmoCollider;
|
||||
|
||||
Vector3 originalXAxisScale;
|
||||
Vector3 originalYAxisScale;
|
||||
Vector3 originalZAxisScale;
|
||||
Vector3 originalAnyAxisScale;
|
||||
|
||||
public void Init(int layer)
|
||||
{
|
||||
if(xAxisGizmo != null)
|
||||
{
|
||||
SetLayerRecursively(xAxisGizmo.gameObject, layer);
|
||||
xAxisGizmoCollider = xAxisGizmo.GetComponentInChildren<Collider>();
|
||||
originalXAxisScale = xAxisGizmo.localScale;
|
||||
}
|
||||
if(yAxisGizmo != null)
|
||||
{
|
||||
SetLayerRecursively(yAxisGizmo.gameObject, layer);
|
||||
yAxisGizmoCollider = yAxisGizmo.GetComponentInChildren<Collider>();
|
||||
originalYAxisScale = yAxisGizmo.localScale;
|
||||
}
|
||||
if(zAxisGizmo != null)
|
||||
{
|
||||
SetLayerRecursively(zAxisGizmo.gameObject, layer);
|
||||
zAxisGizmoCollider = zAxisGizmo.GetComponentInChildren<Collider>();
|
||||
originalZAxisScale = zAxisGizmo.localScale;
|
||||
}
|
||||
if(anyAxisGizmo != null)
|
||||
{
|
||||
SetLayerRecursively(anyAxisGizmo.gameObject, layer);
|
||||
anyAxisGizmoCollider = anyAxisGizmo.GetComponentInChildren<Collider>();
|
||||
originalAnyAxisScale = anyAxisGizmo.localScale;
|
||||
}
|
||||
}
|
||||
|
||||
public void SetEnable(bool enable)
|
||||
{
|
||||
if(xAxisGizmo != null && xAxisGizmo.gameObject.activeSelf != enable) xAxisGizmo.gameObject.SetActive(enable);
|
||||
if(yAxisGizmo != null && yAxisGizmo.gameObject.activeSelf != enable) yAxisGizmo.gameObject.SetActive(enable);
|
||||
if(zAxisGizmo != null && zAxisGizmo.gameObject.activeSelf != enable) zAxisGizmo.gameObject.SetActive(enable);
|
||||
if(anyAxisGizmo != null && anyAxisGizmo.gameObject.activeSelf != enable) anyAxisGizmo.gameObject.SetActive(enable);
|
||||
}
|
||||
|
||||
public void SetAxis(AxisInfo axisInfo)
|
||||
{
|
||||
Quaternion lookRotation = Quaternion.LookRotation(axisInfo.zDirection, axisInfo.yDirection);
|
||||
|
||||
if(xAxisGizmo != null) xAxisGizmo.rotation = lookRotation;
|
||||
if(yAxisGizmo != null) yAxisGizmo.rotation = lookRotation;
|
||||
if(zAxisGizmo != null) zAxisGizmo.rotation = lookRotation;
|
||||
if(anyAxisGizmo != null) anyAxisGizmo.rotation = lookRotation;
|
||||
}
|
||||
|
||||
public void SetPosition(Vector3 position)
|
||||
{
|
||||
if(xAxisGizmo != null) xAxisGizmo.position = position;
|
||||
if(yAxisGizmo != null) yAxisGizmo.position = position;
|
||||
if(zAxisGizmo != null) zAxisGizmo.position = position;
|
||||
if(anyAxisGizmo != null) anyAxisGizmo.position = position;
|
||||
}
|
||||
|
||||
public void ScaleMultiply(Vector4 scaleMultiplier)
|
||||
{
|
||||
if(xAxisGizmo != null) xAxisGizmo.localScale = Vector3.Scale(originalXAxisScale, new Vector3(scaleMultiplier.w + scaleMultiplier.x, scaleMultiplier.w, scaleMultiplier.w));
|
||||
if(yAxisGizmo != null) yAxisGizmo.localScale = Vector3.Scale(originalYAxisScale, new Vector3(scaleMultiplier.w, scaleMultiplier.w + scaleMultiplier.y, scaleMultiplier.w));
|
||||
if(zAxisGizmo != null) zAxisGizmo.localScale = Vector3.Scale(originalZAxisScale, new Vector3(scaleMultiplier.w, scaleMultiplier.w, scaleMultiplier.w + scaleMultiplier.z));
|
||||
if(anyAxisGizmo != null) anyAxisGizmo.localScale = originalAnyAxisScale * scaleMultiplier.w;
|
||||
}
|
||||
|
||||
public Axis GetSelectedAxis(Collider selectedCollider)
|
||||
{
|
||||
if(xAxisGizmoCollider != null && xAxisGizmoCollider == selectedCollider) return Axis.X;
|
||||
if(yAxisGizmoCollider != null && yAxisGizmoCollider == selectedCollider) return Axis.Y;
|
||||
if(zAxisGizmoCollider != null && zAxisGizmoCollider == selectedCollider) return Axis.Z;
|
||||
if(anyAxisGizmoCollider != null && anyAxisGizmoCollider == selectedCollider) return Axis.Any;
|
||||
|
||||
return Axis.None;
|
||||
}
|
||||
|
||||
void SetLayerRecursively(GameObject gameObject, int layer)
|
||||
{
|
||||
Transform[] selfAndChildren = gameObject.GetComponentsInChildren<Transform>(true);
|
||||
|
||||
for(int i = 0; i < selfAndChildren.Length; i++)
|
||||
{
|
||||
selfAndChildren[i].gameObject.layer = layer;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cdd2b15eef7330a409ca57669e82a33a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
460
Assets/Scripts/RuntimeGizmo/ExampleScene.unity
Normal file
460
Assets/Scripts/RuntimeGizmo/ExampleScene.unity
Normal file
@@ -0,0 +1,460 @@
|
||||
%YAML 1.1
|
||||
%TAG !u! tag:unity3d.com,2011:
|
||||
--- !u!29 &1
|
||||
OcclusionCullingSettings:
|
||||
m_ObjectHideFlags: 0
|
||||
serializedVersion: 2
|
||||
m_OcclusionBakeSettings:
|
||||
smallestOccluder: 5
|
||||
smallestHole: 0.25
|
||||
backfaceThreshold: 100
|
||||
m_SceneGUID: 00000000000000000000000000000000
|
||||
m_OcclusionCullingData: {fileID: 0}
|
||||
--- !u!104 &2
|
||||
RenderSettings:
|
||||
m_ObjectHideFlags: 0
|
||||
serializedVersion: 9
|
||||
m_Fog: 0
|
||||
m_FogColor: {r: 0.5, g: 0.5, b: 0.5, a: 1}
|
||||
m_FogMode: 3
|
||||
m_FogDensity: 0.01
|
||||
m_LinearFogStart: 0
|
||||
m_LinearFogEnd: 300
|
||||
m_AmbientSkyColor: {r: 0.212, g: 0.227, b: 0.259, a: 1}
|
||||
m_AmbientEquatorColor: {r: 0.114, g: 0.125, b: 0.133, a: 1}
|
||||
m_AmbientGroundColor: {r: 0.047, g: 0.043, b: 0.035, a: 1}
|
||||
m_AmbientIntensity: 1
|
||||
m_AmbientMode: 0
|
||||
m_SubtractiveShadowColor: {r: 0.42, g: 0.478, b: 0.627, a: 1}
|
||||
m_SkyboxMaterial: {fileID: 10304, guid: 0000000000000000f000000000000000, type: 0}
|
||||
m_HaloStrength: 0.5
|
||||
m_FlareStrength: 1
|
||||
m_FlareFadeSpeed: 3
|
||||
m_HaloTexture: {fileID: 0}
|
||||
m_SpotCookie: {fileID: 10001, guid: 0000000000000000e000000000000000, type: 0}
|
||||
m_DefaultReflectionMode: 0
|
||||
m_DefaultReflectionResolution: 128
|
||||
m_ReflectionBounces: 1
|
||||
m_ReflectionIntensity: 1
|
||||
m_CustomReflection: {fileID: 0}
|
||||
m_Sun: {fileID: 0}
|
||||
m_IndirectSpecularColor: {r: 0, g: 0, b: 0, a: 1}
|
||||
m_UseRadianceAmbientProbe: 0
|
||||
--- !u!157 &3
|
||||
LightmapSettings:
|
||||
m_ObjectHideFlags: 0
|
||||
serializedVersion: 12
|
||||
m_GIWorkflowMode: 0
|
||||
m_GISettings:
|
||||
serializedVersion: 2
|
||||
m_BounceScale: 1
|
||||
m_IndirectOutputScale: 1
|
||||
m_AlbedoBoost: 1
|
||||
m_EnvironmentLightingMode: 0
|
||||
m_EnableBakedLightmaps: 1
|
||||
m_EnableRealtimeLightmaps: 1
|
||||
m_LightmapEditorSettings:
|
||||
serializedVersion: 12
|
||||
m_Resolution: 2
|
||||
m_BakeResolution: 40
|
||||
m_AtlasSize: 1024
|
||||
m_AO: 0
|
||||
m_AOMaxDistance: 1
|
||||
m_CompAOExponent: 1
|
||||
m_CompAOExponentDirect: 0
|
||||
m_ExtractAmbientOcclusion: 0
|
||||
m_Padding: 2
|
||||
m_LightmapParameters: {fileID: 0}
|
||||
m_LightmapsBakeMode: 1
|
||||
m_TextureCompression: 1
|
||||
m_FinalGather: 0
|
||||
m_FinalGatherFiltering: 1
|
||||
m_FinalGatherRayCount: 256
|
||||
m_ReflectionCompression: 2
|
||||
m_MixedBakeMode: 1
|
||||
m_BakeBackend: 0
|
||||
m_PVRSampling: 1
|
||||
m_PVRDirectSampleCount: 32
|
||||
m_PVRSampleCount: 512
|
||||
m_PVRBounces: 2
|
||||
m_PVREnvironmentSampleCount: 512
|
||||
m_PVREnvironmentReferencePointCount: 2048
|
||||
m_PVRFilteringMode: 0
|
||||
m_PVRDenoiserTypeDirect: 0
|
||||
m_PVRDenoiserTypeIndirect: 0
|
||||
m_PVRDenoiserTypeAO: 0
|
||||
m_PVRFilterTypeDirect: 0
|
||||
m_PVRFilterTypeIndirect: 0
|
||||
m_PVRFilterTypeAO: 0
|
||||
m_PVREnvironmentMIS: 0
|
||||
m_PVRCulling: 1
|
||||
m_PVRFilteringGaussRadiusDirect: 1
|
||||
m_PVRFilteringGaussRadiusIndirect: 5
|
||||
m_PVRFilteringGaussRadiusAO: 2
|
||||
m_PVRFilteringAtrousPositionSigmaDirect: 0.5
|
||||
m_PVRFilteringAtrousPositionSigmaIndirect: 2
|
||||
m_PVRFilteringAtrousPositionSigmaAO: 1
|
||||
m_ExportTrainingData: 0
|
||||
m_TrainingDataDestination: TrainingData
|
||||
m_LightProbeSampleCountMultiplier: 4
|
||||
m_LightingDataAsset: {fileID: 0}
|
||||
m_LightingSettings: {fileID: 4890085278179872738, guid: 51ffe0a0f225b594bad25e66af6c8e32, type: 2}
|
||||
--- !u!196 &4
|
||||
NavMeshSettings:
|
||||
serializedVersion: 2
|
||||
m_ObjectHideFlags: 0
|
||||
m_BuildSettings:
|
||||
serializedVersion: 2
|
||||
agentTypeID: 0
|
||||
agentRadius: 0.5
|
||||
agentHeight: 2
|
||||
agentSlope: 45
|
||||
agentClimb: 0.4
|
||||
ledgeDropHeight: 0
|
||||
maxJumpAcrossDistance: 0
|
||||
minRegionArea: 2
|
||||
manualCellSize: 0
|
||||
cellSize: 0.16666667
|
||||
manualTileSize: 0
|
||||
tileSize: 256
|
||||
accuratePlacement: 0
|
||||
maxJobWorkers: 0
|
||||
preserveTilesOutsideBounds: 0
|
||||
debug:
|
||||
m_Flags: 0
|
||||
m_NavMeshData: {fileID: 0}
|
||||
--- !u!1 &343817361
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
serializedVersion: 6
|
||||
m_Component:
|
||||
- component: {fileID: 343817366}
|
||||
- component: {fileID: 343817365}
|
||||
- component: {fileID: 343817363}
|
||||
- component: {fileID: 343817362}
|
||||
m_Layer: 0
|
||||
m_Name: TransformGizmoCamera
|
||||
m_TagString: MainCamera
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
m_StaticEditorFlags: 0
|
||||
m_IsActive: 1
|
||||
--- !u!114 &343817362
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 343817361}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 1c0ad0e8e55c95c4e931911c4b943a64, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
space: 0
|
||||
transformType: 0
|
||||
pivot: 0
|
||||
centerType: 0
|
||||
scaleType: 0
|
||||
SetMoveType: 119
|
||||
SetRotateType: 101
|
||||
SetScaleType: 114
|
||||
SetAllTransformType: 121
|
||||
SetSpaceToggle: 120
|
||||
SetPivotModeToggle: 122
|
||||
SetCenterTypeToggle: 99
|
||||
SetScaleTypeToggle: 115
|
||||
translationSnapping: 306
|
||||
AddSelection: 304
|
||||
RemoveSelection: 306
|
||||
ActionKey: 304
|
||||
UndoAction: 122
|
||||
RedoAction: 121
|
||||
xColor: {r: 1, g: 0, b: 0, a: 0.8}
|
||||
yColor: {r: 0, g: 1, b: 0, a: 0.8}
|
||||
zColor: {r: 0, g: 0, b: 1, a: 0.8}
|
||||
allColor: {r: 0.7, g: 0.7, b: 0.7, a: 0.8}
|
||||
selectedColor: {r: 1, g: 1, b: 0, a: 0.8}
|
||||
hoverColor: {r: 1, g: 0.75, b: 0, a: 0.8}
|
||||
planesOpacity: 0.5
|
||||
movementSnap: 0.25
|
||||
rotationSnap: 15
|
||||
scaleSnap: 1
|
||||
handleLength: 0.25
|
||||
handleWidth: 0.003
|
||||
planeSize: 0.035
|
||||
triangleSize: 0.03
|
||||
boxSize: 0.03
|
||||
circleDetail: 40
|
||||
allMoveHandleLengthMultiplier: 1
|
||||
allRotateHandleLengthMultiplier: 1.4
|
||||
allScaleHandleLengthMultiplier: 1.6
|
||||
minSelectedDistanceCheck: 0.01
|
||||
moveSpeedMultiplier: 1
|
||||
scaleSpeedMultiplier: 1
|
||||
rotateSpeedMultiplier: 1
|
||||
allRotateSpeedMultiplier: 20
|
||||
useFirstSelectedAsMain: 1
|
||||
circularRotationMethod: 0
|
||||
forceUpdatePivotPointOnChange: 1
|
||||
maxUndoStored: 100
|
||||
manuallyHandleGizmo: 0
|
||||
selectionMask:
|
||||
serializedVersion: 2
|
||||
m_Bits: 4294967291
|
||||
--- !u!124 &343817363
|
||||
Behaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 343817361}
|
||||
m_Enabled: 1
|
||||
--- !u!20 &343817365
|
||||
Camera:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 343817361}
|
||||
m_Enabled: 1
|
||||
serializedVersion: 2
|
||||
m_ClearFlags: 1
|
||||
m_BackGroundColor: {r: 0.19215687, g: 0.3019608, b: 0.4745098, a: 0}
|
||||
m_projectionMatrixMode: 1
|
||||
m_GateFitMode: 2
|
||||
m_FOVAxisMode: 0
|
||||
m_SensorSize: {x: 36, y: 24}
|
||||
m_LensShift: {x: 0, y: 0}
|
||||
m_FocalLength: 50
|
||||
m_NormalizedViewPortRect:
|
||||
serializedVersion: 2
|
||||
x: 0
|
||||
y: 0
|
||||
width: 1
|
||||
height: 1
|
||||
near clip plane: 0.3
|
||||
far clip plane: 1000
|
||||
field of view: 60
|
||||
orthographic: 0
|
||||
orthographic size: 5
|
||||
m_Depth: -1
|
||||
m_CullingMask:
|
||||
serializedVersion: 2
|
||||
m_Bits: 4294967295
|
||||
m_RenderingPath: -1
|
||||
m_TargetTexture: {fileID: 0}
|
||||
m_TargetDisplay: 0
|
||||
m_TargetEye: 3
|
||||
m_HDR: 0
|
||||
m_AllowMSAA: 1
|
||||
m_AllowDynamicResolution: 0
|
||||
m_ForceIntoRT: 0
|
||||
m_OcclusionCulling: 1
|
||||
m_StereoConvergence: 10
|
||||
m_StereoSeparation: 0.022
|
||||
--- !u!4 &343817366
|
||||
Transform:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 343817361}
|
||||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||
m_LocalPosition: {x: 0, y: 1, z: -10}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_Children: []
|
||||
m_Father: {fileID: 0}
|
||||
m_RootOrder: 0
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
--- !u!1 &1138828411
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
serializedVersion: 6
|
||||
m_Component:
|
||||
- component: {fileID: 1138828413}
|
||||
- component: {fileID: 1138828412}
|
||||
m_Layer: 0
|
||||
m_Name: Directional Light
|
||||
m_TagString: Untagged
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
m_StaticEditorFlags: 0
|
||||
m_IsActive: 1
|
||||
--- !u!108 &1138828412
|
||||
Light:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 1138828411}
|
||||
m_Enabled: 1
|
||||
serializedVersion: 10
|
||||
m_Type: 1
|
||||
m_Shape: 0
|
||||
m_Color: {r: 1, g: 0.95686275, b: 0.8392157, a: 1}
|
||||
m_Intensity: 0.8
|
||||
m_Range: 10
|
||||
m_SpotAngle: 30
|
||||
m_InnerSpotAngle: 21.80208
|
||||
m_CookieSize: 10
|
||||
m_Shadows:
|
||||
m_Type: 2
|
||||
m_Resolution: -1
|
||||
m_CustomResolution: -1
|
||||
m_Strength: 1
|
||||
m_Bias: 0.05
|
||||
m_NormalBias: 0.4
|
||||
m_NearPlane: 0.2
|
||||
m_CullingMatrixOverride:
|
||||
e00: 1
|
||||
e01: 0
|
||||
e02: 0
|
||||
e03: 0
|
||||
e10: 0
|
||||
e11: 1
|
||||
e12: 0
|
||||
e13: 0
|
||||
e20: 0
|
||||
e21: 0
|
||||
e22: 1
|
||||
e23: 0
|
||||
e30: 0
|
||||
e31: 0
|
||||
e32: 0
|
||||
e33: 1
|
||||
m_UseCullingMatrixOverride: 0
|
||||
m_Cookie: {fileID: 0}
|
||||
m_DrawHalo: 0
|
||||
m_Flare: {fileID: 0}
|
||||
m_RenderMode: 0
|
||||
m_CullingMask:
|
||||
serializedVersion: 2
|
||||
m_Bits: 4294967295
|
||||
m_RenderingLayerMask: 1
|
||||
m_Lightmapping: 4
|
||||
m_LightShadowCasterMode: 0
|
||||
m_AreaSize: {x: 1, y: 1}
|
||||
m_BounceIntensity: 1
|
||||
m_ColorTemperature: 6570
|
||||
m_UseColorTemperature: 0
|
||||
m_BoundingSphereOverride: {x: 0, y: 0, z: 0, w: 0}
|
||||
m_UseBoundingSphereOverride: 0
|
||||
m_UseViewFrustumForShadowCasterCull: 1
|
||||
m_ShadowRadius: 0
|
||||
m_ShadowAngle: 0
|
||||
--- !u!4 &1138828413
|
||||
Transform:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 1138828411}
|
||||
m_LocalRotation: {x: 0.40821788, y: -0.23456968, z: 0.10938163, w: 0.8754261}
|
||||
m_LocalPosition: {x: 15.92, y: -23.72, z: -27.58}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_Children: []
|
||||
m_Father: {fileID: 0}
|
||||
m_RootOrder: 1
|
||||
m_LocalEulerAnglesHint: {x: 50, y: -30, z: 0}
|
||||
--- !u!1 &1755359865
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
serializedVersion: 6
|
||||
m_Component:
|
||||
- component: {fileID: 1755359869}
|
||||
- component: {fileID: 1755359868}
|
||||
- component: {fileID: 1755359867}
|
||||
- component: {fileID: 1755359866}
|
||||
m_Layer: 0
|
||||
m_Name: Cube
|
||||
m_TagString: Untagged
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
m_StaticEditorFlags: 0
|
||||
m_IsActive: 1
|
||||
--- !u!23 &1755359866
|
||||
MeshRenderer:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 1755359865}
|
||||
m_Enabled: 1
|
||||
m_CastShadows: 1
|
||||
m_ReceiveShadows: 1
|
||||
m_DynamicOccludee: 1
|
||||
m_MotionVectors: 1
|
||||
m_LightProbeUsage: 1
|
||||
m_ReflectionProbeUsage: 1
|
||||
m_RayTracingMode: 2
|
||||
m_RayTraceProcedural: 0
|
||||
m_RenderingLayerMask: 1
|
||||
m_RendererPriority: 0
|
||||
m_Materials:
|
||||
- {fileID: 10303, guid: 0000000000000000f000000000000000, type: 0}
|
||||
m_StaticBatchInfo:
|
||||
firstSubMesh: 0
|
||||
subMeshCount: 0
|
||||
m_StaticBatchRoot: {fileID: 0}
|
||||
m_ProbeAnchor: {fileID: 0}
|
||||
m_LightProbeVolumeOverride: {fileID: 0}
|
||||
m_ScaleInLightmap: 1
|
||||
m_ReceiveGI: 1
|
||||
m_PreserveUVs: 1
|
||||
m_IgnoreNormalsForChartDetection: 0
|
||||
m_ImportantGI: 0
|
||||
m_StitchLightmapSeams: 1
|
||||
m_SelectedEditorRenderState: 3
|
||||
m_MinimumChartSize: 4
|
||||
m_AutoUVMaxDistance: 0.5
|
||||
m_AutoUVMaxAngle: 89
|
||||
m_LightmapParameters: {fileID: 0}
|
||||
m_SortingLayerID: 0
|
||||
m_SortingLayer: 0
|
||||
m_SortingOrder: 0
|
||||
m_AdditionalVertexStreams: {fileID: 0}
|
||||
--- !u!65 &1755359867
|
||||
BoxCollider:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 1755359865}
|
||||
m_Material: {fileID: 0}
|
||||
m_IsTrigger: 0
|
||||
m_Enabled: 1
|
||||
serializedVersion: 2
|
||||
m_Size: {x: 1, y: 1, z: 1}
|
||||
m_Center: {x: 0, y: 0, z: 0}
|
||||
--- !u!33 &1755359868
|
||||
MeshFilter:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 1755359865}
|
||||
m_Mesh: {fileID: 10202, guid: 0000000000000000e000000000000000, type: 0}
|
||||
--- !u!4 &1755359869
|
||||
Transform:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 1755359865}
|
||||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||
m_LocalPosition: {x: -2.48, y: 0.3, z: -4.1958246}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_Children: []
|
||||
m_Father: {fileID: 0}
|
||||
m_RootOrder: 2
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
8
Assets/Scripts/RuntimeGizmo/ExampleScene.unity.meta
Normal file
8
Assets/Scripts/RuntimeGizmo/ExampleScene.unity.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 678d4f03f0bd01b4faf0609706d37c25
|
||||
timeCreated: 1476929737
|
||||
licenseType: Free
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
63
Assets/Scripts/RuntimeGizmo/ExampleSceneSettings.lighting
Normal file
63
Assets/Scripts/RuntimeGizmo/ExampleSceneSettings.lighting
Normal file
@@ -0,0 +1,63 @@
|
||||
%YAML 1.1
|
||||
%TAG !u! tag:unity3d.com,2011:
|
||||
--- !u!850595691 &4890085278179872738
|
||||
LightingSettings:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_Name: ExampleSceneSettings
|
||||
serializedVersion: 3
|
||||
m_GIWorkflowMode: 0
|
||||
m_EnableBakedLightmaps: 1
|
||||
m_EnableRealtimeLightmaps: 1
|
||||
m_RealtimeEnvironmentLighting: 1
|
||||
m_BounceScale: 1
|
||||
m_AlbedoBoost: 1
|
||||
m_IndirectOutputScale: 1
|
||||
m_UsingShadowmask: 0
|
||||
m_BakeBackend: 0
|
||||
m_LightmapMaxSize: 1024
|
||||
m_BakeResolution: 40
|
||||
m_Padding: 2
|
||||
m_TextureCompression: 1
|
||||
m_AO: 0
|
||||
m_AOMaxDistance: 1
|
||||
m_CompAOExponent: 1
|
||||
m_CompAOExponentDirect: 0
|
||||
m_ExtractAO: 0
|
||||
m_MixedBakeMode: 1
|
||||
m_LightmapsBakeMode: 1
|
||||
m_FilterMode: 1
|
||||
m_LightmapParameters: {fileID: 15204, guid: 0000000000000000f000000000000000, type: 0}
|
||||
m_ExportTrainingData: 0
|
||||
m_TrainingDataDestination: TrainingData
|
||||
m_RealtimeResolution: 2
|
||||
m_ForceWhiteAlbedo: 0
|
||||
m_ForceUpdates: 0
|
||||
m_FinalGather: 0
|
||||
m_FinalGatherRayCount: 256
|
||||
m_FinalGatherFiltering: 1
|
||||
m_PVRCulling: 1
|
||||
m_PVRSampling: 1
|
||||
m_PVRDirectSampleCount: 32
|
||||
m_PVRSampleCount: 512
|
||||
m_PVREnvironmentSampleCount: 512
|
||||
m_PVREnvironmentReferencePointCount: 2048
|
||||
m_LightProbeSampleCountMultiplier: 4
|
||||
m_PVRBounces: 2
|
||||
m_PVRMinBounces: 2
|
||||
m_PVREnvironmentMIS: 0
|
||||
m_PVRFilteringMode: 0
|
||||
m_PVRDenoiserTypeDirect: 0
|
||||
m_PVRDenoiserTypeIndirect: 0
|
||||
m_PVRDenoiserTypeAO: 0
|
||||
m_PVRFilterTypeDirect: 0
|
||||
m_PVRFilterTypeIndirect: 0
|
||||
m_PVRFilterTypeAO: 0
|
||||
m_PVRFilteringGaussRadiusDirect: 1
|
||||
m_PVRFilteringGaussRadiusIndirect: 5
|
||||
m_PVRFilteringGaussRadiusAO: 2
|
||||
m_PVRFilteringAtrousPositionSigmaDirect: 0.5
|
||||
m_PVRFilteringAtrousPositionSigmaIndirect: 2
|
||||
m_PVRFilteringAtrousPositionSigmaAO: 1
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 51ffe0a0f225b594bad25e66af6c8e32
|
||||
NativeFormatImporter:
|
||||
externalObjects: {}
|
||||
mainObjectFileID: 4890085278179872738
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
Assets/Scripts/RuntimeGizmo/Helpers.meta
Normal file
8
Assets/Scripts/RuntimeGizmo/Helpers.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: dee424a967eea484fadbac8469d555f5
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
18
Assets/Scripts/RuntimeGizmo/Helpers/ExtMathf.cs
Normal file
18
Assets/Scripts/RuntimeGizmo/Helpers/ExtMathf.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
using System;
|
||||
|
||||
namespace RuntimeGizmos
|
||||
{
|
||||
public static class ExtMathf
|
||||
{
|
||||
public static float Squared(this float value)
|
||||
{
|
||||
return value * value;
|
||||
}
|
||||
|
||||
public static float SafeDivide(float value, float divider)
|
||||
{
|
||||
if(divider == 0) return 0;
|
||||
return value / divider;
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/RuntimeGizmo/Helpers/ExtMathf.cs.meta
Normal file
11
Assets/Scripts/RuntimeGizmo/Helpers/ExtMathf.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7c2828eb1bcf6ac4daaad1e58e5abfca
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
87
Assets/Scripts/RuntimeGizmo/Helpers/ExtTransform.cs
Normal file
87
Assets/Scripts/RuntimeGizmo/Helpers/ExtTransform.cs
Normal file
@@ -0,0 +1,87 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace RuntimeGizmos
|
||||
{
|
||||
public static class ExtTransform
|
||||
{
|
||||
//This acts as if you are using a parent transform as your new pivot and transforming that parent instead of the child.
|
||||
//So instead of creating a gameobject and parenting "target" to it and translating only the parent gameobject, we can use this method.
|
||||
public static void SetScaleFrom(this Transform target, Vector3 worldPivot, Vector3 newScale)
|
||||
{
|
||||
Vector3 localOffset = target.InverseTransformPoint(worldPivot);
|
||||
|
||||
Vector3 localScale = target.localScale;
|
||||
Vector3 scaleRatio = new Vector3(ExtMathf.SafeDivide(newScale.x, localScale.x), ExtMathf.SafeDivide(newScale.y, localScale.y), ExtMathf.SafeDivide(newScale.z, localScale.z));
|
||||
Vector3 scaledLocalOffset = Vector3.Scale(localOffset, scaleRatio);
|
||||
|
||||
Vector3 newPosition = target.TransformPoint(localOffset - scaledLocalOffset);
|
||||
|
||||
target.localScale = newScale;
|
||||
target.position = newPosition;
|
||||
}
|
||||
|
||||
//This acts as if you are scaling based on a point that is offset from the actual pivot.
|
||||
//It gives results similar to when you scale an object in the unity editor when in Center mode instead of Pivot mode.
|
||||
//The Center was an offset from the actual Pivot.
|
||||
public static void SetScaleFromOffset(this Transform target, Vector3 worldPivot, Vector3 newScale)
|
||||
{
|
||||
//Seemed to work, except when under a parent that has a non uniform scale and rotation it was a bit off.
|
||||
//This might be due to transform.lossyScale not being accurate under those conditions, or possibly something else is wrong...
|
||||
//Maybe things can work if we can find a way to convert the "newPosition = ..." line to use Matrix4x4 for possibly more scale accuracy.
|
||||
//However, I have tried and tried and have no idea how to do that kind of math =/
|
||||
//Seems like unity editor also has some inaccuracies with skewed scales, such as scaling little by little compared to scaling one large scale.
|
||||
//
|
||||
//Will mess up or give undesired results if the target.localScale or target.lossyScale has any set to 0.
|
||||
//Unity editor doesnt even allow you to scale an axis when it is set to 0.
|
||||
|
||||
Vector3 localOffset = target.InverseTransformPoint(worldPivot);
|
||||
|
||||
Vector3 localScale = target.localScale;
|
||||
Vector3 scaleRatio = new Vector3(ExtMathf.SafeDivide(newScale.x, localScale.x), ExtMathf.SafeDivide(newScale.y, localScale.y), ExtMathf.SafeDivide(newScale.z, localScale.z));
|
||||
Vector3 scaledLocalOffset = Vector3.Scale(localOffset, scaleRatio);
|
||||
|
||||
Vector3 newPosition = target.rotation * Vector3.Scale(localOffset - scaledLocalOffset, target.lossyScale) + target.position;
|
||||
|
||||
target.localScale = newScale;
|
||||
target.position = newPosition;
|
||||
}
|
||||
|
||||
public static Vector3 GetCenter(this Transform transform, CenterType centerType)
|
||||
{
|
||||
if(centerType == CenterType.Solo)
|
||||
{
|
||||
Renderer renderer = transform.GetComponent<Renderer>();
|
||||
if(renderer != null)
|
||||
{
|
||||
return renderer.bounds.center;
|
||||
}else{
|
||||
return transform.position;
|
||||
}
|
||||
}
|
||||
else if(centerType == CenterType.All)
|
||||
{
|
||||
Bounds totalBounds = new Bounds(transform.position, Vector3.zero);
|
||||
GetCenterAll(transform, ref totalBounds);
|
||||
return totalBounds.center;
|
||||
}
|
||||
|
||||
return transform.position;
|
||||
}
|
||||
static void GetCenterAll(this Transform transform, ref Bounds currentTotalBounds)
|
||||
{
|
||||
Renderer renderer = transform.GetComponent<Renderer>();
|
||||
if(renderer != null)
|
||||
{
|
||||
currentTotalBounds.Encapsulate(renderer.bounds);
|
||||
}else{
|
||||
currentTotalBounds.Encapsulate(transform.position);
|
||||
}
|
||||
|
||||
for(int i = 0; i < transform.childCount; i++)
|
||||
{
|
||||
transform.GetChild(i).GetCenterAll(ref currentTotalBounds);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/RuntimeGizmo/Helpers/ExtTransform.cs.meta
Normal file
11
Assets/Scripts/RuntimeGizmo/Helpers/ExtTransform.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 62ed5fee79d72a640af40a5879f0c91c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
22
Assets/Scripts/RuntimeGizmo/Helpers/ExtTransformType.cs
Normal file
22
Assets/Scripts/RuntimeGizmo/Helpers/ExtTransformType.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
using System;
|
||||
|
||||
namespace RuntimeGizmos
|
||||
{
|
||||
public static class ExtTransformType
|
||||
{
|
||||
public static bool TransformTypeContains(this TransformType mainType, TransformType type, TransformSpace space)
|
||||
{
|
||||
if(type == mainType) return true;
|
||||
|
||||
if(mainType == TransformType.All)
|
||||
{
|
||||
if(type == TransformType.Move) return true;
|
||||
else if(type == TransformType.Rotate) return true;
|
||||
//else if(type == TransformType.RectTool) return false;
|
||||
else if(type == TransformType.Scale && space == TransformSpace.Local) return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/RuntimeGizmo/Helpers/ExtTransformType.cs.meta
Normal file
11
Assets/Scripts/RuntimeGizmo/Helpers/ExtTransformType.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a5054101d6691f145ac338d9dc668c31
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
29
Assets/Scripts/RuntimeGizmo/Helpers/ExtVector3.cs
Normal file
29
Assets/Scripts/RuntimeGizmo/Helpers/ExtVector3.cs
Normal file
@@ -0,0 +1,29 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace RuntimeGizmos
|
||||
{
|
||||
public static class ExtVector3
|
||||
{
|
||||
public static float MagnitudeInDirection(Vector3 vector, Vector3 direction, bool normalizeParameters = true)
|
||||
{
|
||||
if(normalizeParameters) direction.Normalize();
|
||||
return Vector3.Dot(vector, direction);
|
||||
}
|
||||
|
||||
public static Vector3 Abs(this Vector3 vector)
|
||||
{
|
||||
return new Vector3(Mathf.Abs(vector.x), Mathf.Abs(vector.y), Mathf.Abs(vector.z));
|
||||
}
|
||||
|
||||
public static bool IsParallel(Vector3 direction, Vector3 otherDirection, float precision = .0001f)
|
||||
{
|
||||
return Vector3.Cross(direction, otherDirection).sqrMagnitude < precision;
|
||||
}
|
||||
|
||||
public static bool IsInDirection(Vector3 direction, Vector3 otherDirection)
|
||||
{
|
||||
return Vector3.Dot(direction, otherDirection) > 0f;
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/RuntimeGizmo/Helpers/ExtVector3.cs.meta
Normal file
11
Assets/Scripts/RuntimeGizmo/Helpers/ExtVector3.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6cb5edf746639e54cbe3f25314bc67ec
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
101
Assets/Scripts/RuntimeGizmo/Helpers/Geometry.cs
Normal file
101
Assets/Scripts/RuntimeGizmo/Helpers/Geometry.cs
Normal file
@@ -0,0 +1,101 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace RuntimeGizmos
|
||||
{
|
||||
public static class Geometry
|
||||
{
|
||||
public static float LinePlaneDistance(Vector3 linePoint, Vector3 lineVec, Vector3 planePoint, Vector3 planeNormal)
|
||||
{
|
||||
//calculate the distance between the linePoint and the line-plane intersection point
|
||||
float dotNumerator = Vector3.Dot((planePoint - linePoint), planeNormal);
|
||||
float dotDenominator = Vector3.Dot(lineVec, planeNormal);
|
||||
|
||||
//line and plane are not parallel
|
||||
if(dotDenominator != 0f)
|
||||
{
|
||||
return dotNumerator / dotDenominator;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
//Note that the line is infinite, this is not a line-segment plane intersect
|
||||
public static Vector3 LinePlaneIntersect(Vector3 linePoint, Vector3 lineVec, Vector3 planePoint, Vector3 planeNormal)
|
||||
{
|
||||
float distance = LinePlaneDistance(linePoint, lineVec, planePoint, planeNormal);
|
||||
|
||||
//line and plane are not parallel
|
||||
if(distance != 0f)
|
||||
{
|
||||
return linePoint + (lineVec * distance);
|
||||
}
|
||||
|
||||
return Vector3.zero;
|
||||
}
|
||||
|
||||
//Returns 2 points since on line 1 there will be a closest point to line 2, and on line 2 there will be a closest point to line 1.
|
||||
public static IntersectPoints ClosestPointsOnTwoLines(Vector3 point1, Vector3 point1Direction, Vector3 point2, Vector3 point2Direction)
|
||||
{
|
||||
IntersectPoints intersections = new IntersectPoints();
|
||||
|
||||
//I dont think we need to normalize
|
||||
//point1Direction.Normalize();
|
||||
//point2Direction.Normalize();
|
||||
|
||||
float a = Vector3.Dot(point1Direction, point1Direction);
|
||||
float b = Vector3.Dot(point1Direction, point2Direction);
|
||||
float e = Vector3.Dot(point2Direction, point2Direction);
|
||||
|
||||
float d = a*e - b*b;
|
||||
|
||||
//This is a check if parallel, howeverm since we are not normalizing the directions, it seems even if they are parallel they will not == 0
|
||||
//so they will get past this point, but its seems to be alright since it seems to still give a correct point (although a point very fary away).
|
||||
//Also, if they are parallel and we dont normalize, the deciding point seems randomly choses on the lines, which while is still correct,
|
||||
//our ClosestPointsOnTwoLineSegments gets undesireable results when on corners. (for example when using it in our ClosestPointOnTriangleToLine).
|
||||
if(d != 0f)
|
||||
{
|
||||
Vector3 r = point1 - point2;
|
||||
float c = Vector3.Dot(point1Direction, r);
|
||||
float f = Vector3.Dot(point2Direction, r);
|
||||
|
||||
float s = (b*f - c*e) / d;
|
||||
float t = (a*f - c*b) / d;
|
||||
|
||||
intersections.first = point1 + point1Direction * s;
|
||||
intersections.second = point2 + point2Direction * t;
|
||||
}else{
|
||||
//Lines are parallel, select any points next to eachother
|
||||
intersections.first = point1;
|
||||
intersections.second = point2 + Vector3.Project(point1 - point2, point2Direction);
|
||||
}
|
||||
|
||||
return intersections;
|
||||
}
|
||||
|
||||
public static IntersectPoints ClosestPointsOnSegmentToLine(Vector3 segment0, Vector3 segment1, Vector3 linePoint, Vector3 lineDirection)
|
||||
{
|
||||
IntersectPoints closests = ClosestPointsOnTwoLines(segment0, segment1 - segment0, linePoint, lineDirection);
|
||||
closests.first = ClampToSegment(closests.first, segment0, segment1);
|
||||
|
||||
return closests;
|
||||
}
|
||||
|
||||
//Assumes the point is already on the line somewhere
|
||||
public static Vector3 ClampToSegment(Vector3 point, Vector3 linePoint1, Vector3 linePoint2)
|
||||
{
|
||||
Vector3 lineDirection = linePoint2 - linePoint1;
|
||||
|
||||
if(!ExtVector3.IsInDirection(point - linePoint1, lineDirection))
|
||||
{
|
||||
point = linePoint1;
|
||||
}
|
||||
else if(ExtVector3.IsInDirection(point - linePoint2, lineDirection))
|
||||
{
|
||||
point = linePoint2;
|
||||
}
|
||||
|
||||
return point;
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/RuntimeGizmo/Helpers/Geometry.cs.meta
Normal file
11
Assets/Scripts/RuntimeGizmo/Helpers/Geometry.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 38a05d582bac6ac4da31d8a6b6311d64
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
Assets/Scripts/RuntimeGizmo/Interfaces.meta
Normal file
8
Assets/Scripts/RuntimeGizmo/Interfaces.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: febd3820c7e024e48bceb14319a591cc
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
10
Assets/Scripts/RuntimeGizmo/Interfaces/ICommand.cs
Normal file
10
Assets/Scripts/RuntimeGizmo/Interfaces/ICommand.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
using System;
|
||||
|
||||
namespace CommandUndoRedo
|
||||
{
|
||||
public interface ICommand
|
||||
{
|
||||
void Execute();
|
||||
void UnExecute();
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/RuntimeGizmo/Interfaces/ICommand.cs.meta
Normal file
11
Assets/Scripts/RuntimeGizmo/Interfaces/ICommand.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7b1e2b794a40c4a47908d24695ed1449
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"name": "RuntimeGizmoShared"
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: aee7fa92e14bf364ebccdd24623e1764
|
||||
AssemblyDefinitionImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
6
Assets/Scripts/RuntimeGizmo/Interfaces/UndoData.cs
Normal file
6
Assets/Scripts/RuntimeGizmo/Interfaces/UndoData.cs
Normal file
@@ -0,0 +1,6 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class UndoData
|
||||
{
|
||||
public UndoData() { }
|
||||
}
|
||||
11
Assets/Scripts/RuntimeGizmo/Interfaces/UndoData.cs.meta
Normal file
11
Assets/Scripts/RuntimeGizmo/Interfaces/UndoData.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b61b9aa1e67a46c469f2b3d1982dd09d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
21
Assets/Scripts/RuntimeGizmo/LICENSE
Normal file
21
Assets/Scripts/RuntimeGizmo/LICENSE
Normal file
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2016 HiddenMonk
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
7
Assets/Scripts/RuntimeGizmo/LICENSE.meta
Normal file
7
Assets/Scripts/RuntimeGizmo/LICENSE.meta
Normal file
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d0c3b92d5b2dc534b941587e5bed2af7
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
Assets/Scripts/RuntimeGizmo/Objects.meta
Normal file
8
Assets/Scripts/RuntimeGizmo/Objects.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 290855abb9ae5da408c7a022e2083954
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
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:
|
||||
19
Assets/Scripts/RuntimeGizmo/RuntimeGizmo.asmdef
Normal file
19
Assets/Scripts/RuntimeGizmo/RuntimeGizmo.asmdef
Normal file
@@ -0,0 +1,19 @@
|
||||
{
|
||||
"name": "RuntimeGizmo",
|
||||
"rootNamespace": "",
|
||||
"references": [
|
||||
"GUID:1f135e4ce2898524aa1e81c5cd7f1242",
|
||||
"GUID:aee7fa92e14bf364ebccdd24623e1764",
|
||||
"GUID:ee695b84b4c90104b9367eebc6b0d70d",
|
||||
"GUID:24ad1c085c49dc34dbe16c3d92c6f299"
|
||||
],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": [],
|
||||
"versionDefines": [],
|
||||
"noEngineReferences": false
|
||||
}
|
||||
7
Assets/Scripts/RuntimeGizmo/RuntimeGizmo.asmdef.meta
Normal file
7
Assets/Scripts/RuntimeGizmo/RuntimeGizmo.asmdef.meta
Normal file
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5a35f47be2e63a54eb99351d22833673
|
||||
AssemblyDefinitionImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
Assets/Scripts/RuntimeGizmo/Shader.meta
Normal file
8
Assets/Scripts/RuntimeGizmo/Shader.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 87db21c0f3c83aa48bbb901ce39c6d7a
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
Assets/Scripts/RuntimeGizmo/Shader/Resources.meta
Normal file
8
Assets/Scripts/RuntimeGizmo/Shader/Resources.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 56308c649022e5e4c98212e0685bf28d
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
20
Assets/Scripts/RuntimeGizmo/Shader/Resources/Lines.shader
Normal file
20
Assets/Scripts/RuntimeGizmo/Shader/Resources/Lines.shader
Normal file
@@ -0,0 +1,20 @@
|
||||
Shader "Custom/Lines"
|
||||
{
|
||||
SubShader
|
||||
{
|
||||
Pass
|
||||
{
|
||||
Blend SrcAlpha OneMinusSrcAlpha
|
||||
ZWrite Off
|
||||
ZTest Always
|
||||
Cull Off
|
||||
Fog { Mode Off }
|
||||
|
||||
BindChannels
|
||||
{
|
||||
Bind "vertex", vertex
|
||||
Bind "color", color
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6a31e6e67bc4dc748a0e31657ba5c58e
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
preprocessorOverride: 0
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
57
Assets/Scripts/RuntimeGizmo/Shader/Resources/Outline.shader
Normal file
57
Assets/Scripts/RuntimeGizmo/Shader/Resources/Outline.shader
Normal file
@@ -0,0 +1,57 @@
|
||||
//Taken and modified from github.com/Shrimpey/Outlined-Diffuse-Shader-Fixed/blob/master/CustomOutline.shader
|
||||
|
||||
Shader "Custom/Outline" {
|
||||
Properties {
|
||||
_OutlineColor ("Outline Color", Color) = (1,.5,0,1)
|
||||
_Outline ("Outline width", Range (0, 1)) = .1
|
||||
}
|
||||
|
||||
CGINCLUDE
|
||||
#include "UnityCG.cginc"
|
||||
|
||||
struct appdata {
|
||||
float4 vertex : POSITION;
|
||||
float3 normal : NORMAL;
|
||||
};
|
||||
|
||||
struct v2f {
|
||||
float4 pos : POSITION;
|
||||
float4 color : COLOR;
|
||||
};
|
||||
|
||||
uniform float _Outline;
|
||||
uniform float4 _OutlineColor;
|
||||
|
||||
v2f vert(appdata v) {
|
||||
// just make a copy of incoming vertex data but scaled according to normal direction
|
||||
v2f o;
|
||||
|
||||
v.vertex *= ( 1 + _Outline);
|
||||
|
||||
o.pos = UnityObjectToClipPos(v.vertex);
|
||||
|
||||
o.color = _OutlineColor;
|
||||
return o;
|
||||
}
|
||||
ENDCG
|
||||
|
||||
SubShader {
|
||||
Tags { "DisableBatching" = "True" }
|
||||
Pass {
|
||||
Name "OUTLINE"
|
||||
Tags {"LightMode" = "UniversalForward" }
|
||||
Cull Front
|
||||
ZWrite On
|
||||
ColorMask RGB
|
||||
Blend SrcAlpha OneMinusSrcAlpha
|
||||
|
||||
CGPROGRAM
|
||||
#pragma vertex vert
|
||||
#pragma fragment frag
|
||||
half4 frag(v2f i) :COLOR { return i.color; }
|
||||
ENDCG
|
||||
}
|
||||
}
|
||||
|
||||
Fallback "Diffuse"
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7d6bfa5d6b2b72a4eb8c7cfb922661de
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
preprocessorOverride: 0
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
1503
Assets/Scripts/RuntimeGizmo/TransformGizmo.cs
Normal file
1503
Assets/Scripts/RuntimeGizmo/TransformGizmo.cs
Normal file
File diff suppressed because it is too large
Load Diff
11
Assets/Scripts/RuntimeGizmo/TransformGizmo.cs.meta
Normal file
11
Assets/Scripts/RuntimeGizmo/TransformGizmo.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1c0ad0e8e55c95c4e931911c4b943a64
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 5
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
15
Assets/Scripts/RuntimeGizmo/TransformGizmoHotkeys.cs
Normal file
15
Assets/Scripts/RuntimeGizmo/TransformGizmoHotkeys.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
using CommandUndoRedo;
|
||||
using UnityEngine;
|
||||
|
||||
public class TransformGizmoHotkeys : MonoBehaviour
|
||||
{
|
||||
public void Undo()
|
||||
{
|
||||
UndoRedoManager.Undo();
|
||||
}
|
||||
|
||||
public void Redo()
|
||||
{
|
||||
UndoRedoManager.Redo();
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/RuntimeGizmo/TransformGizmoHotkeys.cs.meta
Normal file
11
Assets/Scripts/RuntimeGizmo/TransformGizmoHotkeys.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c9a2023f1ce29ab4dad6a65ea603cdd0
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
Assets/Scripts/RuntimeGizmo/UndoRedo.meta
Normal file
8
Assets/Scripts/RuntimeGizmo/UndoRedo.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 61a3413ca6047f047beea5b609690d37
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
55
Assets/Scripts/RuntimeGizmo/UndoRedo/CommandGroup.cs
Normal file
55
Assets/Scripts/RuntimeGizmo/UndoRedo/CommandGroup.cs
Normal file
@@ -0,0 +1,55 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Debug = UnityEngine.Debug;
|
||||
|
||||
namespace CommandUndoRedo
|
||||
{
|
||||
public class CommandGroup : ICommand
|
||||
{
|
||||
List<ICommand> commands = new List<ICommand>();
|
||||
|
||||
public CommandGroup() {}
|
||||
public CommandGroup(List<ICommand> commands)
|
||||
{
|
||||
this.commands.AddRange(commands);
|
||||
}
|
||||
|
||||
public void Set(List<ICommand> commands)
|
||||
{
|
||||
this.commands = commands;
|
||||
}
|
||||
|
||||
public void Add(ICommand command)
|
||||
{
|
||||
commands.Add(command);
|
||||
}
|
||||
|
||||
public void Remove(ICommand command)
|
||||
{
|
||||
commands.Remove(command);
|
||||
}
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
commands.Clear();
|
||||
}
|
||||
|
||||
public void Execute()
|
||||
{
|
||||
for(int i = 0; i < commands.Count; i++)
|
||||
{
|
||||
Debug.Log("Executing " + commands[i].GetType().Name);
|
||||
commands[i].Execute();
|
||||
}
|
||||
}
|
||||
|
||||
public void UnExecute()
|
||||
{
|
||||
for(int i = commands.Count - 1; i >= 0; i--)
|
||||
{
|
||||
Debug.Log("Executing " + commands[i].GetType().Name);
|
||||
commands[i].UnExecute();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/RuntimeGizmo/UndoRedo/CommandGroup.cs.meta
Normal file
11
Assets/Scripts/RuntimeGizmo/UndoRedo/CommandGroup.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: da819dbd08b38eb45a35dbdb0fe78711
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
51
Assets/Scripts/RuntimeGizmo/UndoRedo/DropoutStack.cs
Normal file
51
Assets/Scripts/RuntimeGizmo/UndoRedo/DropoutStack.cs
Normal file
@@ -0,0 +1,51 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace CommandUndoRedo
|
||||
{
|
||||
public class DropoutStack<T> : LinkedList<T>
|
||||
{
|
||||
int _maxLength = int.MaxValue;
|
||||
public int maxLength {get {return _maxLength;} set {SetMaxLength(value);}}
|
||||
|
||||
public DropoutStack() {}
|
||||
public DropoutStack(int maxLength)
|
||||
{
|
||||
this.maxLength = maxLength;
|
||||
}
|
||||
|
||||
public void Push(T item)
|
||||
{
|
||||
if(this.Count > 0 && this.Count + 1 > maxLength)
|
||||
{
|
||||
this.RemoveLast();
|
||||
}
|
||||
|
||||
if(this.Count + 1 <= maxLength)
|
||||
{
|
||||
this.AddFirst(item);
|
||||
}
|
||||
}
|
||||
|
||||
public T Pop()
|
||||
{
|
||||
T item = this.First.Value;
|
||||
this.RemoveFirst();
|
||||
return item;
|
||||
}
|
||||
|
||||
void SetMaxLength(int max)
|
||||
{
|
||||
_maxLength = max;
|
||||
|
||||
if(this.Count > _maxLength)
|
||||
{
|
||||
int leftover = this.Count - _maxLength;
|
||||
for(int i = 0; i < leftover; i++)
|
||||
{
|
||||
this.RemoveLast();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/RuntimeGizmo/UndoRedo/DropoutStack.cs.meta
Normal file
11
Assets/Scripts/RuntimeGizmo/UndoRedo/DropoutStack.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c376afccd664f4e42b36d3a99300037d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
16
Assets/Scripts/RuntimeGizmo/UndoRedo/UndoManager.asmdef
Normal file
16
Assets/Scripts/RuntimeGizmo/UndoRedo/UndoManager.asmdef
Normal file
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"name": "UndoManager",
|
||||
"rootNamespace": "",
|
||||
"references": [
|
||||
"GUID:aee7fa92e14bf364ebccdd24623e1764"
|
||||
],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": [],
|
||||
"versionDefines": [],
|
||||
"noEngineReferences": false
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ee695b84b4c90104b9367eebc6b0d70d
|
||||
AssemblyDefinitionImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
65
Assets/Scripts/RuntimeGizmo/UndoRedo/UndoRedo.cs
Normal file
65
Assets/Scripts/RuntimeGizmo/UndoRedo/UndoRedo.cs
Normal file
@@ -0,0 +1,65 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace CommandUndoRedo
|
||||
{
|
||||
public class UndoRedo
|
||||
{
|
||||
public int maxUndoStored {get {return undoCommands.maxLength;} set {SetMaxLength(value);}}
|
||||
|
||||
DropoutStack<ICommand> undoCommands = new DropoutStack<ICommand>();
|
||||
DropoutStack<ICommand> redoCommands = new DropoutStack<ICommand>();
|
||||
|
||||
public UndoRedo() {}
|
||||
public UndoRedo(int maxUndoStored)
|
||||
{
|
||||
this.maxUndoStored = maxUndoStored;
|
||||
}
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
undoCommands.Clear();
|
||||
redoCommands.Clear();
|
||||
}
|
||||
|
||||
public void Undo()
|
||||
{
|
||||
if(undoCommands.Count > 0)
|
||||
{
|
||||
ICommand command = undoCommands.Pop();
|
||||
command.UnExecute();
|
||||
redoCommands.Push(command);
|
||||
}
|
||||
}
|
||||
|
||||
public void Redo()
|
||||
{
|
||||
if(redoCommands.Count > 0)
|
||||
{
|
||||
ICommand command = redoCommands.Pop();
|
||||
command.Execute();
|
||||
undoCommands.Push(command);
|
||||
}
|
||||
}
|
||||
|
||||
public void Insert(ICommand command)
|
||||
{
|
||||
if(maxUndoStored <= 0) return;
|
||||
|
||||
undoCommands.Push(command);
|
||||
redoCommands.Clear();
|
||||
}
|
||||
|
||||
public void Execute(ICommand command)
|
||||
{
|
||||
command.Execute();
|
||||
Insert(command);
|
||||
}
|
||||
|
||||
void SetMaxLength(int max)
|
||||
{
|
||||
undoCommands.maxLength = max;
|
||||
redoCommands.maxLength = max;
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/RuntimeGizmo/UndoRedo/UndoRedo.cs.meta
Normal file
11
Assets/Scripts/RuntimeGizmo/UndoRedo/UndoRedo.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4ed1af1a5fc734b49894376597a9c723
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
36
Assets/Scripts/RuntimeGizmo/UndoRedo/UndoRedoManager.cs
Normal file
36
Assets/Scripts/RuntimeGizmo/UndoRedo/UndoRedoManager.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
using System;
|
||||
|
||||
namespace CommandUndoRedo
|
||||
{
|
||||
public static class UndoRedoManager
|
||||
{
|
||||
static UndoRedo undoRedo = new UndoRedo();
|
||||
|
||||
public static int maxUndoStored {get {return undoRedo.maxUndoStored;} set {undoRedo.maxUndoStored = value;}}
|
||||
|
||||
public static void Clear()
|
||||
{
|
||||
undoRedo.Clear();
|
||||
}
|
||||
|
||||
public static void Undo()
|
||||
{
|
||||
undoRedo.Undo();
|
||||
}
|
||||
|
||||
public static void Redo()
|
||||
{
|
||||
undoRedo.Redo();
|
||||
}
|
||||
|
||||
public static void Insert(ICommand command)
|
||||
{
|
||||
undoRedo.Insert(command);
|
||||
}
|
||||
|
||||
public static void Execute(ICommand command)
|
||||
{
|
||||
undoRedo.Execute(command);
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/RuntimeGizmo/UndoRedo/UndoRedoManager.cs.meta
Normal file
11
Assets/Scripts/RuntimeGizmo/UndoRedo/UndoRedoManager.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ace2ece517a3a1c4f898c0fc635a5dd9
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user