runtime transform gizmo 추가
This commit is contained in:
8
Assets/Runtime Transform Gizmos.meta
Normal file
8
Assets/Runtime Transform Gizmos.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 75ab24b49b0b14e40bff6a685bd934fa
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
9
Assets/Runtime Transform Gizmos/Demo Scenes.meta
Normal file
9
Assets/Runtime Transform Gizmos/Demo Scenes.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 81fdbd98237ec204f83a26cdd4da6ecc
|
||||
folderAsset: yes
|
||||
timeCreated: 1526645153
|
||||
licenseType: Store
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
109
Assets/Runtime Transform Gizmos/Demo Scenes/Blue.mat
Normal file
109
Assets/Runtime Transform Gizmos/Demo Scenes/Blue.mat
Normal file
@@ -0,0 +1,109 @@
|
||||
%YAML 1.1
|
||||
%TAG !u! tag:unity3d.com,2011:
|
||||
--- !u!114 &-8214510742461266717
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 11
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 0}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: d0353a89b1f911e48b9e16bdc9f2e058, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
version: 1
|
||||
--- !u!21 &2100000
|
||||
Material:
|
||||
serializedVersion: 6
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_Name: Blue
|
||||
m_Shader: {fileID: 46, guid: 0000000000000000f000000000000000, type: 0}
|
||||
m_ShaderKeywords:
|
||||
m_LightmapFlags: 4
|
||||
m_EnableInstancingVariants: 0
|
||||
m_DoubleSidedGI: 0
|
||||
m_CustomRenderQueue: -1
|
||||
stringTagMap: {}
|
||||
disabledShaderPasses: []
|
||||
m_SavedProperties:
|
||||
serializedVersion: 3
|
||||
m_TexEnvs:
|
||||
- _BaseMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _BumpMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _DetailAlbedoMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _DetailMask:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _DetailNormalMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _EmissionMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _MainTex:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _MetallicGlossMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _OcclusionMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _ParallaxMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _SpecGlossMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
m_Floats:
|
||||
- _AlphaClip: 0
|
||||
- _Blend: 0
|
||||
- _BumpScale: 1
|
||||
- _Cull: 2
|
||||
- _Cutoff: 0.5
|
||||
- _DetailNormalMapScale: 1
|
||||
- _DstBlend: 0
|
||||
- _EnvironmentReflections: 1
|
||||
- _GlossMapScale: 1
|
||||
- _Glossiness: 0.5
|
||||
- _GlossyReflections: 1
|
||||
- _Metallic: 0
|
||||
- _Mode: 0
|
||||
- _OcclusionStrength: 1
|
||||
- _Parallax: 0.02
|
||||
- _QueueOffset: 0
|
||||
- _ReceiveShadows: 1
|
||||
- _Smoothness: 0.5
|
||||
- _SmoothnessTextureChannel: 0
|
||||
- _SpecularHighlights: 1
|
||||
- _SrcBlend: 1
|
||||
- _Surface: 0
|
||||
- _UVSec: 0
|
||||
- _WorkflowMode: 1
|
||||
- _ZWrite: 1
|
||||
m_Colors:
|
||||
- _BaseColor: {r: 0.210532, g: 0.2150638, b: 0.86764705, a: 1}
|
||||
- _Color: {r: 0.210532, g: 0.2150638, b: 0.86764705, a: 1}
|
||||
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1}
|
||||
- _SpecColor: {r: 0.2, g: 0.2, b: 0.2, a: 1}
|
||||
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4b21980f2319365459f8d688b54b061f
|
||||
timeCreated: 1526645214
|
||||
licenseType: Store
|
||||
NativeFormatImporter:
|
||||
mainObjectFileID: 2100000
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
53
Assets/Runtime Transform Gizmos/Demo Scenes/Demo.cs
Normal file
53
Assets/Runtime Transform Gizmos/Demo Scenes/Demo.cs
Normal file
@@ -0,0 +1,53 @@
|
||||
using UnityEngine;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace RTG
|
||||
{
|
||||
public class Demo : MonoBehaviour
|
||||
{
|
||||
private void Start()
|
||||
{
|
||||
var moveTargetNames = new string[] { "Blue Cube", "Sphere" };
|
||||
foreach (var targetName in moveTargetNames)
|
||||
{
|
||||
var transformGizmo = RTGizmosEngine.Get.CreateObjectMoveGizmo();
|
||||
|
||||
GameObject targetObject = GameObject.Find(targetName);
|
||||
transformGizmo.SetTargetObject(targetObject);
|
||||
transformGizmo.Gizmo.MoveGizmo.SetVertexSnapTargetObjects(new List<GameObject> { targetObject });
|
||||
transformGizmo.SetTransformSpace(GizmoSpace.Local);
|
||||
}
|
||||
|
||||
var rotationTargetNames = new string[] { "Cylinder", "Red Cube" };
|
||||
foreach (var targetName in rotationTargetNames)
|
||||
{
|
||||
var transformGizmo = RTGizmosEngine.Get.CreateObjectRotationGizmo();
|
||||
|
||||
GameObject targetObject = GameObject.Find(targetName);
|
||||
transformGizmo.SetTargetObject(targetObject);
|
||||
transformGizmo.SetTransformSpace(GizmoSpace.Local);
|
||||
}
|
||||
|
||||
var scaleTargetNames = new string[] { "Cylinder (1)", "Sphere (1)" };
|
||||
foreach (var targetName in scaleTargetNames)
|
||||
{
|
||||
var transformGizmo = RTGizmosEngine.Get.CreateObjectScaleGizmo();
|
||||
|
||||
GameObject targetObject = GameObject.Find(targetName);
|
||||
transformGizmo.SetTargetObject(targetObject);
|
||||
transformGizmo.SetTransformSpace(GizmoSpace.Local);
|
||||
}
|
||||
|
||||
var universalTargetNames = new string[] { "Blue Cube (1)", "Green Cube" };
|
||||
foreach (var targetName in universalTargetNames)
|
||||
{
|
||||
var transformGizmo = RTGizmosEngine.Get.CreateObjectUniversalGizmo();
|
||||
|
||||
GameObject targetObject = GameObject.Find(targetName);
|
||||
transformGizmo.SetTargetObject(targetObject);
|
||||
transformGizmo.Gizmo.UniversalGizmo.SetMvVertexSnapTargetObjects(new List<GameObject> { targetObject });
|
||||
transformGizmo.SetTransformSpace(GizmoSpace.Local);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
12
Assets/Runtime Transform Gizmos/Demo Scenes/Demo.cs.meta
Normal file
12
Assets/Runtime Transform Gizmos/Demo Scenes/Demo.cs.meta
Normal file
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4087e6b8d8d7e2941b74e1050f1c6fae
|
||||
timeCreated: 1533908384
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
4935
Assets/Runtime Transform Gizmos/Demo Scenes/Demo.unity
Normal file
4935
Assets/Runtime Transform Gizmos/Demo Scenes/Demo.unity
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 98241052b2493964ab3adad75f144d97
|
||||
timeCreated: 1526645206
|
||||
licenseType: Store
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
109
Assets/Runtime Transform Gizmos/Demo Scenes/Green.mat
Normal file
109
Assets/Runtime Transform Gizmos/Demo Scenes/Green.mat
Normal file
@@ -0,0 +1,109 @@
|
||||
%YAML 1.1
|
||||
%TAG !u! tag:unity3d.com,2011:
|
||||
--- !u!114 &-7475917354030070031
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 11
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 0}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: d0353a89b1f911e48b9e16bdc9f2e058, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
version: 1
|
||||
--- !u!21 &2100000
|
||||
Material:
|
||||
serializedVersion: 6
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_Name: Green
|
||||
m_Shader: {fileID: 46, guid: 0000000000000000f000000000000000, type: 0}
|
||||
m_ShaderKeywords:
|
||||
m_LightmapFlags: 4
|
||||
m_EnableInstancingVariants: 0
|
||||
m_DoubleSidedGI: 0
|
||||
m_CustomRenderQueue: -1
|
||||
stringTagMap: {}
|
||||
disabledShaderPasses: []
|
||||
m_SavedProperties:
|
||||
serializedVersion: 3
|
||||
m_TexEnvs:
|
||||
- _BaseMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _BumpMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _DetailAlbedoMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _DetailMask:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _DetailNormalMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _EmissionMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _MainTex:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _MetallicGlossMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _OcclusionMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _ParallaxMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _SpecGlossMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
m_Floats:
|
||||
- _AlphaClip: 0
|
||||
- _Blend: 0
|
||||
- _BumpScale: 1
|
||||
- _Cull: 2
|
||||
- _Cutoff: 0.5
|
||||
- _DetailNormalMapScale: 1
|
||||
- _DstBlend: 0
|
||||
- _EnvironmentReflections: 1
|
||||
- _GlossMapScale: 1
|
||||
- _Glossiness: 0.5
|
||||
- _GlossyReflections: 1
|
||||
- _Metallic: 0
|
||||
- _Mode: 0
|
||||
- _OcclusionStrength: 1
|
||||
- _Parallax: 0.02
|
||||
- _QueueOffset: 0
|
||||
- _ReceiveShadows: 1
|
||||
- _Smoothness: 0.5
|
||||
- _SmoothnessTextureChannel: 0
|
||||
- _SpecularHighlights: 1
|
||||
- _SrcBlend: 1
|
||||
- _Surface: 0
|
||||
- _UVSec: 0
|
||||
- _WorkflowMode: 1
|
||||
- _ZWrite: 1
|
||||
m_Colors:
|
||||
- _BaseColor: {r: 0.15295199, g: 0.9044118, b: 0.28251404, a: 1}
|
||||
- _Color: {r: 0.15295199, g: 0.9044118, b: 0.28251404, a: 1}
|
||||
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1}
|
||||
- _SpecColor: {r: 0.2, g: 0.2, b: 0.2, a: 1}
|
||||
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9ca3bdc9866ca4c4489e3ec310d3b109
|
||||
timeCreated: 1526645214
|
||||
licenseType: Store
|
||||
NativeFormatImporter:
|
||||
mainObjectFileID: 2100000
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
109
Assets/Runtime Transform Gizmos/Demo Scenes/Red.mat
Normal file
109
Assets/Runtime Transform Gizmos/Demo Scenes/Red.mat
Normal file
@@ -0,0 +1,109 @@
|
||||
%YAML 1.1
|
||||
%TAG !u! tag:unity3d.com,2011:
|
||||
--- !u!21 &2100000
|
||||
Material:
|
||||
serializedVersion: 6
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_Name: Red
|
||||
m_Shader: {fileID: 46, guid: 0000000000000000f000000000000000, type: 0}
|
||||
m_ShaderKeywords:
|
||||
m_LightmapFlags: 4
|
||||
m_EnableInstancingVariants: 0
|
||||
m_DoubleSidedGI: 0
|
||||
m_CustomRenderQueue: -1
|
||||
stringTagMap: {}
|
||||
disabledShaderPasses: []
|
||||
m_SavedProperties:
|
||||
serializedVersion: 3
|
||||
m_TexEnvs:
|
||||
- _BaseMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _BumpMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _DetailAlbedoMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _DetailMask:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _DetailNormalMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _EmissionMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _MainTex:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _MetallicGlossMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _OcclusionMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _ParallaxMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _SpecGlossMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
m_Floats:
|
||||
- _AlphaClip: 0
|
||||
- _Blend: 0
|
||||
- _BumpScale: 1
|
||||
- _Cull: 2
|
||||
- _Cutoff: 0.5
|
||||
- _DetailNormalMapScale: 1
|
||||
- _DstBlend: 0
|
||||
- _EnvironmentReflections: 1
|
||||
- _GlossMapScale: 1
|
||||
- _Glossiness: 0.5
|
||||
- _GlossyReflections: 1
|
||||
- _Metallic: 0
|
||||
- _Mode: 0
|
||||
- _OcclusionStrength: 1
|
||||
- _Parallax: 0.02
|
||||
- _QueueOffset: 0
|
||||
- _ReceiveShadows: 1
|
||||
- _Smoothness: 0.5
|
||||
- _SmoothnessTextureChannel: 0
|
||||
- _SpecularHighlights: 1
|
||||
- _SrcBlend: 1
|
||||
- _Surface: 0
|
||||
- _UVSec: 0
|
||||
- _WorkflowMode: 1
|
||||
- _ZWrite: 1
|
||||
m_Colors:
|
||||
- _BaseColor: {r: 0.9852941, g: 0.15214103, b: 0.15214103, a: 1}
|
||||
- _Color: {r: 0.9852941, g: 0.15214103, b: 0.15214103, a: 1}
|
||||
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1}
|
||||
- _SpecColor: {r: 0.2, g: 0.2, b: 0.2, a: 1}
|
||||
--- !u!114 &7996450688058991107
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 11
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 0}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: d0353a89b1f911e48b9e16bdc9f2e058, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
version: 1
|
||||
9
Assets/Runtime Transform Gizmos/Demo Scenes/Red.mat.meta
Normal file
9
Assets/Runtime Transform Gizmos/Demo Scenes/Red.mat.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5135d2a67ae7f3e458b3109d5fbd5f04
|
||||
timeCreated: 1526645214
|
||||
licenseType: Store
|
||||
NativeFormatImporter:
|
||||
mainObjectFileID: 2100000
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
109
Assets/Runtime Transform Gizmos/Demo Scenes/White.mat
Normal file
109
Assets/Runtime Transform Gizmos/Demo Scenes/White.mat
Normal file
@@ -0,0 +1,109 @@
|
||||
%YAML 1.1
|
||||
%TAG !u! tag:unity3d.com,2011:
|
||||
--- !u!21 &2100000
|
||||
Material:
|
||||
serializedVersion: 6
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_Name: White
|
||||
m_Shader: {fileID: 46, guid: 0000000000000000f000000000000000, type: 0}
|
||||
m_ShaderKeywords: _GLOSSYREFLECTIONS_OFF
|
||||
m_LightmapFlags: 4
|
||||
m_EnableInstancingVariants: 0
|
||||
m_DoubleSidedGI: 0
|
||||
m_CustomRenderQueue: -1
|
||||
stringTagMap: {}
|
||||
disabledShaderPasses: []
|
||||
m_SavedProperties:
|
||||
serializedVersion: 3
|
||||
m_TexEnvs:
|
||||
- _BaseMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _BumpMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _DetailAlbedoMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _DetailMask:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _DetailNormalMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _EmissionMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _MainTex:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _MetallicGlossMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _OcclusionMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _ParallaxMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _SpecGlossMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
m_Floats:
|
||||
- _AlphaClip: 0
|
||||
- _Blend: 0
|
||||
- _BumpScale: 1
|
||||
- _Cull: 2
|
||||
- _Cutoff: 0.5
|
||||
- _DetailNormalMapScale: 1
|
||||
- _DstBlend: 0
|
||||
- _EnvironmentReflections: 1
|
||||
- _GlossMapScale: 0
|
||||
- _Glossiness: 0
|
||||
- _GlossyReflections: 0
|
||||
- _Metallic: 0
|
||||
- _Mode: 0
|
||||
- _OcclusionStrength: 1
|
||||
- _Parallax: 0.02
|
||||
- _QueueOffset: 0
|
||||
- _ReceiveShadows: 1
|
||||
- _Smoothness: 0.5
|
||||
- _SmoothnessTextureChannel: 0
|
||||
- _SpecularHighlights: 1
|
||||
- _SrcBlend: 1
|
||||
- _Surface: 0
|
||||
- _UVSec: 0
|
||||
- _WorkflowMode: 1
|
||||
- _ZWrite: 1
|
||||
m_Colors:
|
||||
- _BaseColor: {r: 1, g: 1, b: 1, a: 1}
|
||||
- _Color: {r: 1, g: 1, b: 1, a: 1}
|
||||
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1}
|
||||
- _SpecColor: {r: 0.2, g: 0.2, b: 0.2, a: 1}
|
||||
--- !u!114 &7098383115011353574
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 11
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 0}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: d0353a89b1f911e48b9e16bdc9f2e058, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
version: 1
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0733e2b16ba3e7047af0397a9878e181
|
||||
NativeFormatImporter:
|
||||
externalObjects: {}
|
||||
mainObjectFileID: 0
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
109
Assets/Runtime Transform Gizmos/Demo Scenes/Yellow.mat
Normal file
109
Assets/Runtime Transform Gizmos/Demo Scenes/Yellow.mat
Normal file
@@ -0,0 +1,109 @@
|
||||
%YAML 1.1
|
||||
%TAG !u! tag:unity3d.com,2011:
|
||||
--- !u!114 &-2242521812297890073
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 11
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 0}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: d0353a89b1f911e48b9e16bdc9f2e058, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
version: 1
|
||||
--- !u!21 &2100000
|
||||
Material:
|
||||
serializedVersion: 6
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_Name: Yellow
|
||||
m_Shader: {fileID: 46, guid: 0000000000000000f000000000000000, type: 0}
|
||||
m_ShaderKeywords:
|
||||
m_LightmapFlags: 4
|
||||
m_EnableInstancingVariants: 0
|
||||
m_DoubleSidedGI: 0
|
||||
m_CustomRenderQueue: -1
|
||||
stringTagMap: {}
|
||||
disabledShaderPasses: []
|
||||
m_SavedProperties:
|
||||
serializedVersion: 3
|
||||
m_TexEnvs:
|
||||
- _BaseMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _BumpMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _DetailAlbedoMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _DetailMask:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _DetailNormalMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _EmissionMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _MainTex:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _MetallicGlossMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _OcclusionMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _ParallaxMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _SpecGlossMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
m_Floats:
|
||||
- _AlphaClip: 0
|
||||
- _Blend: 0
|
||||
- _BumpScale: 1
|
||||
- _Cull: 2
|
||||
- _Cutoff: 0.5
|
||||
- _DetailNormalMapScale: 1
|
||||
- _DstBlend: 0
|
||||
- _EnvironmentReflections: 1
|
||||
- _GlossMapScale: 1
|
||||
- _Glossiness: 0.5
|
||||
- _GlossyReflections: 1
|
||||
- _Metallic: 0
|
||||
- _Mode: 0
|
||||
- _OcclusionStrength: 1
|
||||
- _Parallax: 0.02
|
||||
- _QueueOffset: 0
|
||||
- _ReceiveShadows: 1
|
||||
- _Smoothness: 0.5
|
||||
- _SmoothnessTextureChannel: 0
|
||||
- _SpecularHighlights: 1
|
||||
- _SrcBlend: 1
|
||||
- _Surface: 0
|
||||
- _UVSec: 0
|
||||
- _WorkflowMode: 1
|
||||
- _ZWrite: 1
|
||||
m_Colors:
|
||||
- _BaseColor: {r: 0.9852941, g: 0.8588847, b: 0.15214103, a: 1}
|
||||
- _Color: {r: 0.9852941, g: 0.8588847, b: 0.15214103, a: 1}
|
||||
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1}
|
||||
- _SpecColor: {r: 0.2, g: 0.2, b: 0.2, a: 1}
|
||||
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c1a2babdfb385db4a9ed6985e88d36cc
|
||||
timeCreated: 1526645214
|
||||
licenseType: Store
|
||||
NativeFormatImporter:
|
||||
mainObjectFileID: 2100000
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
9
Assets/Runtime Transform Gizmos/Docs.meta
Normal file
9
Assets/Runtime Transform Gizmos/Docs.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: eb820590f26fdfd4cbf8295abf88a44f
|
||||
folderAsset: yes
|
||||
timeCreated: 1497612599
|
||||
licenseType: Store
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
BIN
Assets/Runtime Transform Gizmos/Docs/RTG - Quick Start Guide.pdf
Normal file
BIN
Assets/Runtime Transform Gizmos/Docs/RTG - Quick Start Guide.pdf
Normal file
Binary file not shown.
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c175b88acd826e249a1c7f6defce5125
|
||||
timeCreated: 1536181671
|
||||
licenseType: Store
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
10
Assets/Runtime Transform Gizmos/Docs/Readme.txt
Normal file
10
Assets/Runtime Transform Gizmos/Docs/Readme.txt
Normal file
@@ -0,0 +1,10 @@
|
||||
Welcome to Runtime Transform Gizmos!
|
||||
------------------------------------------
|
||||
|
||||
Get started with:
|
||||
API Docs: https://rtg.readthedocs.io/en/latest/
|
||||
Video Tutorials: https://www.youtube.com/watch?v=5i2m550eFyg&list=PLPwpt1oIEdwAY_Qo6fczi6qTiUjCMZBW1
|
||||
|
||||
Tutorial files can be found in Assets/Runtime Transform Gizmos/Scripting Tutorials.
|
||||
|
||||
Enjoy!
|
||||
8
Assets/Runtime Transform Gizmos/Docs/Readme.txt.meta
Normal file
8
Assets/Runtime Transform Gizmos/Docs/Readme.txt.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bba9cdcaf6720bc40940d84e84f373ac
|
||||
timeCreated: 1485452727
|
||||
licenseType: Store
|
||||
TextScriptImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
105
Assets/Runtime Transform Gizmos/Docs/Version History.txt
Normal file
105
Assets/Runtime Transform Gizmos/Docs/Version History.txt
Normal file
@@ -0,0 +1,105 @@
|
||||
Release 1.3.3:
|
||||
---------------------------------------------
|
||||
[Bug Fix]: Fixed hover info updating while cursor lock state is locked;
|
||||
[Bug Fix]: Fixed new Input system bug;
|
||||
|
||||
Release 1.3.2:
|
||||
---------------------------------------------
|
||||
[Bug Fix]: Fixed incorrect value for total drag scale;
|
||||
|
||||
Release 1.3.1:
|
||||
---------------------------------------------
|
||||
[Bug Fix]: Fixed bug in GizmoDragSession;
|
||||
[Bug Fix]: Fixed bug which was causing scale gizmos to change the sibling index of
|
||||
the object being scaled;
|
||||
|
||||
Release 1.3:
|
||||
---------------------------------------------
|
||||
[New Feature] : implemented support for the new input system. This was done to solve
|
||||
certain issues that appear when using RDC.
|
||||
|
||||
Release 1.2.2:
|
||||
---------------------------------------------
|
||||
[New Feature] : implemented MeshVertexChunkCollectionDb.SetMeshDirty to allow vertex
|
||||
snapping to work correctly after a mesh is modified.
|
||||
|
||||
Release 1.2.1:
|
||||
---------------------------------------------
|
||||
[Improvement] : eliminated recursion from SphereTree;
|
||||
|
||||
[Bug Fix] : fixed SphereTree.IntegrateNodeRecurse stack overflow exception;
|
||||
|
||||
Release 1.2:
|
||||
---------------------------------------------
|
||||
[New Feature] : added support for URP - there is a limitation: the scene gizmo can not be used with URP;
|
||||
[New Feature] : added 'MinPositiveScale' and 'ScaleConstraintEnabled' properties to ObjectTransformGizmo;
|
||||
|
||||
[Improvement] : Optimized the RTScene::Update_SystemCall function. The client code is now required to call
|
||||
RTScene.Get.OnGameObjectWillBeDestroyed whenever it destroys a game object and RTMeshDb.Get.OnMeshWillBeDestroyed
|
||||
if it ever destroys a mesh asset at runtime.
|
||||
|
||||
[Removed] : removed unnecessary field from RTScene Inspector;
|
||||
|
||||
Release 1.1.4:
|
||||
---------------------------------------------
|
||||
[New Feature] : added 'RemoveGizmo' function to the RTGizmosEngine class
|
||||
to allow the client code to remove gizmos when they are
|
||||
no longer needed.
|
||||
|
||||
[Bug Fix] : fixed gizmo hover state not updated correctly when moving the mouse cursor
|
||||
from the gizmo over the UI;
|
||||
|
||||
Release 1.1.3:
|
||||
---------------------------------------------
|
||||
[Bug Fix] : fixed internal issues with 2D shape and sphere border rendering artifacts;
|
||||
|
||||
Release 1.1.2:
|
||||
---------------------------------------------
|
||||
[New Feature] : it is now possible to change the scene gizmo screen size.
|
||||
|
||||
Release 1.1.1:
|
||||
---------------------------------------------
|
||||
[Bug Fix] : fixed bug which was preventing gizmos from being dragged
|
||||
for certain camera angles.
|
||||
|
||||
Release 1.1:
|
||||
---------------------------------------------
|
||||
[New Feature] : added 'SetAxesLinesHoverable' function to the 'MoveGizmo' class;
|
||||
[New Feature] : added 'SetMidCapHoverable' function to the 'RotationGizmo' class;
|
||||
[New Feature] : added 'SetAxesLinesHoverable' function to the 'ScaleGizmo' class;
|
||||
[New Feature] : added 'SetMvAxesLinesHoverable' and 'SetRtMidCapHoverable' functions to the 'UniversalGizmo' class;
|
||||
|
||||
[Bug Fix] : fixed scale & universal gizmos scaling objects incorrectly;
|
||||
[Bug Fix] : fixed scale snap step Inspector freeze for scale & universal gizmos;
|
||||
[Bug Fix] : fixed mid scale cap for universal gizmo not hiding when switching to 2D mode;
|
||||
[Bug Fix] : fixed bug in the 'OnHoverableStateChanged' function of the 'GizmoPlaneSlider3D' class;
|
||||
|
||||
Release 1.0.5:
|
||||
---------------------------------------------
|
||||
[New Feature] : fixed incorrect mapping between Ids and gizmo handles (move, scale and universal);
|
||||
[New Feature] : added SetRootObjectIgnored to RTScene class;
|
||||
|
||||
[Bug Fix] : fixed camera focus;
|
||||
[Bug Fix] : fixed warnings about PrefabType being obsolete;
|
||||
[Bug Fix] : fixed SphereTreeNode stack overflow bug;
|
||||
|
||||
Release 1.0.4:
|
||||
---------------------------------------------
|
||||
[New Feature] : gizmo states such as enabling/disabling snapping can now correctly be activated/deactivated
|
||||
using the gizmo interface. Previously, this was not possible because these states would
|
||||
always be overwritten by the hotkeys;
|
||||
[New Feature] : added 'Initialized' event for the RTGApp class;
|
||||
[New Feature] : added 'OffsetDragAxisModify' event to the 'Gizmo' class which allows the client code to
|
||||
alter the drag axis produced while dragging gizmo offset/move handles;
|
||||
[New Feature] : it is now possible to control the visibility of the universal gizmo's mid cap. This
|
||||
is the shape (box by default) that is used to perform uniform scaling;
|
||||
|
||||
Release 1.0.2
|
||||
---------------------------------------------
|
||||
[New Feature] : it is now possible to choose the type of rotation switch performed by the camera;
|
||||
|
||||
Release 1.0.1
|
||||
---------------------------------------------
|
||||
[Bug Fix]: fixed bug which was causing buggy interaction with the gizmos for custom defined camera viewports;
|
||||
|
||||
Release 1.0
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5ca2999f96aec8244bdb303c16351bc7
|
||||
timeCreated: 1485452727
|
||||
licenseType: Store
|
||||
TextScriptImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
9
Assets/Runtime Transform Gizmos/Editor.meta
Normal file
9
Assets/Runtime Transform Gizmos/Editor.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d32caefd6672bb048a3e36e094cc9e9f
|
||||
folderAsset: yes
|
||||
timeCreated: 1485511940
|
||||
licenseType: Store
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
9
Assets/Runtime Transform Gizmos/Editor/Scripts.meta
Normal file
9
Assets/Runtime Transform Gizmos/Editor/Scripts.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: dcbf278cde1fbcb48a22ef0f0c40e723
|
||||
folderAsset: yes
|
||||
timeCreated: 1485511943
|
||||
licenseType: Store
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,105 @@
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
|
||||
namespace RTG
|
||||
{
|
||||
[CustomEditor(typeof(RTGizmosEngine))]
|
||||
public class RTGizmoEngineInspector : Editor
|
||||
{
|
||||
private const int _generalTab = 0;
|
||||
private const int _sceneGizmo = _generalTab + 1;
|
||||
private const int _moveGizmoTab = _sceneGizmo + 1;
|
||||
private const int _rotationGizmoTab = _moveGizmoTab + 1;
|
||||
private const int _scaleGizmoTab = _rotationGizmoTab + 1;
|
||||
private const int _universalGizmoTab = _scaleGizmoTab + 1;
|
||||
|
||||
private RTGizmosEngine _gizmoEngine;
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
EditorGUILayout.Separator();
|
||||
_gizmoEngine.MainToolbar.RenderEditorGUI(_gizmoEngine);
|
||||
}
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
_gizmoEngine = target as RTGizmosEngine;
|
||||
|
||||
_gizmoEngine.MainToolbar.GetTabByIndex(_generalTab).AddTargetSettings(_gizmoEngine.Settings);
|
||||
_gizmoEngine.MainToolbar.GetTabByIndex(_sceneGizmo).AddTargetSettings(_gizmoEngine.SceneGizmoLookAndFeel);
|
||||
|
||||
_gizmoEngine.MoveGizmoSettings2D.FoldoutLabel = "2D Mode settings";
|
||||
_gizmoEngine.MoveGizmoSettings2D.UsesFoldout = true;
|
||||
_gizmoEngine.MoveGizmoSettings3D.FoldoutLabel = "3D Mode settings";
|
||||
_gizmoEngine.MoveGizmoSettings3D.UsesFoldout = true;
|
||||
_gizmoEngine.MoveGizmoLookAndFeel2D.FoldoutLabel = "2D Mode look & feel";
|
||||
_gizmoEngine.MoveGizmoLookAndFeel2D.UsesFoldout = true;
|
||||
_gizmoEngine.MoveGizmoLookAndFeel3D.FoldoutLabel = "3D Mode look & feel";
|
||||
_gizmoEngine.MoveGizmoLookAndFeel3D.UsesFoldout = true;
|
||||
_gizmoEngine.MoveGizmoHotkeys.FoldoutLabel = "Hotkeys";
|
||||
_gizmoEngine.MoveGizmoHotkeys.UsesFoldout = true;
|
||||
_gizmoEngine.ObjectMoveGizmoSettings.FoldoutLabel = "Object settings";
|
||||
_gizmoEngine.ObjectMoveGizmoSettings.UsesFoldout = true;
|
||||
|
||||
_gizmoEngine.RotationGizmoSettings3D.FoldoutLabel = "Settings";
|
||||
_gizmoEngine.RotationGizmoSettings3D.UsesFoldout = true;
|
||||
_gizmoEngine.RotationGizmoLookAndFeel3D.FoldoutLabel = "Look & feel";
|
||||
_gizmoEngine.RotationGizmoLookAndFeel3D.UsesFoldout = true;
|
||||
_gizmoEngine.RotationGizmoHotkeys.FoldoutLabel = "Hotkeys";
|
||||
_gizmoEngine.RotationGizmoHotkeys.UsesFoldout = true;
|
||||
_gizmoEngine.ObjectRotationGizmoSettings.FoldoutLabel = "Object settings";
|
||||
_gizmoEngine.ObjectRotationGizmoSettings.UsesFoldout = true;
|
||||
|
||||
_gizmoEngine.ScaleGizmoSettings3D.FoldoutLabel = "Settings";
|
||||
_gizmoEngine.ScaleGizmoSettings3D.UsesFoldout = true;
|
||||
_gizmoEngine.ScaleGizmoLookAndFeel3D.FoldoutLabel = "Look & feel";
|
||||
_gizmoEngine.ScaleGizmoLookAndFeel3D.UsesFoldout = true;
|
||||
_gizmoEngine.ScaleGizmoHotkeys.FoldoutLabel = "Hotkeys";
|
||||
_gizmoEngine.ScaleGizmoHotkeys.UsesFoldout = true;
|
||||
_gizmoEngine.ObjectScaleGizmoSettings.FoldoutLabel = "Object settings";
|
||||
_gizmoEngine.ObjectScaleGizmoSettings.UsesFoldout = true;
|
||||
|
||||
_gizmoEngine.UniversalGizmoSettings2D.FoldoutLabel = "2D Mode settings";
|
||||
_gizmoEngine.UniversalGizmoSettings2D.UsesFoldout = true;
|
||||
_gizmoEngine.UniversalGizmoSettings3D.FoldoutLabel = "3D Mode settings";
|
||||
_gizmoEngine.UniversalGizmoSettings3D.UsesFoldout = true;
|
||||
_gizmoEngine.UniversalGizmoLookAndFeel2D.FoldoutLabel = "2D Mode look & feel";
|
||||
_gizmoEngine.UniversalGizmoLookAndFeel2D.UsesFoldout = true;
|
||||
_gizmoEngine.UniversalGizmoLookAndFeel3D.FoldoutLabel = "3D Mode look & feel";
|
||||
_gizmoEngine.UniversalGizmoLookAndFeel3D.UsesFoldout = true;
|
||||
_gizmoEngine.UniversalGizmoHotkeys.FoldoutLabel = "Hotkeys";
|
||||
_gizmoEngine.UniversalGizmoHotkeys.UsesFoldout = true;
|
||||
_gizmoEngine.ObjectUniversalGizmoSettings.FoldoutLabel = "Object settings";
|
||||
_gizmoEngine.ObjectUniversalGizmoSettings.UsesFoldout = true;
|
||||
|
||||
var tab = _gizmoEngine.MainToolbar.GetTabByIndex(_moveGizmoTab);
|
||||
tab.AddTargetSettings(_gizmoEngine.ObjectMoveGizmoSettings);
|
||||
tab.AddTargetSettings(_gizmoEngine.MoveGizmoSettings3D);
|
||||
tab.AddTargetSettings(_gizmoEngine.MoveGizmoSettings2D);
|
||||
tab.AddTargetSettings(_gizmoEngine.MoveGizmoLookAndFeel3D);
|
||||
tab.AddTargetSettings(_gizmoEngine.MoveGizmoLookAndFeel2D);
|
||||
tab.AddTargetSettings(_gizmoEngine.MoveGizmoHotkeys);
|
||||
|
||||
tab = _gizmoEngine.MainToolbar.GetTabByIndex(_rotationGizmoTab);
|
||||
tab.AddTargetSettings(_gizmoEngine.ObjectRotationGizmoSettings);
|
||||
tab.AddTargetSettings(_gizmoEngine.RotationGizmoSettings3D);
|
||||
tab.AddTargetSettings(_gizmoEngine.RotationGizmoLookAndFeel3D);
|
||||
tab.AddTargetSettings(_gizmoEngine.RotationGizmoHotkeys);
|
||||
|
||||
tab = _gizmoEngine.MainToolbar.GetTabByIndex(_scaleGizmoTab);
|
||||
tab.AddTargetSettings(_gizmoEngine.ObjectScaleGizmoSettings);
|
||||
tab.AddTargetSettings(_gizmoEngine.ScaleGizmoSettings3D);
|
||||
tab.AddTargetSettings(_gizmoEngine.ScaleGizmoLookAndFeel3D);
|
||||
tab.AddTargetSettings(_gizmoEngine.ScaleGizmoHotkeys);
|
||||
|
||||
tab = _gizmoEngine.MainToolbar.GetTabByIndex(_universalGizmoTab);
|
||||
tab.AddTargetSettings(_gizmoEngine.UniversalGizmoConfig);
|
||||
tab.AddTargetSettings(_gizmoEngine.ObjectUniversalGizmoSettings);
|
||||
tab.AddTargetSettings(_gizmoEngine.UniversalGizmoSettings2D);
|
||||
tab.AddTargetSettings(_gizmoEngine.UniversalGizmoSettings3D);
|
||||
tab.AddTargetSettings(_gizmoEngine.UniversalGizmoLookAndFeel2D);
|
||||
tab.AddTargetSettings(_gizmoEngine.UniversalGizmoLookAndFeel3D);
|
||||
tab.AddTargetSettings(_gizmoEngine.UniversalGizmoHotkeys);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f999de9a48aa6a54f84eefdca82133b4
|
||||
timeCreated: 1497955245
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
9
Assets/Runtime Transform Gizmos/Scripting Tutorials.meta
Normal file
9
Assets/Runtime Transform Gizmos/Scripting Tutorials.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 267643c1b145de0419ea03c079ebd643
|
||||
folderAsset: yes
|
||||
timeCreated: 1533928667
|
||||
licenseType: Store
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,59 @@
|
||||
using UnityEngine;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace RTG
|
||||
{
|
||||
/// <summary>
|
||||
/// In this tutorial we create 4 gizmos (move, rotation, scale, universal)
|
||||
/// and assign an object to each gizmo. In order to use the tutorial, you
|
||||
/// have to open up the 'Tutorial_0_CreatingGizmos' scene.
|
||||
/// </summary>
|
||||
public class Tut_0_CreatingGizmos_and_AssigningObjects : MonoBehaviour
|
||||
{
|
||||
/// <summary>
|
||||
/// Performs all necessary initializations. In this tutorial, we create
|
||||
/// 4 gizmos and assign them to 4 different objects each.
|
||||
/// </summary>
|
||||
private void Start()
|
||||
{
|
||||
// We will first create the move gizmo. We make a call to 'RTGizmosEngine.Get.CreateObjectMoveGizmo'
|
||||
// and this function will return an instance of the 'ObjectTransformGizmo' class which is configured
|
||||
// to act like a move gizmo. The 'ObjectTransformGizmo' class is derived from 'GizmoBehaviour'. You
|
||||
// can think of a gizmo behaviour as the equivalent of a 'MonoBehaviour', but for gizmos. The object
|
||||
// transform gizmo behaviour is responsible for listening to gizmo drag events (when you drag the gizmo
|
||||
// with the mouse) and applying the drag values to the target object which is set via 'SetTargetObject'.
|
||||
ObjectTransformGizmo objectTransformGizmo = RTGizmosEngine.Get.CreateObjectMoveGizmo();
|
||||
GameObject targetObject = GameObject.Find("RedCube");
|
||||
objectTransformGizmo.SetTargetObject(targetObject);
|
||||
|
||||
// Now we need to add support for vertex snapping. In order to do this, we need to access another gizmo
|
||||
// behaviour: 'MoveGizmo'. This behaviour is responsible for drawing the gizmo in the scene and generating
|
||||
// the drag values which are then intercepted by 'ObjectTransformGizmo'. In order to support vertex snapping,
|
||||
// we have to call 'SetVertexSnapTargetObjects' and pass a list of objects that contain the source vertices.
|
||||
// In this case, we only have one target object, so we will use that.
|
||||
MoveGizmo moveGizmo = objectTransformGizmo.Gizmo.MoveGizmo;
|
||||
moveGizmo.SetVertexSnapTargetObjects(new List<GameObject> { targetObject });
|
||||
|
||||
// Now we need to do the same thing for the other gizmos. Next one on the list is the rotation gizmo. Again,
|
||||
// we use the 'RTGizmosEngine' class to create the gizmo. The return value is the same: an instance of the
|
||||
// 'ObjectTransformGizmo' class. The exception in this case is that the returned transform gizmo is configured
|
||||
// to intercept rotation values and thus it will rotate objects instead of moving them.
|
||||
objectTransformGizmo = RTGizmosEngine.Get.CreateObjectRotationGizmo();
|
||||
targetObject = GameObject.Find("GreenCube");
|
||||
objectTransformGizmo.SetTargetObject(targetObject);
|
||||
|
||||
// Same for the scale gizmo
|
||||
objectTransformGizmo = RTGizmosEngine.Get.CreateObjectScaleGizmo();
|
||||
targetObject = GameObject.Find("BlueCube");
|
||||
objectTransformGizmo.SetTargetObject(targetObject);
|
||||
|
||||
// Same for the universal gizmo.
|
||||
// Note: The object transform gizmo returned from 'CreateObjectUniversalGizmo' is configured to intercept all
|
||||
// types of drag values: offset, rotation and scale. This is because a universal gizmo can be used to
|
||||
// move, rotate and scale objects.
|
||||
objectTransformGizmo = RTGizmosEngine.Get.CreateObjectUniversalGizmo();
|
||||
targetObject = GameObject.Find("YellowCube");
|
||||
objectTransformGizmo.SetTargetObject(targetObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d996e69dcc656f94190979d72121871b
|
||||
timeCreated: 1533928687
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8ada1c043650e4a4892cabcae968b130
|
||||
timeCreated: 1533991480
|
||||
licenseType: Store
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,207 @@
|
||||
using UnityEngine;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace RTG
|
||||
{
|
||||
/// <summary>
|
||||
/// The main focus in this tutorial is to learn how to enable and
|
||||
/// disable gizmos in the scene, switch between different gizmo
|
||||
/// types, pick a target object by clicking on objects in the scene
|
||||
/// and implement a basic gizmo manager in the process.
|
||||
/// </summary>
|
||||
public class Tut_1_Enabling_and_Disabling_Gizmos : MonoBehaviour
|
||||
{
|
||||
/// <summary>
|
||||
/// A private enum which is used by the class to differentiate between different
|
||||
/// gizmo types. An example where this enum will come in handy is when we use the
|
||||
/// W,E,R,T keys to switch between different types of gizmos. When the W key is
|
||||
/// pressed for example, we will call the 'SetWorkGizmoId' function passing
|
||||
/// GizmoId.Move as the parameter.
|
||||
/// </summary>
|
||||
private enum GizmoId
|
||||
{
|
||||
Move = 1,
|
||||
Rotate,
|
||||
Scale,
|
||||
Universal
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The following 4 variables are references to the ObjectTransformGizmo behaviours
|
||||
/// that will be used to move, rotate and scale our objects.
|
||||
/// </summary>
|
||||
private ObjectTransformGizmo _objectMoveGizmo;
|
||||
private ObjectTransformGizmo _objectRotationGizmo;
|
||||
private ObjectTransformGizmo _objectScaleGizmo;
|
||||
private ObjectTransformGizmo _objectUniversalGizmo;
|
||||
|
||||
/// <summary>
|
||||
/// The current work gizmo id. The work gizmo is the gizmo which is currently used
|
||||
/// to transform objects. The W,E,R,T keys can be used to change the work gizmo as
|
||||
/// needed.
|
||||
/// </summary>
|
||||
private GizmoId _workGizmoId;
|
||||
/// <summary>
|
||||
/// A reference to the current work gizmo. If the work gizmo id is GizmoId.Move, then
|
||||
/// this will point to '_objectMoveGizmo'. For GizmoId.Rotate, it will point to
|
||||
/// '_objectRotationGizmo' and so on.
|
||||
/// </summary>
|
||||
private ObjectTransformGizmo _workGizmo;
|
||||
/// <summary>
|
||||
/// A reference to the target object. This is the object that will be manipulated by
|
||||
/// the gizmos and it will always be picked from the scene via a mouse click. This will
|
||||
/// be set to null when the user clicks in thin air.
|
||||
/// </summary>
|
||||
private GameObject _targetObject;
|
||||
|
||||
/// <summary>
|
||||
/// Performs all necessary initializations.
|
||||
/// </summary>
|
||||
private void Start()
|
||||
{
|
||||
// Create the 4 gizmos
|
||||
_objectMoveGizmo = RTGizmosEngine.Get.CreateObjectMoveGizmo();
|
||||
_objectRotationGizmo = RTGizmosEngine.Get.CreateObjectRotationGizmo();
|
||||
_objectScaleGizmo = RTGizmosEngine.Get.CreateObjectScaleGizmo();
|
||||
_objectUniversalGizmo = RTGizmosEngine.Get.CreateObjectUniversalGizmo();
|
||||
|
||||
// Call the 'SetEnabled' function on the parent gizmo to make sure
|
||||
// the gizmos are initially hidden in the scene. We want the gizmo
|
||||
// to show only when we have a target object available.
|
||||
_objectMoveGizmo.Gizmo.SetEnabled(false);
|
||||
_objectRotationGizmo.Gizmo.SetEnabled(false);
|
||||
_objectScaleGizmo.Gizmo.SetEnabled(false);
|
||||
_objectUniversalGizmo.Gizmo.SetEnabled(false);
|
||||
|
||||
// We initialize the work gizmo to the move gizmo by default. This means
|
||||
// that the first time an object is clicked, the move gizmo will appear.
|
||||
// You can change the default gizmo, by simply changing these 2 lines of
|
||||
// code. For example, if you wanted the scale gizmo to be the default work
|
||||
// gizmo, replace '_objectMoveGizmo' with '_objectScaleGizmo' and GizmoId.Move
|
||||
// with GizmoId.Scale.
|
||||
_workGizmo = _objectMoveGizmo;
|
||||
_workGizmoId = GizmoId.Move;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called every frame to perform all necessary updates. In this tutorial,
|
||||
/// we listen to user input and take action.
|
||||
/// </summary>
|
||||
private void Update()
|
||||
{
|
||||
// Check if the left mouse button was pressed in the current frame.
|
||||
// Note: Something that was left out of the video tutorial by mistake. We
|
||||
// only take the mouse click into account if no gizmo is currently
|
||||
// hovered. When a gizmo is hovered, we ignore clicks because in that
|
||||
// case a click usually represents the intent of clicking and dragging
|
||||
// the gizmo handles. If we didn't perform this check, clicking on a
|
||||
// gizmo might actually disable it instead if the click does not hover
|
||||
// a game object (i.e. thin air click).
|
||||
if (RTInput.WasLeftMouseButtonPressedThisFrame() &&
|
||||
RTGizmosEngine.Get.HoveredGizmo == null)
|
||||
{
|
||||
// The left mouse button was pressed; now pick a game object and check
|
||||
// if the picked object is different than the current target object if
|
||||
// if is, we call 'OnTargetObjectChanged' to take action.
|
||||
GameObject pickedObject = PickGameObject();
|
||||
if (pickedObject != _targetObject) OnTargetObjectChanged(pickedObject);
|
||||
}
|
||||
|
||||
// Switch between different gizmo types using the W,E,R,T keys.
|
||||
// Note: We use the 'SetWorkGizmoId' function to perform the switch.
|
||||
if (RTInput.WasKeyPressedThisFrame(KeyCode.W)) SetWorkGizmoId(GizmoId.Move);
|
||||
else if (RTInput.WasKeyPressedThisFrame(KeyCode.E)) SetWorkGizmoId(GizmoId.Rotate);
|
||||
else if (RTInput.WasKeyPressedThisFrame(KeyCode.R)) SetWorkGizmoId(GizmoId.Scale);
|
||||
else if (RTInput.WasKeyPressedThisFrame(KeyCode.T)) SetWorkGizmoId(GizmoId.Universal);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Uses the mouse position to pick a game object in the scene. Returns
|
||||
/// the picked game object or null if no object is picked.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Objects must have colliders attached.
|
||||
/// </remarks>
|
||||
private GameObject PickGameObject()
|
||||
{
|
||||
// Build a ray using the current mouse cursor position
|
||||
Ray ray = Camera.main.ScreenPointToRay(RTInput.MousePosition);
|
||||
|
||||
// Check if the ray intersects a game object. If it does, return it
|
||||
RaycastHit rayHit;
|
||||
if (Physics.Raycast(ray, out rayHit, float.MaxValue))
|
||||
return rayHit.collider.gameObject;
|
||||
|
||||
// No object is intersected by the ray. Return null.
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This function is called to change the type of work gizmo. This is
|
||||
/// used in the 'Update' function in response to the user pressing the
|
||||
/// W,E,R,T keys to switch between different gizmo types.
|
||||
/// </summary>
|
||||
private void SetWorkGizmoId(GizmoId gizmoId)
|
||||
{
|
||||
// If the specified gizmo id is the same as the current id, there is nothing left to do
|
||||
if (gizmoId == _workGizmoId) return;
|
||||
|
||||
// Start with a clean slate and disable all gizmos
|
||||
_objectMoveGizmo.Gizmo.SetEnabled(false);
|
||||
_objectRotationGizmo.Gizmo.SetEnabled(false);
|
||||
_objectScaleGizmo.Gizmo.SetEnabled(false);
|
||||
_objectUniversalGizmo.Gizmo.SetEnabled(false);
|
||||
|
||||
// At this point all gizmos are disabled. Now we need to check the gizmo id
|
||||
// and adjust the '_workGizmo' variable.
|
||||
_workGizmoId = gizmoId;
|
||||
if (gizmoId == GizmoId.Move) _workGizmo = _objectMoveGizmo;
|
||||
else if (gizmoId == GizmoId.Rotate) _workGizmo = _objectRotationGizmo;
|
||||
else if (gizmoId == GizmoId.Scale) _workGizmo = _objectScaleGizmo;
|
||||
else if (gizmoId == GizmoId.Universal) _workGizmo = _objectUniversalGizmo;
|
||||
|
||||
// At this point, the work gizmo points to the correct gizmo based on the
|
||||
// specified gizmo id. All that's left to do is to activate the gizmo.
|
||||
// Note: We only activate the gizmo if we have a target object available.
|
||||
// If no target object is available, we don't do anything because we
|
||||
// only want to show a gizmo when a target is available for use.
|
||||
if (_targetObject != null) _workGizmo.Gizmo.SetEnabled(true);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called from the 'Update' function when the user clicks on a game object
|
||||
/// that is different from the current target object. The function takes care
|
||||
/// of adjusting the gizmo states accordingly.
|
||||
/// </summary>
|
||||
private void OnTargetObjectChanged(GameObject newTargetObject)
|
||||
{
|
||||
// Store the new target object
|
||||
_targetObject = newTargetObject;
|
||||
|
||||
// Is the target object valid?
|
||||
if (_targetObject != null)
|
||||
{
|
||||
// It is. Now call 'SetTargetObject' for all gizmos. After the next 4 lines
|
||||
// of code are executed, all gizmos will be able to control this object.
|
||||
_objectMoveGizmo.SetTargetObject(_targetObject);
|
||||
_objectRotationGizmo.SetTargetObject(_targetObject);
|
||||
_objectScaleGizmo.SetTargetObject(_targetObject);
|
||||
_objectUniversalGizmo.SetTargetObject(_targetObject);
|
||||
|
||||
// Make sure the work gizmo is enabled. We always activate the work gizmo when
|
||||
// a target object is valid. There is no need to check if the gizmo is already
|
||||
// enabled. The 'SetEnabled' call will simply be ignored if that is the case.
|
||||
_workGizmo.Gizmo.SetEnabled(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
// The target object is null. In this case, we don't want any gizmos to be visible
|
||||
// in the scene, so we disable all of them.
|
||||
_objectMoveGizmo.Gizmo.SetEnabled(false);
|
||||
_objectRotationGizmo.Gizmo.SetEnabled(false);
|
||||
_objectScaleGizmo.Gizmo.SetEnabled(false);
|
||||
_objectUniversalGizmo.Gizmo.SetEnabled(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fc8c7e0092c581942bfffa063236d91e
|
||||
timeCreated: 1533928687
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b674ca0ba1385a74ca84f00c872b52b2
|
||||
timeCreated: 1533991480
|
||||
licenseType: Store
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,253 @@
|
||||
using UnityEngine;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace RTG
|
||||
{
|
||||
/// <summary>
|
||||
/// The main focus in this tutorial is to learn how to assign multiple
|
||||
/// target objects to a gizmo. This enables our gizmos to control more
|
||||
/// than one object at a time.
|
||||
/// </summary>
|
||||
public class Tut_2_MultipleTargetObjects : MonoBehaviour
|
||||
{
|
||||
/// <summary>
|
||||
/// A private enum which is used by the class to differentiate between different
|
||||
/// gizmo types. An example where this enum will come in handy is when we use the
|
||||
/// W,E,R,T keys to switch between different types of gizmos. When the W key is
|
||||
/// pressed for example, we will call the 'SetWorkGizmoId' function passing
|
||||
/// GizmoId.Move as the parameter.
|
||||
/// </summary>
|
||||
private enum GizmoId
|
||||
{
|
||||
Move = 1,
|
||||
Rotate,
|
||||
Scale,
|
||||
Universal
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The following 4 variables are references to the ObjectTransformGizmo behaviours
|
||||
/// that will be used to move, rotate and scale our objects.
|
||||
/// </summary>
|
||||
private ObjectTransformGizmo _objectMoveGizmo;
|
||||
private ObjectTransformGizmo _objectRotationGizmo;
|
||||
private ObjectTransformGizmo _objectScaleGizmo;
|
||||
private ObjectTransformGizmo _objectUniversalGizmo;
|
||||
|
||||
/// <summary>
|
||||
/// The current work gizmo id. The work gizmo is the gizmo which is currently used
|
||||
/// to transform objects. The W,E,R,T keys can be used to change the work gizmo as
|
||||
/// needed.
|
||||
/// </summary>
|
||||
private GizmoId _workGizmoId;
|
||||
/// <summary>
|
||||
/// A reference to the current work gizmo. If the work gizmo id is GizmoId.Move, then
|
||||
/// this will point to '_objectMoveGizmo'. For GizmoId.Rotate, it will point to
|
||||
/// '_objectRotationGizmo' and so on.
|
||||
/// </summary>
|
||||
private ObjectTransformGizmo _workGizmo;
|
||||
/// <summary>
|
||||
/// A list of objects which are currently selected. This is also the list that holds
|
||||
/// the gizmo target objects.
|
||||
/// </summary>
|
||||
private List<GameObject> _selectedObjects = new List<GameObject>();
|
||||
|
||||
/// <summary>
|
||||
/// Performs all necessary initializations.
|
||||
/// </summary>
|
||||
private void Start()
|
||||
{
|
||||
// Create the 4 gizmos
|
||||
_objectMoveGizmo = RTGizmosEngine.Get.CreateObjectMoveGizmo();
|
||||
_objectRotationGizmo = RTGizmosEngine.Get.CreateObjectRotationGizmo();
|
||||
_objectScaleGizmo = RTGizmosEngine.Get.CreateObjectScaleGizmo();
|
||||
_objectUniversalGizmo = RTGizmosEngine.Get.CreateObjectUniversalGizmo();
|
||||
|
||||
// Call the 'SetEnabled' function on the parent gizmo to make sure
|
||||
// the gizmos are initially hidden in the scene. We want the gizmo
|
||||
// to show only when we have a target object available.
|
||||
_objectMoveGizmo.Gizmo.SetEnabled(false);
|
||||
_objectRotationGizmo.Gizmo.SetEnabled(false);
|
||||
_objectScaleGizmo.Gizmo.SetEnabled(false);
|
||||
_objectUniversalGizmo.Gizmo.SetEnabled(false);
|
||||
|
||||
// Link the selected objects list to the gizmos
|
||||
// Note: The 'SetTargetObjects' function will instruct the gizmo to store
|
||||
// a direct reference to the '_selecteObjects' list. This means that
|
||||
// when you add or remove objects from this list, the gizmos will have
|
||||
// access to the most recent/updated collection. You don't need to call
|
||||
// 'SetTargetObjects' again when the list changes.
|
||||
_objectMoveGizmo.SetTargetObjects(_selectedObjects);
|
||||
_objectRotationGizmo.SetTargetObjects(_selectedObjects);
|
||||
_objectScaleGizmo.SetTargetObjects(_selectedObjects);
|
||||
_objectUniversalGizmo.SetTargetObjects(_selectedObjects);
|
||||
|
||||
// We initialize the work gizmo to the move gizmo by default. This means
|
||||
// that the first time an object is clicked, the move gizmo will appear.
|
||||
// You can change the default gizmo, by simply changing these 2 lines of
|
||||
// code. For example, if you wanted the scale gizmo to be the default work
|
||||
// gizmo, replace '_objectMoveGizmo' with '_objectScaleGizmo' and GizmoId.Move
|
||||
// with GizmoId.Scale.
|
||||
_workGizmo = _objectMoveGizmo;
|
||||
_workGizmoId = GizmoId.Move;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called every frame to perform all necessary updates. In this tutorial,
|
||||
/// we listen to user input and take action.
|
||||
/// </summary>
|
||||
private void Update()
|
||||
{
|
||||
// Check if the left mouse button was pressed in the current frame.
|
||||
// Note: Something that was left out of the video tutorial by mistake. We
|
||||
// only take the mouse click into account if no gizmo is currently
|
||||
// hovered. When a gizmo is hovered, we ignore clicks because in that
|
||||
// case a click usually represents the intent of clicking and dragging
|
||||
// the gizmo handles. If we didn't perform this check, clicking on a
|
||||
// gizmo might actually disable it instead if the click does not hover
|
||||
// a game object (i.e. thin air click).
|
||||
if (RTInput.WasLeftMouseButtonPressedThisFrame() &&
|
||||
RTGizmosEngine.Get.HoveredGizmo == null)
|
||||
{
|
||||
// Pick a game object
|
||||
GameObject pickedObject = PickGameObject();
|
||||
if (pickedObject != null)
|
||||
{
|
||||
// Is the CTRL key pressed?
|
||||
if (RTInput.IsKeyPressed(KeyCode.LeftControl))
|
||||
{
|
||||
// The CTRL key is pressed; it means we find ourselves in 2 possible situations:
|
||||
// a) the picked object is already selected, in which case we deselect it;
|
||||
// b) the picked object is not selected, in which case we append it to the selection.
|
||||
if (_selectedObjects.Contains(pickedObject)) _selectedObjects.Remove(pickedObject);
|
||||
else _selectedObjects.Add(pickedObject);
|
||||
|
||||
// The selection has changed
|
||||
OnSelectionChanged();
|
||||
}
|
||||
else
|
||||
{
|
||||
// The CTRL key is not pressed; in this case we just clear the selection and
|
||||
// select only the object that we clicked on.
|
||||
_selectedObjects.Clear();
|
||||
_selectedObjects.Add(pickedObject);
|
||||
|
||||
// The selection has changed
|
||||
OnSelectionChanged();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// If we reach this point, it means no object was picked. This means that we clicked
|
||||
// in thin air, so we just clear the selected objects list.
|
||||
_selectedObjects.Clear();
|
||||
OnSelectionChanged();
|
||||
|
||||
// The selection has changed
|
||||
OnSelectionChanged();
|
||||
}
|
||||
}
|
||||
|
||||
// Switch between different gizmo types using the W,E,R,T keys.
|
||||
// Note: We use the 'SetWorkGizmoId' function to perform the switch.
|
||||
if (RTInput.WasKeyPressedThisFrame(KeyCode.W)) SetWorkGizmoId(GizmoId.Move);
|
||||
else if (RTInput.WasKeyPressedThisFrame(KeyCode.E)) SetWorkGizmoId(GizmoId.Rotate);
|
||||
else if (RTInput.WasKeyPressedThisFrame(KeyCode.R)) SetWorkGizmoId(GizmoId.Scale);
|
||||
else if (RTInput.WasKeyPressedThisFrame(KeyCode.T)) SetWorkGizmoId(GizmoId.Universal);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Uses the mouse position to pick a game object in the scene. Returns
|
||||
/// the picked game object or null if no object is picked.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Objects must have colliders attached.
|
||||
/// </remarks>
|
||||
private GameObject PickGameObject()
|
||||
{
|
||||
// Build a ray using the current mouse cursor position
|
||||
Ray ray = Camera.main.ScreenPointToRay(RTInput.MousePosition);
|
||||
|
||||
// Check if the ray intersects a game object. If it does, return it
|
||||
RaycastHit rayHit;
|
||||
if (Physics.Raycast(ray, out rayHit, float.MaxValue))
|
||||
return rayHit.collider.gameObject;
|
||||
|
||||
// No object is intersected by the ray. Return null.
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This function is called to change the type of work gizmo. This is
|
||||
/// used in the 'Update' function in response to the user pressing the
|
||||
/// W,E,R,T keys to switch between different gizmo types.
|
||||
/// </summary>
|
||||
private void SetWorkGizmoId(GizmoId gizmoId)
|
||||
{
|
||||
// If the specified gizmo id is the same as the current id, there is nothing left to do
|
||||
if (gizmoId == _workGizmoId) return;
|
||||
|
||||
// Start with a clean slate and disable all gizmos
|
||||
_objectMoveGizmo.Gizmo.SetEnabled(false);
|
||||
_objectRotationGizmo.Gizmo.SetEnabled(false);
|
||||
_objectScaleGizmo.Gizmo.SetEnabled(false);
|
||||
_objectUniversalGizmo.Gizmo.SetEnabled(false);
|
||||
|
||||
// At this point all gizmos are disabled. Now we need to check the gizmo id
|
||||
// and adjust the '_workGizmo' variable.
|
||||
_workGizmoId = gizmoId;
|
||||
if (gizmoId == GizmoId.Move) _workGizmo = _objectMoveGizmo;
|
||||
else if (gizmoId == GizmoId.Rotate) _workGizmo = _objectRotationGizmo;
|
||||
else if (gizmoId == GizmoId.Scale) _workGizmo = _objectScaleGizmo;
|
||||
else if (gizmoId == GizmoId.Universal) _workGizmo = _objectUniversalGizmo;
|
||||
|
||||
// If we have any selected objects, we need to make sure the work gizmo is enabled
|
||||
if (_selectedObjects.Count != 0)
|
||||
{
|
||||
// Make sure the work gizmo is enabled. There is no need to check if the gizmo is already
|
||||
// enabled. The 'SetEnabled' call will simply be ignored if that is the case.
|
||||
_workGizmo.Gizmo.SetEnabled(true);
|
||||
|
||||
// The last step we need to perform is to make sure that the work gizmo is positioned
|
||||
// and rotated correctly. This is because the gizmos (as will become more clear in
|
||||
// later tutorials) have 2 properties such as transform space and transform pivot and
|
||||
// when the selected objects change, these 2 properties will dictate how the gizmo should
|
||||
// be positioned and rotated. In order to ensure that the correct position and rotation
|
||||
// are used, we need to call 'RefreshPositionAndRotation'.
|
||||
_workGizmo.RefreshPositionAndRotation();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called from the 'Update' function whenever the '_selectedObjects' list
|
||||
/// changes. It is responsible for updating the gizmos accordingly.
|
||||
/// </summary>
|
||||
private void OnSelectionChanged()
|
||||
{
|
||||
// If we have any selected objects, we need to make sure the work gizmo is enabled
|
||||
if (_selectedObjects.Count != 0)
|
||||
{
|
||||
// Make sure the work gizmo is enabled. There is no need to check if the gizmo is already
|
||||
// enabled. The 'SetEnabled' call will simply be ignored if that is the case.
|
||||
_workGizmo.Gizmo.SetEnabled(true);
|
||||
|
||||
// The last step we need to perform is to make sure that the work gizmo is positioned
|
||||
// and rotated correctly. This is because the gizmos (as will become more clear in
|
||||
// later tutorials) have 2 properties such as transform space and transform pivot and
|
||||
// when the selected objects change, these 2 properties will dictate how the gizmo should
|
||||
// be positioned and rotated. In order to ensure that the correct position and rotation
|
||||
// are used, we need to call 'RefreshPositionAndRotation'.
|
||||
_workGizmo.RefreshPositionAndRotation();
|
||||
}
|
||||
else
|
||||
{
|
||||
// The target object is null. In this case, we don't want any gizmos to be visible
|
||||
// in the scene, so we disable all of them.
|
||||
_objectMoveGizmo.Gizmo.SetEnabled(false);
|
||||
_objectRotationGizmo.Gizmo.SetEnabled(false);
|
||||
_objectScaleGizmo.Gizmo.SetEnabled(false);
|
||||
_objectUniversalGizmo.Gizmo.SetEnabled(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9ec6cb4737782da49a7bc377ad93f297
|
||||
timeCreated: 1533928687
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b9044b6d50141bc48931f7c793e6e4fa
|
||||
timeCreated: 1533991480
|
||||
licenseType: Store
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,297 @@
|
||||
using UnityEngine;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace RTG
|
||||
{
|
||||
/// <summary>
|
||||
/// The main focus in this tutorial is to learn how to change the transform
|
||||
/// space (Global & Local) of a transform gizmo.
|
||||
/// </summary>
|
||||
public class Tut_3_TransformSpaces : MonoBehaviour
|
||||
{
|
||||
/// <summary>
|
||||
/// A private enum which is used by the class to differentiate between different
|
||||
/// gizmo types. An example where this enum will come in handy is when we use the
|
||||
/// W,E,R,T keys to switch between different types of gizmos. When the W key is
|
||||
/// pressed for example, we will call the 'SetWorkGizmoId' function passing
|
||||
/// GizmoId.Move as the parameter.
|
||||
/// </summary>
|
||||
private enum GizmoId
|
||||
{
|
||||
Move = 1,
|
||||
Rotate,
|
||||
Scale,
|
||||
Universal
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The following 4 variables are references to the ObjectTransformGizmo behaviours
|
||||
/// that will be used to move, rotate and scale our objects.
|
||||
/// </summary>
|
||||
private ObjectTransformGizmo _objectMoveGizmo;
|
||||
private ObjectTransformGizmo _objectRotationGizmo;
|
||||
private ObjectTransformGizmo _objectScaleGizmo;
|
||||
private ObjectTransformGizmo _objectUniversalGizmo;
|
||||
|
||||
/// <summary>
|
||||
/// The current work gizmo id. The work gizmo is the gizmo which is currently used
|
||||
/// to transform objects. The W,E,R,T keys can be used to change the work gizmo as
|
||||
/// needed.
|
||||
/// </summary>
|
||||
private GizmoId _workGizmoId;
|
||||
/// <summary>
|
||||
/// A reference to the current work gizmo. If the work gizmo id is GizmoId.Move, then
|
||||
/// this will point to '_objectMoveGizmo'. For GizmoId.Rotate, it will point to
|
||||
/// '_objectRotationGizmo' and so on.
|
||||
/// </summary>
|
||||
private ObjectTransformGizmo _workGizmo;
|
||||
/// <summary>
|
||||
/// A list of objects which are currently selected. This is also the list that holds
|
||||
/// the gizmo target objects.
|
||||
/// </summary>
|
||||
private List<GameObject> _selectedObjects = new List<GameObject>();
|
||||
|
||||
/// <summary>
|
||||
/// Performs all necessary initializations.
|
||||
/// </summary>
|
||||
private void Start()
|
||||
{
|
||||
// Create the 4 gizmos
|
||||
_objectMoveGizmo = RTGizmosEngine.Get.CreateObjectMoveGizmo();
|
||||
_objectRotationGizmo = RTGizmosEngine.Get.CreateObjectRotationGizmo();
|
||||
_objectScaleGizmo = RTGizmosEngine.Get.CreateObjectScaleGizmo();
|
||||
_objectUniversalGizmo = RTGizmosEngine.Get.CreateObjectUniversalGizmo();
|
||||
|
||||
// Call the 'SetEnabled' function on the parent gizmo to make sure
|
||||
// the gizmos are initially hidden in the scene. We want the gizmo
|
||||
// to show only when we have a target object available.
|
||||
_objectMoveGizmo.Gizmo.SetEnabled(false);
|
||||
_objectRotationGizmo.Gizmo.SetEnabled(false);
|
||||
_objectScaleGizmo.Gizmo.SetEnabled(false);
|
||||
_objectUniversalGizmo.Gizmo.SetEnabled(false);
|
||||
|
||||
// Link the selected objects list to the gizmos
|
||||
// Note: The 'SetTargetObjects' function will instruct the gizmo to store
|
||||
// a direct reference to the '_selecteObjects' list. This means that
|
||||
// when you add or remove objects from this list, the gizmos will have
|
||||
// access to the most recent/updated collection. You don't need to call
|
||||
// 'SetTargetObjects' again when the list changes.
|
||||
_objectMoveGizmo.SetTargetObjects(_selectedObjects);
|
||||
_objectRotationGizmo.SetTargetObjects(_selectedObjects);
|
||||
_objectScaleGizmo.SetTargetObjects(_selectedObjects);
|
||||
_objectUniversalGizmo.SetTargetObjects(_selectedObjects);
|
||||
|
||||
// We initialize the work gizmo to the move gizmo by default. This means
|
||||
// that the first time an object is clicked, the move gizmo will appear.
|
||||
// You can change the default gizmo, by simply changing these 2 lines of
|
||||
// code. For example, if you wanted the scale gizmo to be the default work
|
||||
// gizmo, replace '_objectMoveGizmo' with '_objectScaleGizmo' and GizmoId.Move
|
||||
// with GizmoId.Scale.
|
||||
_workGizmo = _objectMoveGizmo;
|
||||
_workGizmoId = GizmoId.Move;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called every frame to perform all necessary updates. In this tutorial,
|
||||
/// we listen to user input and take action.
|
||||
/// </summary>
|
||||
private void Update()
|
||||
{
|
||||
// Check if the left mouse button was pressed in the current frame.
|
||||
// Note: Something that was left out of the video tutorial by mistake. We
|
||||
// only take the mouse click into account if no gizmo is currently
|
||||
// hovered. When a gizmo is hovered, we ignore clicks because in that
|
||||
// case a click usually represents the intent of clicking and dragging
|
||||
// the gizmo handles. If we didn't perform this check, clicking on a
|
||||
// gizmo might actually disable it instead if the click does not hover
|
||||
// a game object (i.e. thin air click).
|
||||
if (RTInput.WasLeftMouseButtonPressedThisFrame() &&
|
||||
RTGizmosEngine.Get.HoveredGizmo == null)
|
||||
{
|
||||
// Pick a game object
|
||||
GameObject pickedObject = PickGameObject();
|
||||
if (pickedObject != null)
|
||||
{
|
||||
// Is the CTRL key pressed?
|
||||
if (RTInput.IsKeyPressed(KeyCode.LeftControl))
|
||||
{
|
||||
// The CTRL key is pressed; it means we find ourselves in 2 possible situations:
|
||||
// a) the picked object is already selected, in which case we deselect it;
|
||||
// b) the picked object is not selected, in which case we append it to the selection.
|
||||
if (_selectedObjects.Contains(pickedObject)) _selectedObjects.Remove(pickedObject);
|
||||
else _selectedObjects.Add(pickedObject);
|
||||
|
||||
// The selection has changed
|
||||
OnSelectionChanged();
|
||||
}
|
||||
else
|
||||
{
|
||||
// The CTRL key is not pressed; in this case we just clear the selection and
|
||||
// select only the object that we clicked on.
|
||||
_selectedObjects.Clear();
|
||||
_selectedObjects.Add(pickedObject);
|
||||
|
||||
// The selection has changed
|
||||
OnSelectionChanged();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// If we reach this point, it means no object was picked. This means that we clicked
|
||||
// in thin air, so we just clear the selected objects list.
|
||||
_selectedObjects.Clear();
|
||||
OnSelectionChanged();
|
||||
|
||||
// The selection has changed
|
||||
OnSelectionChanged();
|
||||
}
|
||||
}
|
||||
|
||||
// If the G key was pressed, we change the transform space to Global. Otherwise,
|
||||
// if the L key was pressed, we change it to Local.
|
||||
if (RTInput.WasKeyPressedThisFrame(KeyCode.G)) SetTransformSpace(GizmoSpace.Global);
|
||||
else if (RTInput.WasKeyPressedThisFrame(KeyCode.L)) SetTransformSpace(GizmoSpace.Local);
|
||||
|
||||
// Switch between different gizmo types using the W,E,R,T keys.
|
||||
// Note: We use the 'SetWorkGizmoId' function to perform the switch.
|
||||
if (RTInput.WasKeyPressedThisFrame(KeyCode.W)) SetWorkGizmoId(GizmoId.Move);
|
||||
else if (RTInput.WasKeyPressedThisFrame(KeyCode.E)) SetWorkGizmoId(GizmoId.Rotate);
|
||||
else if (RTInput.WasKeyPressedThisFrame(KeyCode.R)) SetWorkGizmoId(GizmoId.Scale);
|
||||
else if (RTInput.WasKeyPressedThisFrame(KeyCode.T)) SetWorkGizmoId(GizmoId.Universal);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// An implementatio of the OnGUI function which shows the current transform
|
||||
/// space in the top left corner of the screen.
|
||||
/// </summary>
|
||||
private void OnGUI()
|
||||
{
|
||||
// We will use a style with a green text color
|
||||
var guiStyle = new GUIStyle();
|
||||
guiStyle.normal.textColor = Color.green;
|
||||
|
||||
// Draw the label.
|
||||
// Note: In order to get access to the current transform space, we use the 'TransformSpace'
|
||||
// property of the move gizmo. Any gizmo would do because all of them use the same
|
||||
// transform space. We make sure of that inside the 'SetTransformSpace' function.
|
||||
GUILayout.Label("Transform Space: " + _objectMoveGizmo.TransformSpace.ToString(), guiStyle);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Uses the mouse position to pick a game object in the scene. Returns
|
||||
/// the picked game object or null if no object is picked.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Objects must have colliders attached.
|
||||
/// </remarks>
|
||||
private GameObject PickGameObject()
|
||||
{
|
||||
// Build a ray using the current mouse cursor position
|
||||
Ray ray = Camera.main.ScreenPointToRay(RTInput.MousePosition);
|
||||
|
||||
// Check if the ray intersects a game object. If it does, return it
|
||||
RaycastHit rayHit;
|
||||
if (Physics.Raycast(ray, out rayHit, float.MaxValue))
|
||||
return rayHit.collider.gameObject;
|
||||
|
||||
// No object is intersected by the ray. Return null.
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This function is called to change the type of work gizmo. This is
|
||||
/// used in the 'Update' function in response to the user pressing the
|
||||
/// W,E,R,T keys to switch between different gizmo types.
|
||||
/// </summary>
|
||||
private void SetWorkGizmoId(GizmoId gizmoId)
|
||||
{
|
||||
// If the specified gizmo id is the same as the current id, there is nothing left to do
|
||||
if (gizmoId == _workGizmoId) return;
|
||||
|
||||
// Start with a clean slate and disable all gizmos
|
||||
_objectMoveGizmo.Gizmo.SetEnabled(false);
|
||||
_objectRotationGizmo.Gizmo.SetEnabled(false);
|
||||
_objectScaleGizmo.Gizmo.SetEnabled(false);
|
||||
_objectUniversalGizmo.Gizmo.SetEnabled(false);
|
||||
|
||||
// At this point all gizmos are disabled. Now we need to check the gizmo id
|
||||
// and adjust the '_workGizmo' variable.
|
||||
_workGizmoId = gizmoId;
|
||||
if (gizmoId == GizmoId.Move) _workGizmo = _objectMoveGizmo;
|
||||
else if (gizmoId == GizmoId.Rotate) _workGizmo = _objectRotationGizmo;
|
||||
else if (gizmoId == GizmoId.Scale) _workGizmo = _objectScaleGizmo;
|
||||
else if (gizmoId == GizmoId.Universal) _workGizmo = _objectUniversalGizmo;
|
||||
|
||||
// If we have any selected objects, we need to make sure the work gizmo is enabled
|
||||
if (_selectedObjects.Count != 0)
|
||||
{
|
||||
// Make sure the work gizmo is enabled. There is no need to check if the gizmo is already
|
||||
// enabled. The 'SetEnabled' call will simply be ignored if that is the case.
|
||||
_workGizmo.Gizmo.SetEnabled(true);
|
||||
|
||||
// When working with transform spaces, the gizmos need to know about the pivot object. This piece
|
||||
// of information is necessary when the transform space is set to local because in that case the
|
||||
// gizmo will have its rotation synchronized with the target objects rotation. But because there
|
||||
// is more than one target object, we need to tell the gizmo which object to use. This is the role
|
||||
// if the pivot object in this case.
|
||||
_workGizmo.SetTargetPivotObject(_selectedObjects[_selectedObjects.Count - 1]);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called from the 'Update' function whenever the '_selectedObjects' list
|
||||
/// changes. It is responsible for updating the gizmos accordingly.
|
||||
/// </summary>
|
||||
private void OnSelectionChanged()
|
||||
{
|
||||
// If we have any selected objects, we need to make sure the work gizmo is enabled
|
||||
if (_selectedObjects.Count != 0)
|
||||
{
|
||||
// Make sure the work gizmo is enabled. There is no need to check if the gizmo is already
|
||||
// enabled. The 'SetEnabled' call will simply be ignored if that is the case.
|
||||
_workGizmo.Gizmo.SetEnabled(true);
|
||||
|
||||
// When working with transform spaces, the gizmos need to know about the pivot object. This piece
|
||||
// of information is necessary when the transform space is set to local because in that case the
|
||||
// gizmo will have its rotation synchronized with the target objects rotation. But because there
|
||||
// is more than one target object, we need to tell the gizmo which object to use. This is the role
|
||||
// if the pivot object in this case.
|
||||
_workGizmo.SetTargetPivotObject(_selectedObjects[_selectedObjects.Count - 1]);
|
||||
|
||||
// The last step we need to perform is to make sure that the work gizmo is positioned
|
||||
// and rotated correctly. This is because the gizmos (as will become more clear in
|
||||
// later tutorials) have 2 properties such as transform space and transform pivot and
|
||||
// when the selected objects change, these 2 properties will dictate how the gizmo should
|
||||
// be positioned and rotated. In order to ensure that the correct position and rotation
|
||||
// are used, we need to call 'RefreshPositionAndRotation'.
|
||||
_workGizmo.RefreshPositionAndRotation();
|
||||
}
|
||||
else
|
||||
{
|
||||
// The target object is null. In this case, we don't want any gizmos to be visible
|
||||
// in the scene, so we disable all of them.
|
||||
_objectMoveGizmo.Gizmo.SetEnabled(false);
|
||||
_objectRotationGizmo.Gizmo.SetEnabled(false);
|
||||
_objectScaleGizmo.Gizmo.SetEnabled(false);
|
||||
_objectUniversalGizmo.Gizmo.SetEnabled(false);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called from the 'Update' function in response to user input in order
|
||||
/// to change the transform space for all gizmos. The parameter represents
|
||||
/// the desired transform space and is of type 'GizmoSpace'. This is an enum
|
||||
/// with 2 mamebers: Global and Local.
|
||||
/// </summary>
|
||||
private void SetTransformSpace(GizmoSpace transformSpace)
|
||||
{
|
||||
// In order to change the transform space for a gizmo, we need to call the
|
||||
// gizmo's 'SetTransformSpace' function. We do this for all gizmos and pass
|
||||
// the specified transform space as parameter.
|
||||
_objectMoveGizmo.SetTransformSpace(transformSpace);
|
||||
_objectRotationGizmo.SetTransformSpace(transformSpace);
|
||||
_objectScaleGizmo.SetTransformSpace(transformSpace);
|
||||
_objectUniversalGizmo.SetTransformSpace(transformSpace);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fa8e31054f09cdd43b20641b6bda3d81
|
||||
timeCreated: 1534160799
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 814f06f1d66b325429a5ee9b9431d1e6
|
||||
timeCreated: 1533991480
|
||||
licenseType: Store
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,335 @@
|
||||
using UnityEngine;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace RTG
|
||||
{
|
||||
/// <summary>
|
||||
/// The main focus in this tutorial is to learn how to change the transform
|
||||
/// pivot of a gizmo. There are 5 pivot types in RTG and in this tutorial we
|
||||
/// will only be talking about the ObjectGroupCenter and ObjectMeshPivot pivot
|
||||
/// types.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// No demo scene provided on purpose. You will need a demo scene with objects
|
||||
/// whose mesh pivots are defined to be anything other than the center of the
|
||||
/// object.
|
||||
/// </remarks>
|
||||
public class Tut_4_Mesh_and_Center_Pivots : MonoBehaviour
|
||||
{
|
||||
/// <summary>
|
||||
/// A private enum which is used by the class to differentiate between different
|
||||
/// gizmo types. An example where this enum will come in handy is when we use the
|
||||
/// W,E,R,T keys to switch between different types of gizmos. When the W key is
|
||||
/// pressed for example, we will call the 'SetWorkGizmoId' function passing
|
||||
/// GizmoId.Move as the parameter.
|
||||
/// </summary>
|
||||
private enum GizmoId
|
||||
{
|
||||
Move = 1,
|
||||
Rotate,
|
||||
Scale,
|
||||
Universal
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The following 4 variables are references to the ObjectTransformGizmo behaviours
|
||||
/// that will be used to move, rotate and scale our objects.
|
||||
/// </summary>
|
||||
private ObjectTransformGizmo _objectMoveGizmo;
|
||||
private ObjectTransformGizmo _objectRotationGizmo;
|
||||
private ObjectTransformGizmo _objectScaleGizmo;
|
||||
private ObjectTransformGizmo _objectUniversalGizmo;
|
||||
|
||||
/// <summary>
|
||||
/// The current work gizmo id. The work gizmo is the gizmo which is currently used
|
||||
/// to transform objects. The W,E,R,T keys can be used to change the work gizmo as
|
||||
/// needed.
|
||||
/// </summary>
|
||||
private GizmoId _workGizmoId;
|
||||
/// <summary>
|
||||
/// A reference to the current work gizmo. If the work gizmo id is GizmoId.Move, then
|
||||
/// this will point to '_objectMoveGizmo'. For GizmoId.Rotate, it will point to
|
||||
/// '_objectRotationGizmo' and so on.
|
||||
/// </summary>
|
||||
private ObjectTransformGizmo _workGizmo;
|
||||
/// <summary>
|
||||
/// A list of objects which are currently selected. This is also the list that holds
|
||||
/// the gizmo target objects.
|
||||
/// </summary>
|
||||
private List<GameObject> _selectedObjects = new List<GameObject>();
|
||||
|
||||
/// <summary>
|
||||
/// Performs all necessary initializations.
|
||||
/// </summary>
|
||||
private void Start()
|
||||
{
|
||||
// Create the 4 gizmos
|
||||
_objectMoveGizmo = RTGizmosEngine.Get.CreateObjectMoveGizmo();
|
||||
_objectRotationGizmo = RTGizmosEngine.Get.CreateObjectRotationGizmo();
|
||||
_objectScaleGizmo = RTGizmosEngine.Get.CreateObjectScaleGizmo();
|
||||
_objectUniversalGizmo = RTGizmosEngine.Get.CreateObjectUniversalGizmo();
|
||||
|
||||
// Call the 'SetEnabled' function on the parent gizmo to make sure
|
||||
// the gizmos are initially hidden in the scene. We want the gizmo
|
||||
// to show only when we have a target object available.
|
||||
_objectMoveGizmo.Gizmo.SetEnabled(false);
|
||||
_objectRotationGizmo.Gizmo.SetEnabled(false);
|
||||
_objectScaleGizmo.Gizmo.SetEnabled(false);
|
||||
_objectUniversalGizmo.Gizmo.SetEnabled(false);
|
||||
|
||||
// Link the selected objects list to the gizmos
|
||||
// Note: The 'SetTargetObjects' function will instruct the gizmo to store
|
||||
// a direct reference to the '_selecteObjects' list. This means that
|
||||
// when you add or remove objects from this list, the gizmos will have
|
||||
// access to the most recent/updated collection. You don't need to call
|
||||
// 'SetTargetObjects' again when the list changes.
|
||||
_objectMoveGizmo.SetTargetObjects(_selectedObjects);
|
||||
_objectRotationGizmo.SetTargetObjects(_selectedObjects);
|
||||
_objectScaleGizmo.SetTargetObjects(_selectedObjects);
|
||||
_objectUniversalGizmo.SetTargetObjects(_selectedObjects);
|
||||
|
||||
// We initialize the work gizmo to the move gizmo by default. This means
|
||||
// that the first time an object is clicked, the move gizmo will appear.
|
||||
// You can change the default gizmo, by simply changing these 2 lines of
|
||||
// code. For example, if you wanted the scale gizmo to be the default work
|
||||
// gizmo, replace '_objectMoveGizmo' with '_objectScaleGizmo' and GizmoId.Move
|
||||
// with GizmoId.Scale.
|
||||
_workGizmo = _objectMoveGizmo;
|
||||
_workGizmoId = GizmoId.Move;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called every frame to perform all necessary updates. In this tutorial,
|
||||
/// we listen to user input and take action.
|
||||
/// </summary>
|
||||
private void Update()
|
||||
{
|
||||
// Check if the left mouse button was pressed in the current frame.
|
||||
// Note: Something that was left out of the video tutorial by mistake. We
|
||||
// only take the mouse click into account if no gizmo is currently
|
||||
// hovered. When a gizmo is hovered, we ignore clicks because in that
|
||||
// case a click usually represents the intent of clicking and dragging
|
||||
// the gizmo handles. If we didn't perform this check, clicking on a
|
||||
// gizmo might actually disable it instead if the click does not hover
|
||||
// a game object (i.e. thin air click).
|
||||
if (RTInput.WasLeftMouseButtonPressedThisFrame() &&
|
||||
RTGizmosEngine.Get.HoveredGizmo == null)
|
||||
{
|
||||
// Pick a game object
|
||||
GameObject pickedObject = PickGameObject();
|
||||
if (pickedObject != null)
|
||||
{
|
||||
// Is the CTRL key pressed?
|
||||
if (RTInput.IsKeyPressed(KeyCode.LeftControl))
|
||||
{
|
||||
// The CTRL key is pressed; it means we find ourselves in 2 possible situations:
|
||||
// a) the picked object is already selected, in which case we deselect it;
|
||||
// b) the picked object is not selected, in which case we append it to the selection.
|
||||
if (_selectedObjects.Contains(pickedObject)) _selectedObjects.Remove(pickedObject);
|
||||
else _selectedObjects.Add(pickedObject);
|
||||
|
||||
// The selection has changed
|
||||
OnSelectionChanged();
|
||||
}
|
||||
else
|
||||
{
|
||||
// The CTRL key is not pressed; in this case we just clear the selection and
|
||||
// select only the object that we clicked on.
|
||||
_selectedObjects.Clear();
|
||||
_selectedObjects.Add(pickedObject);
|
||||
|
||||
// The selection has changed
|
||||
OnSelectionChanged();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// If we reach this point, it means no object was picked. This means that we clicked
|
||||
// in thin air, so we just clear the selected objects list.
|
||||
_selectedObjects.Clear();
|
||||
OnSelectionChanged();
|
||||
|
||||
// The selection has changed
|
||||
OnSelectionChanged();
|
||||
}
|
||||
}
|
||||
|
||||
// If the G key was pressed, we change the transform space to Global. Otherwise,
|
||||
// if the L key was pressed, we change it to Local.
|
||||
if (RTInput.WasKeyPressedThisFrame(KeyCode.G)) SetTransformSpace(GizmoSpace.Global);
|
||||
else if (RTInput.WasKeyPressedThisFrame(KeyCode.L)) SetTransformSpace(GizmoSpace.Local);
|
||||
|
||||
// We will change the pivot type when the P key is pressed
|
||||
if (RTInput.WasKeyPressedThisFrame(KeyCode.P))
|
||||
{
|
||||
// Retrieve the current transform pivot and activate the other one instead.
|
||||
// Note: In order to retrieve the current transform pivot, it is enough to
|
||||
// use the 'TransformPivot' property of one of our gizmos. This works
|
||||
// because all gizmos use the same transform pivot in this example. We
|
||||
// make sure of that inside the 'SetTransformPivot' function.
|
||||
GizmoObjectTransformPivot currentPivot = _objectMoveGizmo.TransformPivot;
|
||||
if (currentPivot == GizmoObjectTransformPivot.ObjectGroupCenter) SetTransformPivot(GizmoObjectTransformPivot.ObjectMeshPivot);
|
||||
else SetTransformPivot(GizmoObjectTransformPivot.ObjectGroupCenter);
|
||||
}
|
||||
|
||||
// Switch between different gizmo types using the W,E,R,T keys.
|
||||
// Note: We use the 'SetWorkGizmoId' function to perform the switch.
|
||||
if (RTInput.WasKeyPressedThisFrame(KeyCode.W)) SetWorkGizmoId(GizmoId.Move);
|
||||
else if (RTInput.WasKeyPressedThisFrame(KeyCode.E)) SetWorkGizmoId(GizmoId.Rotate);
|
||||
else if (RTInput.WasKeyPressedThisFrame(KeyCode.R)) SetWorkGizmoId(GizmoId.Scale);
|
||||
else if (RTInput.WasKeyPressedThisFrame(KeyCode.T)) SetWorkGizmoId(GizmoId.Universal);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// An implementatio of the OnGUI function which shows the current transform
|
||||
/// space and transform pivot in the top left corner of the screen.
|
||||
/// </summary>
|
||||
private void OnGUI()
|
||||
{
|
||||
// We will use a style with a green text color
|
||||
var guiStyle = new GUIStyle();
|
||||
guiStyle.normal.textColor = Color.green;
|
||||
|
||||
// Draw the transform space label.
|
||||
// Note: In order to get access to the current transform space, we use the 'TransformSpace'
|
||||
// property of the move gizmo. Any gizmo would do because all of them use the same
|
||||
// transform space. We make sure of that inside the 'SetTransformSpace' function.
|
||||
GUILayout.Label("Transform Space: " + _objectMoveGizmo.TransformSpace.ToString(), guiStyle);
|
||||
|
||||
// Same for transform pivot
|
||||
GUILayout.Label("Transform Pivot: " + _objectMoveGizmo.TransformPivot.ToString(), guiStyle);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Uses the mouse position to pick a game object in the scene. Returns
|
||||
/// the picked game object or null if no object is picked.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Objects must have colliders attached.
|
||||
/// </remarks>
|
||||
private GameObject PickGameObject()
|
||||
{
|
||||
// Build a ray using the current mouse cursor position
|
||||
Ray ray = Camera.main.ScreenPointToRay(RTInput.MousePosition);
|
||||
|
||||
// Check if the ray intersects a game object. If it does, return it
|
||||
RaycastHit rayHit;
|
||||
if (Physics.Raycast(ray, out rayHit, float.MaxValue))
|
||||
return rayHit.collider.gameObject;
|
||||
|
||||
// No object is intersected by the ray. Return null.
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This function is called to change the type of work gizmo. This is
|
||||
/// used in the 'Update' function in response to the user pressing the
|
||||
/// W,E,R,T keys to switch between different gizmo types.
|
||||
/// </summary>
|
||||
private void SetWorkGizmoId(GizmoId gizmoId)
|
||||
{
|
||||
// If the specified gizmo id is the same as the current id, there is nothing left to do
|
||||
if (gizmoId == _workGizmoId) return;
|
||||
|
||||
// Start with a clean slate and disable all gizmos
|
||||
_objectMoveGizmo.Gizmo.SetEnabled(false);
|
||||
_objectRotationGizmo.Gizmo.SetEnabled(false);
|
||||
_objectScaleGizmo.Gizmo.SetEnabled(false);
|
||||
_objectUniversalGizmo.Gizmo.SetEnabled(false);
|
||||
|
||||
// At this point all gizmos are disabled. Now we need to check the gizmo id
|
||||
// and adjust the '_workGizmo' variable.
|
||||
_workGizmoId = gizmoId;
|
||||
if (gizmoId == GizmoId.Move) _workGizmo = _objectMoveGizmo;
|
||||
else if (gizmoId == GizmoId.Rotate) _workGizmo = _objectRotationGizmo;
|
||||
else if (gizmoId == GizmoId.Scale) _workGizmo = _objectScaleGizmo;
|
||||
else if (gizmoId == GizmoId.Universal) _workGizmo = _objectUniversalGizmo;
|
||||
|
||||
// If we have any selected objects, we need to make sure the work gizmo is enabled
|
||||
if (_selectedObjects.Count != 0)
|
||||
{
|
||||
// Make sure the work gizmo is enabled. There is no need to check if the gizmo is already
|
||||
// enabled. The 'SetEnabled' call will simply be ignored if that is the case.
|
||||
_workGizmo.Gizmo.SetEnabled(true);
|
||||
|
||||
// When working with transform spaces and pivots, the gizmos need to know about the pivot object.
|
||||
// This piece of information is necessary when the transform space is set to local because in that
|
||||
// case the gizmo will have its rotation synchronized with the target objects rotation. But because
|
||||
// there is more than one target object, we need to tell the gizmo which object to use. This is the
|
||||
// role if the pivot object in this case. This pivot object is also useful when the transform pivot
|
||||
// is set to 'ObjectMeshPivot' because it will be used to adjust the position of the gizmo.
|
||||
_workGizmo.SetTargetPivotObject(_selectedObjects[_selectedObjects.Count - 1]);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called from the 'Update' function whenever the '_selectedObjects' list
|
||||
/// changes. It is responsible for updating the gizmos accordingly.
|
||||
/// </summary>
|
||||
private void OnSelectionChanged()
|
||||
{
|
||||
// If we have any selected objects, we need to make sure the work gizmo is enabled
|
||||
if (_selectedObjects.Count != 0)
|
||||
{
|
||||
// Make sure the work gizmo is enabled. There is no need to check if the gizmo is already
|
||||
// enabled. The 'SetEnabled' call will simply be ignored if that is the case.
|
||||
_workGizmo.Gizmo.SetEnabled(true);
|
||||
|
||||
// When working with transform spaces and pivots, the gizmos need to know about the pivot object.
|
||||
// This piece of information is necessary when the transform space is set to local because in that
|
||||
// case the gizmo will have its rotation synchronized with the target objects rotation. But because
|
||||
// there is more than one target object, we need to tell the gizmo which object to use. This is the
|
||||
// role if the pivot object in this case. This pivot object is also useful when the transform pivot
|
||||
// is set to 'ObjectMeshPivot' because it will be used to adjust the position of the gizmo.
|
||||
_workGizmo.SetTargetPivotObject(_selectedObjects[_selectedObjects.Count - 1]);
|
||||
|
||||
// The last step we need to perform is to make sure that the work gizmo is positioned
|
||||
// and rotated correctly. This is because the gizmos (as will become more clear in
|
||||
// later tutorials) have 2 properties such as transform space and transform pivot and
|
||||
// when the selected objects change, these 2 properties will dictate how the gizmo should
|
||||
// be positioned and rotated. In order to ensure that the correct position and rotation
|
||||
// are used, we need to call 'RefreshPositionAndRotation'.
|
||||
_workGizmo.RefreshPositionAndRotation();
|
||||
}
|
||||
else
|
||||
{
|
||||
// The target object is null. In this case, we don't want any gizmos to be visible
|
||||
// in the scene, so we disable all of them.
|
||||
_objectMoveGizmo.Gizmo.SetEnabled(false);
|
||||
_objectRotationGizmo.Gizmo.SetEnabled(false);
|
||||
_objectScaleGizmo.Gizmo.SetEnabled(false);
|
||||
_objectUniversalGizmo.Gizmo.SetEnabled(false);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called from the 'Update' function in response to user input in order
|
||||
/// to change the transform space for all gizmos. The parameter represents
|
||||
/// the desired transform space and is of type 'GizmoSpace'. This is an enum
|
||||
/// with 2 mamebers: Global and Local.
|
||||
/// </summary>
|
||||
private void SetTransformSpace(GizmoSpace transformSpace)
|
||||
{
|
||||
// In order to change the transform space for a gizmo, we need to call the
|
||||
// gizmo's 'SetTransformSpace' function. We do this for all gizmos and pass
|
||||
// the specified transform space as parameter.
|
||||
_objectMoveGizmo.SetTransformSpace(transformSpace);
|
||||
_objectRotationGizmo.SetTransformSpace(transformSpace);
|
||||
_objectScaleGizmo.SetTransformSpace(transformSpace);
|
||||
_objectUniversalGizmo.SetTransformSpace(transformSpace);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called from the 'Update' function in response to user input in order
|
||||
/// to change the transform pivot for all gizmos. The parameter represents
|
||||
/// the desired transform pivot and is of type 'GizmoObjectTransformPivot'.
|
||||
/// </summary>
|
||||
private void SetTransformPivot(GizmoObjectTransformPivot transformPivot)
|
||||
{
|
||||
_objectMoveGizmo.SetTransformPivot(transformPivot);
|
||||
_objectRotationGizmo.SetTransformPivot(transformPivot);
|
||||
_objectScaleGizmo.SetTransformPivot(transformPivot);
|
||||
_objectUniversalGizmo.SetTransformPivot(transformPivot);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 115707a42cb77374fa56f350a933ee2f
|
||||
timeCreated: 1534160799
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,327 @@
|
||||
using UnityEngine;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace RTG
|
||||
{
|
||||
/// <summary>
|
||||
/// The main focus in this tutorial is to learn how to use the
|
||||
/// 'CustomObjectLocalPivot' pivot type.
|
||||
/// </summary>
|
||||
public class Tut_5_CustomObjectLocalPivot : MonoBehaviour
|
||||
{
|
||||
/// <summary>
|
||||
/// A private enum which is used by the class to differentiate between different
|
||||
/// gizmo types. An example where this enum will come in handy is when we use the
|
||||
/// W,E,R,T keys to switch between different types of gizmos. When the W key is
|
||||
/// pressed for example, we will call the 'SetWorkGizmoId' function passing
|
||||
/// GizmoId.Move as the parameter.
|
||||
/// </summary>
|
||||
private enum GizmoId
|
||||
{
|
||||
Move = 1,
|
||||
Rotate,
|
||||
Scale,
|
||||
Universal
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The following 4 variables are references to the ObjectTransformGizmo behaviours
|
||||
/// that will be used to move, rotate and scale our objects.
|
||||
/// </summary>
|
||||
private ObjectTransformGizmo _objectMoveGizmo;
|
||||
private ObjectTransformGizmo _objectRotationGizmo;
|
||||
private ObjectTransformGizmo _objectScaleGizmo;
|
||||
private ObjectTransformGizmo _objectUniversalGizmo;
|
||||
|
||||
/// <summary>
|
||||
/// The current work gizmo id. The work gizmo is the gizmo which is currently used
|
||||
/// to transform objects. The W,E,R,T keys can be used to change the work gizmo as
|
||||
/// needed.
|
||||
/// </summary>
|
||||
private GizmoId _workGizmoId;
|
||||
/// <summary>
|
||||
/// A reference to the current work gizmo. If the work gizmo id is GizmoId.Move, then
|
||||
/// this will point to '_objectMoveGizmo'. For GizmoId.Rotate, it will point to
|
||||
/// '_objectRotationGizmo' and so on.
|
||||
/// </summary>
|
||||
private ObjectTransformGizmo _workGizmo;
|
||||
/// <summary>
|
||||
/// A list of objects which are currently selected. This is also the list that holds
|
||||
/// the gizmo target objects.
|
||||
/// </summary>
|
||||
private List<GameObject> _selectedObjects = new List<GameObject>();
|
||||
|
||||
/// <summary>
|
||||
/// Performs all necessary initializations.
|
||||
/// </summary>
|
||||
private void Start()
|
||||
{
|
||||
// Create the 4 gizmos
|
||||
_objectMoveGizmo = RTGizmosEngine.Get.CreateObjectMoveGizmo();
|
||||
_objectRotationGizmo = RTGizmosEngine.Get.CreateObjectRotationGizmo();
|
||||
_objectScaleGizmo = RTGizmosEngine.Get.CreateObjectScaleGizmo();
|
||||
_objectUniversalGizmo = RTGizmosEngine.Get.CreateObjectUniversalGizmo();
|
||||
|
||||
// Call the 'SetEnabled' function on the parent gizmo to make sure
|
||||
// the gizmos are initially hidden in the scene. We want the gizmo
|
||||
// to show only when we have a target object available.
|
||||
_objectMoveGizmo.Gizmo.SetEnabled(false);
|
||||
_objectRotationGizmo.Gizmo.SetEnabled(false);
|
||||
_objectScaleGizmo.Gizmo.SetEnabled(false);
|
||||
_objectUniversalGizmo.Gizmo.SetEnabled(false);
|
||||
|
||||
// Link the selected objects list to the gizmos
|
||||
// Note: The 'SetTargetObjects' function will instruct the gizmo to store
|
||||
// a direct reference to the '_selecteObjects' list. This means that
|
||||
// when you add or remove objects from this list, the gizmos will have
|
||||
// access to the most recent/updated collection. You don't need to call
|
||||
// 'SetTargetObjects' again when the list changes.
|
||||
_objectMoveGizmo.SetTargetObjects(_selectedObjects);
|
||||
_objectRotationGizmo.SetTargetObjects(_selectedObjects);
|
||||
_objectScaleGizmo.SetTargetObjects(_selectedObjects);
|
||||
_objectUniversalGizmo.SetTargetObjects(_selectedObjects);
|
||||
|
||||
// We initialize the work gizmo to the move gizmo by default. This means
|
||||
// that the first time an object is clicked, the move gizmo will appear.
|
||||
// You can change the default gizmo, by simply changing these 2 lines of
|
||||
// code. For example, if you wanted the scale gizmo to be the default work
|
||||
// gizmo, replace '_objectMoveGizmo' with '_objectScaleGizmo' and GizmoId.Move
|
||||
// with GizmoId.Scale.
|
||||
_workGizmo = _objectMoveGizmo;
|
||||
_workGizmoId = GizmoId.Move;
|
||||
|
||||
// <BEGIN TUTORIAL>
|
||||
// Get a reference to the object whose pivot we want to modify
|
||||
GameObject doorObject = GameObject.Find("GreenCube");
|
||||
|
||||
// Calculate the object's world OBB and then use the 'BoxMath.CalcBoxFaceCenter'
|
||||
// to calculate the center of the object's left face in world space. We will use
|
||||
// this face center as our pivot.
|
||||
OBB worldOBB = ObjectBounds.GetMeshWorldOBB(doorObject);
|
||||
Vector3 faceCenter = BoxMath.CalcBoxFaceCenter(worldOBB.Center, worldOBB.Size, worldOBB.Rotation, BoxFace.Left);
|
||||
|
||||
// Use the 'SetObjectCustomLocalPivot' function to specify the object's pivot.
|
||||
// Note: We need to call 'InverseTransformPoint' on the face center because the function expects
|
||||
// a pivot point expressed in the object's local coordinate system.
|
||||
_objectRotationGizmo.SetObjectCustomLocalPivot(doorObject, doorObject.transform.InverseTransformPoint(faceCenter));
|
||||
|
||||
// Change the transform pivot to 'CustomObjectLocalPivot'
|
||||
_objectRotationGizmo.SetTransformPivot(GizmoObjectTransformPivot.CustomObjectLocalPivot);
|
||||
// <END TUTORIAL>
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called every frame to perform all necessary updates. In this tutorial,
|
||||
/// we listen to user input and take action.
|
||||
/// </summary>
|
||||
private void Update()
|
||||
{
|
||||
// Check if the left mouse button was pressed in the current frame.
|
||||
// Note: Something that was left out of the video tutorial by mistake. We
|
||||
// only take the mouse click into account if no gizmo is currently
|
||||
// hovered. When a gizmo is hovered, we ignore clicks because in that
|
||||
// case a click usually represents the intent of clicking and dragging
|
||||
// the gizmo handles. If we didn't perform this check, clicking on a
|
||||
// gizmo might actually disable it instead if the click does not hover
|
||||
// a game object (i.e. thin air click).
|
||||
if (RTInput.WasLeftMouseButtonPressedThisFrame() &&
|
||||
RTGizmosEngine.Get.HoveredGizmo == null)
|
||||
{
|
||||
// Pick a game object
|
||||
GameObject pickedObject = PickGameObject();
|
||||
if (pickedObject != null)
|
||||
{
|
||||
// Is the CTRL key pressed?
|
||||
if (RTInput.IsKeyPressed(KeyCode.LeftControl))
|
||||
{
|
||||
// The CTRL key is pressed; it means we find ourselves in 2 possible situations:
|
||||
// a) the picked object is already selected, in which case we deselect it;
|
||||
// b) the picked object is not selected, in which case we append it to the selection.
|
||||
if (_selectedObjects.Contains(pickedObject)) _selectedObjects.Remove(pickedObject);
|
||||
else _selectedObjects.Add(pickedObject);
|
||||
|
||||
// The selection has changed
|
||||
OnSelectionChanged();
|
||||
}
|
||||
else
|
||||
{
|
||||
// The CTRL key is not pressed; in this case we just clear the selection and
|
||||
// select only the object that we clicked on.
|
||||
_selectedObjects.Clear();
|
||||
_selectedObjects.Add(pickedObject);
|
||||
|
||||
// The selection has changed
|
||||
OnSelectionChanged();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// If we reach this point, it means no object was picked. This means that we clicked
|
||||
// in thin air, so we just clear the selected objects list.
|
||||
_selectedObjects.Clear();
|
||||
OnSelectionChanged();
|
||||
|
||||
// The selection has changed
|
||||
OnSelectionChanged();
|
||||
}
|
||||
}
|
||||
|
||||
// If the G key was pressed, we change the transform space to Global. Otherwise,
|
||||
// if the L key was pressed, we change it to Local.
|
||||
if (RTInput.WasKeyPressedThisFrame(KeyCode.G)) SetTransformSpace(GizmoSpace.Global);
|
||||
else if (RTInput.WasKeyPressedThisFrame(KeyCode.L)) SetTransformSpace(GizmoSpace.Local);
|
||||
|
||||
// We will change the pivot type when the P key is pressed
|
||||
if (RTInput.WasKeyPressedThisFrame(KeyCode.P))
|
||||
{
|
||||
// Retrieve the current transform pivot and activate the other one instead.
|
||||
// Note: In order to retrieve the current transform pivot, it is enough to
|
||||
// use the 'TransformPivot' property of one of our gizmos. This works
|
||||
// because all gizmos use the same transform pivot in this example. We
|
||||
// make sure of that inside the 'SetTransformPivot' function.
|
||||
GizmoObjectTransformPivot currentPivot = _objectMoveGizmo.TransformPivot;
|
||||
if (currentPivot == GizmoObjectTransformPivot.ObjectGroupCenter) SetTransformPivot(GizmoObjectTransformPivot.ObjectMeshPivot);
|
||||
else SetTransformPivot(GizmoObjectTransformPivot.ObjectGroupCenter);
|
||||
}
|
||||
|
||||
// Switch between different gizmo types using the W,E,R,T keys.
|
||||
// Note: We use the 'SetWorkGizmoId' function to perform the switch.
|
||||
if (RTInput.WasKeyPressedThisFrame(KeyCode.W)) SetWorkGizmoId(GizmoId.Move);
|
||||
else if (RTInput.WasKeyPressedThisFrame(KeyCode.E)) SetWorkGizmoId(GizmoId.Rotate);
|
||||
else if (RTInput.WasKeyPressedThisFrame(KeyCode.R)) SetWorkGizmoId(GizmoId.Scale);
|
||||
else if (RTInput.WasKeyPressedThisFrame(KeyCode.T)) SetWorkGizmoId(GizmoId.Universal);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Uses the mouse position to pick a game object in the scene. Returns
|
||||
/// the picked game object or null if no object is picked.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Objects must have colliders attached.
|
||||
/// </remarks>
|
||||
private GameObject PickGameObject()
|
||||
{
|
||||
// Build a ray using the current mouse cursor position
|
||||
Ray ray = Camera.main.ScreenPointToRay(RTInput.MousePosition);
|
||||
|
||||
// Check if the ray intersects a game object. If it does, return it
|
||||
RaycastHit rayHit;
|
||||
if (Physics.Raycast(ray, out rayHit, float.MaxValue))
|
||||
return rayHit.collider.gameObject;
|
||||
|
||||
// No object is intersected by the ray. Return null.
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This function is called to change the type of work gizmo. This is
|
||||
/// used in the 'Update' function in response to the user pressing the
|
||||
/// W,E,R,T keys to switch between different gizmo types.
|
||||
/// </summary>
|
||||
private void SetWorkGizmoId(GizmoId gizmoId)
|
||||
{
|
||||
// If the specified gizmo id is the same as the current id, there is nothing left to do
|
||||
if (gizmoId == _workGizmoId) return;
|
||||
|
||||
// Start with a clean slate and disable all gizmos
|
||||
_objectMoveGizmo.Gizmo.SetEnabled(false);
|
||||
_objectRotationGizmo.Gizmo.SetEnabled(false);
|
||||
_objectScaleGizmo.Gizmo.SetEnabled(false);
|
||||
_objectUniversalGizmo.Gizmo.SetEnabled(false);
|
||||
|
||||
// At this point all gizmos are disabled. Now we need to check the gizmo id
|
||||
// and adjust the '_workGizmo' variable.
|
||||
_workGizmoId = gizmoId;
|
||||
if (gizmoId == GizmoId.Move) _workGizmo = _objectMoveGizmo;
|
||||
else if (gizmoId == GizmoId.Rotate) _workGizmo = _objectRotationGizmo;
|
||||
else if (gizmoId == GizmoId.Scale) _workGizmo = _objectScaleGizmo;
|
||||
else if (gizmoId == GizmoId.Universal) _workGizmo = _objectUniversalGizmo;
|
||||
|
||||
// If we have any selected objects, we need to make sure the work gizmo is enabled
|
||||
if (_selectedObjects.Count != 0)
|
||||
{
|
||||
// Make sure the work gizmo is enabled. There is no need to check if the gizmo is already
|
||||
// enabled. The 'SetEnabled' call will simply be ignored if that is the case.
|
||||
_workGizmo.Gizmo.SetEnabled(true);
|
||||
|
||||
// When working with transform spaces and pivots, the gizmos need to know about the pivot object.
|
||||
// This piece of information is necessary when the transform space is set to local because in that
|
||||
// case the gizmo will have its rotation synchronized with the target objects rotation. But because
|
||||
// there is more than one target object, we need to tell the gizmo which object to use. This is the
|
||||
// role if the pivot object in this case. This pivot object is also useful when the transform pivot
|
||||
// is set to 'ObjectMeshPivot' because it will be used to adjust the position of the gizmo.
|
||||
_workGizmo.SetTargetPivotObject(_selectedObjects[_selectedObjects.Count - 1]);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called from the 'Update' function whenever the '_selectedObjects' list
|
||||
/// changes. It is responsible for updating the gizmos accordingly.
|
||||
/// </summary>
|
||||
private void OnSelectionChanged()
|
||||
{
|
||||
// If we have any selected objects, we need to make sure the work gizmo is enabled
|
||||
if (_selectedObjects.Count != 0)
|
||||
{
|
||||
// Make sure the work gizmo is enabled. There is no need to check if the gizmo is already
|
||||
// enabled. The 'SetEnabled' call will simply be ignored if that is the case.
|
||||
_workGizmo.Gizmo.SetEnabled(true);
|
||||
|
||||
// When working with transform spaces and pivots, the gizmos need to know about the pivot object.
|
||||
// This piece of information is necessary when the transform space is set to local because in that
|
||||
// case the gizmo will have its rotation synchronized with the target objects rotation. But because
|
||||
// there is more than one target object, we need to tell the gizmo which object to use. This is the
|
||||
// role if the pivot object in this case. This pivot object is also useful when the transform pivot
|
||||
// is set to 'ObjectMeshPivot' because it will be used to adjust the position of the gizmo.
|
||||
_workGizmo.SetTargetPivotObject(_selectedObjects[_selectedObjects.Count - 1]);
|
||||
|
||||
// The last step we need to perform is to make sure that the work gizmo is positioned
|
||||
// and rotated correctly. This is because the gizmos (as will become more clear in
|
||||
// later tutorials) have 2 properties such as transform space and transform pivot and
|
||||
// when the selected objects change, these 2 properties will dictate how the gizmo should
|
||||
// be positioned and rotated. In order to ensure that the correct position and rotation
|
||||
// are used, we need to call 'RefreshPositionAndRotation'.
|
||||
_workGizmo.RefreshPositionAndRotation();
|
||||
}
|
||||
else
|
||||
{
|
||||
// The target object is null. In this case, we don't want any gizmos to be visible
|
||||
// in the scene, so we disable all of them.
|
||||
_objectMoveGizmo.Gizmo.SetEnabled(false);
|
||||
_objectRotationGizmo.Gizmo.SetEnabled(false);
|
||||
_objectScaleGizmo.Gizmo.SetEnabled(false);
|
||||
_objectUniversalGizmo.Gizmo.SetEnabled(false);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called from the 'Update' function in response to user input in order
|
||||
/// to change the transform space for all gizmos. The parameter represents
|
||||
/// the desired transform space and is of type 'GizmoSpace'. This is an enum
|
||||
/// with 2 mamebers: Global and Local.
|
||||
/// </summary>
|
||||
private void SetTransformSpace(GizmoSpace transformSpace)
|
||||
{
|
||||
// In order to change the transform space for a gizmo, we need to call the
|
||||
// gizmo's 'SetTransformSpace' function. We do this for all gizmos and pass
|
||||
// the specified transform space as parameter.
|
||||
_objectMoveGizmo.SetTransformSpace(transformSpace);
|
||||
_objectRotationGizmo.SetTransformSpace(transformSpace);
|
||||
_objectScaleGizmo.SetTransformSpace(transformSpace);
|
||||
_objectUniversalGizmo.SetTransformSpace(transformSpace);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called from the 'Update' function in response to user input in order
|
||||
/// to change the transform pivot for all gizmos. The parameter represents
|
||||
/// the desired transform pivot and is of type 'GizmoObjectTransformPivot'.
|
||||
/// </summary>
|
||||
private void SetTransformPivot(GizmoObjectTransformPivot transformPivot)
|
||||
{
|
||||
_objectMoveGizmo.SetTransformPivot(transformPivot);
|
||||
_objectRotationGizmo.SetTransformPivot(transformPivot);
|
||||
_objectScaleGizmo.SetTransformPivot(transformPivot);
|
||||
_objectUniversalGizmo.SetTransformPivot(transformPivot);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 575ac03eff2544145b33f2f5406210bd
|
||||
timeCreated: 1534160799
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 292f29c32234efc468a86c374c46d2bb
|
||||
timeCreated: 1533991480
|
||||
licenseType: Store
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,317 @@
|
||||
using UnityEngine;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace RTG
|
||||
{
|
||||
/// <summary>
|
||||
/// The main focus in this tutorial is to learn how to use the
|
||||
/// 'CustomWorldPivot' pivot type.
|
||||
/// </summary>
|
||||
public class Tut_6_CustomWorldPivot : MonoBehaviour
|
||||
{
|
||||
/// <summary>
|
||||
/// A private enum which is used by the class to differentiate between different
|
||||
/// gizmo types. An example where this enum will come in handy is when we use the
|
||||
/// W,E,R,T keys to switch between different types of gizmos. When the W key is
|
||||
/// pressed for example, we will call the 'SetWorkGizmoId' function passing
|
||||
/// GizmoId.Move as the parameter.
|
||||
/// </summary>
|
||||
private enum GizmoId
|
||||
{
|
||||
Move = 1,
|
||||
Rotate,
|
||||
Scale,
|
||||
Universal
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The following 4 variables are references to the ObjectTransformGizmo behaviours
|
||||
/// that will be used to move, rotate and scale our objects.
|
||||
/// </summary>
|
||||
private ObjectTransformGizmo _objectMoveGizmo;
|
||||
private ObjectTransformGizmo _objectRotationGizmo;
|
||||
private ObjectTransformGizmo _objectScaleGizmo;
|
||||
private ObjectTransformGizmo _objectUniversalGizmo;
|
||||
|
||||
/// <summary>
|
||||
/// The current work gizmo id. The work gizmo is the gizmo which is currently used
|
||||
/// to transform objects. The W,E,R,T keys can be used to change the work gizmo as
|
||||
/// needed.
|
||||
/// </summary>
|
||||
private GizmoId _workGizmoId;
|
||||
/// <summary>
|
||||
/// A reference to the current work gizmo. If the work gizmo id is GizmoId.Move, then
|
||||
/// this will point to '_objectMoveGizmo'. For GizmoId.Rotate, it will point to
|
||||
/// '_objectRotationGizmo' and so on.
|
||||
/// </summary>
|
||||
private ObjectTransformGizmo _workGizmo;
|
||||
/// <summary>
|
||||
/// A list of objects which are currently selected. This is also the list that holds
|
||||
/// the gizmo target objects.
|
||||
/// </summary>
|
||||
private List<GameObject> _selectedObjects = new List<GameObject>();
|
||||
|
||||
/// <summary>
|
||||
/// Performs all necessary initializations.
|
||||
/// </summary>
|
||||
private void Start()
|
||||
{
|
||||
// Create the 4 gizmos
|
||||
_objectMoveGizmo = RTGizmosEngine.Get.CreateObjectMoveGizmo();
|
||||
_objectRotationGizmo = RTGizmosEngine.Get.CreateObjectRotationGizmo();
|
||||
_objectScaleGizmo = RTGizmosEngine.Get.CreateObjectScaleGizmo();
|
||||
_objectUniversalGizmo = RTGizmosEngine.Get.CreateObjectUniversalGizmo();
|
||||
|
||||
// Call the 'SetEnabled' function on the parent gizmo to make sure
|
||||
// the gizmos are initially hidden in the scene. We want the gizmo
|
||||
// to show only when we have a target object available.
|
||||
_objectMoveGizmo.Gizmo.SetEnabled(false);
|
||||
_objectRotationGizmo.Gizmo.SetEnabled(false);
|
||||
_objectScaleGizmo.Gizmo.SetEnabled(false);
|
||||
_objectUniversalGizmo.Gizmo.SetEnabled(false);
|
||||
|
||||
// Link the selected objects list to the gizmos
|
||||
// Note: The 'SetTargetObjects' function will instruct the gizmo to store
|
||||
// a direct reference to the '_selecteObjects' list. This means that
|
||||
// when you add or remove objects from this list, the gizmos will have
|
||||
// access to the most recent/updated collection. You don't need to call
|
||||
// 'SetTargetObjects' again when the list changes.
|
||||
_objectMoveGizmo.SetTargetObjects(_selectedObjects);
|
||||
_objectRotationGizmo.SetTargetObjects(_selectedObjects);
|
||||
_objectScaleGizmo.SetTargetObjects(_selectedObjects);
|
||||
_objectUniversalGizmo.SetTargetObjects(_selectedObjects);
|
||||
|
||||
// We initialize the work gizmo to the move gizmo by default. This means
|
||||
// that the first time an object is clicked, the move gizmo will appear.
|
||||
// You can change the default gizmo, by simply changing these 2 lines of
|
||||
// code. For example, if you wanted the scale gizmo to be the default work
|
||||
// gizmo, replace '_objectMoveGizmo' with '_objectScaleGizmo' and GizmoId.Move
|
||||
// with GizmoId.Scale.
|
||||
_workGizmo = _objectMoveGizmo;
|
||||
_workGizmoId = GizmoId.Move;
|
||||
|
||||
// <BEGIN TUTORIAL>
|
||||
// Get a reference to the object whose position we will use as the world pivot
|
||||
GameObject pivotObject = GameObject.Find("Sphere");
|
||||
|
||||
// Set the world pivot
|
||||
_objectRotationGizmo.SetCustomWorldPivot(pivotObject.transform.position);
|
||||
_objectRotationGizmo.SetTransformPivot(GizmoObjectTransformPivot.CustomWorldPivot);
|
||||
// <END TUTORIAL>
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called every frame to perform all necessary updates. In this tutorial,
|
||||
/// we listen to user input and take action.
|
||||
/// </summary>
|
||||
private void Update()
|
||||
{
|
||||
// Check if the left mouse button was pressed in the current frame.
|
||||
// Note: Something that was left out of the video tutorial by mistake. We
|
||||
// only take the mouse click into account if no gizmo is currently
|
||||
// hovered. When a gizmo is hovered, we ignore clicks because in that
|
||||
// case a click usually represents the intent of clicking and dragging
|
||||
// the gizmo handles. If we didn't perform this check, clicking on a
|
||||
// gizmo might actually disable it instead if the click does not hover
|
||||
// a game object (i.e. thin air click).
|
||||
if (RTInput.WasLeftMouseButtonPressedThisFrame() &&
|
||||
RTGizmosEngine.Get.HoveredGizmo == null)
|
||||
{
|
||||
// Pick a game object
|
||||
GameObject pickedObject = PickGameObject();
|
||||
if (pickedObject != null)
|
||||
{
|
||||
// Is the CTRL key pressed?
|
||||
if (RTInput.IsKeyPressed(KeyCode.LeftControl))
|
||||
{
|
||||
// The CTRL key is pressed; it means we find ourselves in 2 possible situations:
|
||||
// a) the picked object is already selected, in which case we deselect it;
|
||||
// b) the picked object is not selected, in which case we append it to the selection.
|
||||
if (_selectedObjects.Contains(pickedObject)) _selectedObjects.Remove(pickedObject);
|
||||
else _selectedObjects.Add(pickedObject);
|
||||
|
||||
// The selection has changed
|
||||
OnSelectionChanged();
|
||||
}
|
||||
else
|
||||
{
|
||||
// The CTRL key is not pressed; in this case we just clear the selection and
|
||||
// select only the object that we clicked on.
|
||||
_selectedObjects.Clear();
|
||||
_selectedObjects.Add(pickedObject);
|
||||
|
||||
// The selection has changed
|
||||
OnSelectionChanged();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// If we reach this point, it means no object was picked. This means that we clicked
|
||||
// in thin air, so we just clear the selected objects list.
|
||||
_selectedObjects.Clear();
|
||||
OnSelectionChanged();
|
||||
|
||||
// The selection has changed
|
||||
OnSelectionChanged();
|
||||
}
|
||||
}
|
||||
|
||||
// If the G key was pressed, we change the transform space to Global. Otherwise,
|
||||
// if the L key was pressed, we change it to Local.
|
||||
if (RTInput.WasKeyPressedThisFrame(KeyCode.G)) SetTransformSpace(GizmoSpace.Global);
|
||||
else if (RTInput.WasKeyPressedThisFrame(KeyCode.L)) SetTransformSpace(GizmoSpace.Local);
|
||||
|
||||
// We will change the pivot type when the P key is pressed
|
||||
if (RTInput.WasKeyPressedThisFrame(KeyCode.P))
|
||||
{
|
||||
// Retrieve the current transform pivot and activate the other one instead.
|
||||
// Note: In order to retrieve the current transform pivot, it is enough to
|
||||
// use the 'TransformPivot' property of one of our gizmos. This works
|
||||
// because all gizmos use the same transform pivot in this example. We
|
||||
// make sure of that inside the 'SetTransformPivot' function.
|
||||
GizmoObjectTransformPivot currentPivot = _objectMoveGizmo.TransformPivot;
|
||||
if (currentPivot == GizmoObjectTransformPivot.ObjectGroupCenter) SetTransformPivot(GizmoObjectTransformPivot.ObjectMeshPivot);
|
||||
else SetTransformPivot(GizmoObjectTransformPivot.ObjectGroupCenter);
|
||||
}
|
||||
|
||||
// Switch between different gizmo types using the W,E,R,T keys.
|
||||
// Note: We use the 'SetWorkGizmoId' function to perform the switch.
|
||||
if (RTInput.WasKeyPressedThisFrame(KeyCode.W)) SetWorkGizmoId(GizmoId.Move);
|
||||
else if (RTInput.WasKeyPressedThisFrame(KeyCode.E)) SetWorkGizmoId(GizmoId.Rotate);
|
||||
else if (RTInput.WasKeyPressedThisFrame(KeyCode.R)) SetWorkGizmoId(GizmoId.Scale);
|
||||
else if (RTInput.WasKeyPressedThisFrame(KeyCode.T)) SetWorkGizmoId(GizmoId.Universal);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Uses the mouse position to pick a game object in the scene. Returns
|
||||
/// the picked game object or null if no object is picked.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Objects must have colliders attached.
|
||||
/// </remarks>
|
||||
private GameObject PickGameObject()
|
||||
{
|
||||
// Build a ray using the current mouse cursor position
|
||||
Ray ray = Camera.main.ScreenPointToRay(RTInput.MousePosition);
|
||||
|
||||
// Check if the ray intersects a game object. If it does, return it
|
||||
RaycastHit rayHit;
|
||||
if (Physics.Raycast(ray, out rayHit, float.MaxValue))
|
||||
return rayHit.collider.gameObject;
|
||||
|
||||
// No object is intersected by the ray. Return null.
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This function is called to change the type of work gizmo. This is
|
||||
/// used in the 'Update' function in response to the user pressing the
|
||||
/// W,E,R,T keys to switch between different gizmo types.
|
||||
/// </summary>
|
||||
private void SetWorkGizmoId(GizmoId gizmoId)
|
||||
{
|
||||
// If the specified gizmo id is the same as the current id, there is nothing left to do
|
||||
if (gizmoId == _workGizmoId) return;
|
||||
|
||||
// Start with a clean slate and disable all gizmos
|
||||
_objectMoveGizmo.Gizmo.SetEnabled(false);
|
||||
_objectRotationGizmo.Gizmo.SetEnabled(false);
|
||||
_objectScaleGizmo.Gizmo.SetEnabled(false);
|
||||
_objectUniversalGizmo.Gizmo.SetEnabled(false);
|
||||
|
||||
// At this point all gizmos are disabled. Now we need to check the gizmo id
|
||||
// and adjust the '_workGizmo' variable.
|
||||
_workGizmoId = gizmoId;
|
||||
if (gizmoId == GizmoId.Move) _workGizmo = _objectMoveGizmo;
|
||||
else if (gizmoId == GizmoId.Rotate) _workGizmo = _objectRotationGizmo;
|
||||
else if (gizmoId == GizmoId.Scale) _workGizmo = _objectScaleGizmo;
|
||||
else if (gizmoId == GizmoId.Universal) _workGizmo = _objectUniversalGizmo;
|
||||
|
||||
// If we have any selected objects, we need to make sure the work gizmo is enabled
|
||||
if (_selectedObjects.Count != 0)
|
||||
{
|
||||
// Make sure the work gizmo is enabled. There is no need to check if the gizmo is already
|
||||
// enabled. The 'SetEnabled' call will simply be ignored if that is the case.
|
||||
_workGizmo.Gizmo.SetEnabled(true);
|
||||
|
||||
// When working with transform spaces and pivots, the gizmos need to know about the pivot object.
|
||||
// This piece of information is necessary when the transform space is set to local because in that
|
||||
// case the gizmo will have its rotation synchronized with the target objects rotation. But because
|
||||
// there is more than one target object, we need to tell the gizmo which object to use. This is the
|
||||
// role if the pivot object in this case. This pivot object is also useful when the transform pivot
|
||||
// is set to 'ObjectMeshPivot' because it will be used to adjust the position of the gizmo.
|
||||
_workGizmo.SetTargetPivotObject(_selectedObjects[_selectedObjects.Count - 1]);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called from the 'Update' function whenever the '_selectedObjects' list
|
||||
/// changes. It is responsible for updating the gizmos accordingly.
|
||||
/// </summary>
|
||||
private void OnSelectionChanged()
|
||||
{
|
||||
// If we have any selected objects, we need to make sure the work gizmo is enabled
|
||||
if (_selectedObjects.Count != 0)
|
||||
{
|
||||
// Make sure the work gizmo is enabled. There is no need to check if the gizmo is already
|
||||
// enabled. The 'SetEnabled' call will simply be ignored if that is the case.
|
||||
_workGizmo.Gizmo.SetEnabled(true);
|
||||
|
||||
// When working with transform spaces and pivots, the gizmos need to know about the pivot object.
|
||||
// This piece of information is necessary when the transform space is set to local because in that
|
||||
// case the gizmo will have its rotation synchronized with the target objects rotation. But because
|
||||
// there is more than one target object, we need to tell the gizmo which object to use. This is the
|
||||
// role if the pivot object in this case. This pivot object is also useful when the transform pivot
|
||||
// is set to 'ObjectMeshPivot' because it will be used to adjust the position of the gizmo.
|
||||
_workGizmo.SetTargetPivotObject(_selectedObjects[_selectedObjects.Count - 1]);
|
||||
|
||||
// The last step we need to perform is to make sure that the work gizmo is positioned
|
||||
// and rotated correctly. This is because the gizmos (as will become more clear in
|
||||
// later tutorials) have 2 properties such as transform space and transform pivot and
|
||||
// when the selected objects change, these 2 properties will dictate how the gizmo should
|
||||
// be positioned and rotated. In order to ensure that the correct position and rotation
|
||||
// are used, we need to call 'RefreshPositionAndRotation'.
|
||||
_workGizmo.RefreshPositionAndRotation();
|
||||
}
|
||||
else
|
||||
{
|
||||
// The target object is null. In this case, we don't want any gizmos to be visible
|
||||
// in the scene, so we disable all of them.
|
||||
_objectMoveGizmo.Gizmo.SetEnabled(false);
|
||||
_objectRotationGizmo.Gizmo.SetEnabled(false);
|
||||
_objectScaleGizmo.Gizmo.SetEnabled(false);
|
||||
_objectUniversalGizmo.Gizmo.SetEnabled(false);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called from the 'Update' function in response to user input in order
|
||||
/// to change the transform space for all gizmos. The parameter represents
|
||||
/// the desired transform space and is of type 'GizmoSpace'. This is an enum
|
||||
/// with 2 mamebers: Global and Local.
|
||||
/// </summary>
|
||||
private void SetTransformSpace(GizmoSpace transformSpace)
|
||||
{
|
||||
// In order to change the transform space for a gizmo, we need to call the
|
||||
// gizmo's 'SetTransformSpace' function. We do this for all gizmos and pass
|
||||
// the specified transform space as parameter.
|
||||
_objectMoveGizmo.SetTransformSpace(transformSpace);
|
||||
_objectRotationGizmo.SetTransformSpace(transformSpace);
|
||||
_objectScaleGizmo.SetTransformSpace(transformSpace);
|
||||
_objectUniversalGizmo.SetTransformSpace(transformSpace);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called from the 'Update' function in response to user input in order
|
||||
/// to change the transform pivot for all gizmos. The parameter represents
|
||||
/// the desired transform pivot and is of type 'GizmoObjectTransformPivot'.
|
||||
/// </summary>
|
||||
private void SetTransformPivot(GizmoObjectTransformPivot transformPivot)
|
||||
{
|
||||
_objectMoveGizmo.SetTransformPivot(transformPivot);
|
||||
_objectRotationGizmo.SetTransformPivot(transformPivot);
|
||||
_objectScaleGizmo.SetTransformPivot(transformPivot);
|
||||
_objectUniversalGizmo.SetTransformPivot(transformPivot);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: aec42f65249edfa4fbf97af77d495224
|
||||
timeCreated: 1534160799
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 05e5a1a5b2c34354b955a874c8953ca5
|
||||
timeCreated: 1533991480
|
||||
licenseType: Store
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
9
Assets/Runtime Transform Gizmos/Scripts.meta
Normal file
9
Assets/Runtime Transform Gizmos/Scripts.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5d7e2e448569c554f9d6fe9d8fea289c
|
||||
folderAsset: yes
|
||||
timeCreated: 1485353502
|
||||
licenseType: Store
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
9
Assets/Runtime Transform Gizmos/Scripts/Gizmos.meta
Normal file
9
Assets/Runtime Transform Gizmos/Scripts/Gizmos.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4dc4f01f1d1fed947b3964e63855f13c
|
||||
folderAsset: yes
|
||||
timeCreated: 1485353550
|
||||
licenseType: Store
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
9
Assets/Runtime Transform Gizmos/Scripts/Gizmos/Caps.meta
Normal file
9
Assets/Runtime Transform Gizmos/Scripts/Gizmos/Caps.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1b4474ec3061dd743bfcf9c42266903d
|
||||
folderAsset: yes
|
||||
timeCreated: 1515942073
|
||||
licenseType: Store
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a03a03628370fbd49af8440630ed7363
|
||||
folderAsset: yes
|
||||
timeCreated: 1517574268
|
||||
licenseType: Store
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,44 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace RTG
|
||||
{
|
||||
public class GizmoArrowCap2DController : GizmoCap2DController
|
||||
{
|
||||
public GizmoArrowCap2DController(GizmoCap2DControllerData controllerData)
|
||||
:base(controllerData)
|
||||
{}
|
||||
|
||||
public override void UpdateHandles()
|
||||
{
|
||||
_data.CapHandle.Set2DShapeVisible(_data.CircleIndex, false);
|
||||
_data.CapHandle.Set2DShapeVisible(_data.QuadIndex, false);
|
||||
_data.CapHandle.Set2DShapeVisible(_data.ArrowIndex, _data.Cap.IsVisible);
|
||||
}
|
||||
|
||||
public override void UpdateTransforms()
|
||||
{
|
||||
var cap = _data.Cap;
|
||||
_data.Arrow.Height = cap.GetRealArrowHeight();
|
||||
_data.Arrow.BaseRadius = cap.GetRealArrowBaseRadius();
|
||||
_data.Arrow.RotationDegrees = cap.RotationDegrees;
|
||||
_data.Arrow.BaseCenter = cap.Position;
|
||||
}
|
||||
|
||||
public override void CapSlider2D(Vector2 sliderDirection, Vector2 sliderEndPt)
|
||||
{
|
||||
_data.Cap.AlignTransformAxis(1, AxisSign.Positive, sliderDirection);
|
||||
_data.Cap.Position = sliderEndPt;
|
||||
}
|
||||
|
||||
public override void CapSlider2DInvert(Vector2 sliderDirection, Vector2 sliderEndPt)
|
||||
{
|
||||
_data.Cap.AlignTransformAxis(1, AxisSign.Positive, -sliderDirection);
|
||||
_data.Cap.Position = sliderEndPt + sliderDirection.normalized * _data.Cap.GetRealArrowHeight();
|
||||
}
|
||||
|
||||
public override float GetSliderAlignedRealLength()
|
||||
{
|
||||
return _data.Cap.GetRealArrowHeight();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0fb918063462c3d43b2db3c64e0f1f45
|
||||
timeCreated: 1518107539
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,195 @@
|
||||
using UnityEngine;
|
||||
using System;
|
||||
|
||||
namespace RTG
|
||||
{
|
||||
public class GizmoCap2D : GizmoCap
|
||||
{
|
||||
private int _quadIndex;
|
||||
private QuadShape2D _quad = new QuadShape2D();
|
||||
private int _circleIndex;
|
||||
private CircleShape2D _circle = new CircleShape2D();
|
||||
private int _arrowIndex;
|
||||
private ConeShape2D _arrow = new ConeShape2D();
|
||||
|
||||
private GizmoTransform _transform = new GizmoTransform();
|
||||
private GizmoOverrideColor _overrideFillColor = new GizmoOverrideColor();
|
||||
private GizmoOverrideColor _overrideBorderColor = new GizmoOverrideColor();
|
||||
|
||||
private GizmoCap2DControllerData _controllerData;
|
||||
private IGizmoCap2DController[] _controllers = new IGizmoCap2DController[Enum.GetValues(typeof(GizmoCap2DType)).Length];
|
||||
|
||||
private GizmoCap2DLookAndFeel _lookAndFeel = new GizmoCap2DLookAndFeel();
|
||||
private GizmoCap2DLookAndFeel _sharedLookAndFeel;
|
||||
|
||||
public Vector2 Position { get { return _transform.Position2D; } set { _transform.Position2D = value; } }
|
||||
public Quaternion Rotation { get { return _transform.Rotation2D; } }
|
||||
public float RotationDegrees { get { return _transform.Rotation2DDegrees; } set { _transform.Rotation2DDegrees = value; } }
|
||||
public GizmoOverrideColor OverrideFillColor { get { return _overrideFillColor; } }
|
||||
public GizmoOverrideColor OverrideBorderColor { get { return _overrideBorderColor; } }
|
||||
public IGizmoDragSession DragSession { get { return Handle.DragSession; } set { Handle.DragSession = value; } }
|
||||
public GizmoCap2DLookAndFeel LookAndFeel { get { return _sharedLookAndFeel != null ? _sharedLookAndFeel : _lookAndFeel; } }
|
||||
public GizmoCap2DLookAndFeel SharedLookAndFeel { get { return _sharedLookAndFeel; } set { _sharedLookAndFeel = value; } }
|
||||
|
||||
public GizmoCap2D(Gizmo gizmo, int handleId)
|
||||
:base(gizmo, handleId)
|
||||
{
|
||||
_quadIndex = Handle.Add2DShape(_quad);
|
||||
_circleIndex = Handle.Add2DShape(_circle);
|
||||
_arrowIndex = Handle.Add2DShape(_arrow);
|
||||
|
||||
_controllerData = new GizmoCap2DControllerData();
|
||||
_controllerData.Cap = this;
|
||||
_controllerData.CapHandle = Handle;
|
||||
_controllerData.Gizmo = Gizmo;
|
||||
_controllerData.Quad = _quad;
|
||||
_controllerData.QuadIndex = _quadIndex;
|
||||
_controllerData.Circle = _circle;
|
||||
_controllerData.CircleIndex = _circleIndex;
|
||||
_controllerData.Arrow = _arrow;
|
||||
_controllerData.ArrowIndex = _arrowIndex;
|
||||
|
||||
_controllers[(int)GizmoCap2DType.Quad] = new GizmoQuadCap2DController(_controllerData);
|
||||
_controllers[(int)GizmoCap2DType.Circle] = new GizmoCircleCap2DController(_controllerData);
|
||||
_controllers[(int)GizmoCap2DType.Arrow] = new GizmoArrowCap2DController(_controllerData);
|
||||
|
||||
_transform.SetParent(gizmo.Transform);
|
||||
_transform.Changed += OnTransformChanged;
|
||||
|
||||
Gizmo.PreUpdateBegin += OnGizmoPreUpdateBegin;
|
||||
Gizmo.PostEnabled += OnGizmoPostEnabled;
|
||||
}
|
||||
|
||||
public void RegisterTransformAsDragTarget(IGizmoDragSession dragSession)
|
||||
{
|
||||
dragSession.AddTargetTransform(_transform);
|
||||
}
|
||||
|
||||
public void UnregisterTransformAsDragTarget(IGizmoDragSession dragSession)
|
||||
{
|
||||
dragSession.RemoveTargetTransform(_transform);
|
||||
}
|
||||
|
||||
public void AlignTransformAxis(int axisIndex, AxisSign axisSign, Vector2 axis)
|
||||
{
|
||||
_transform.AlignAxis2D(axisIndex, axisSign, axis);
|
||||
}
|
||||
|
||||
public float GetRealQuadWidth()
|
||||
{
|
||||
return LookAndFeel.QuadWidth * LookAndFeel.Scale;
|
||||
}
|
||||
|
||||
public float GetRealQuadHeight()
|
||||
{
|
||||
return LookAndFeel.QuadHeight * LookAndFeel.Scale;
|
||||
}
|
||||
|
||||
public float GetRealCircleRadius()
|
||||
{
|
||||
return LookAndFeel.CircleRadius * LookAndFeel.Scale;
|
||||
}
|
||||
|
||||
public float GetRealArrowHeight()
|
||||
{
|
||||
return LookAndFeel.ArrowHeight * LookAndFeel.Scale;
|
||||
}
|
||||
|
||||
public float GetRealArrowBaseRadius()
|
||||
{
|
||||
return LookAndFeel.ArrowBaseRadius * LookAndFeel.Scale;
|
||||
}
|
||||
|
||||
public void CapSlider2D(Vector2 sliderDirection, Vector2 sliderEndPt)
|
||||
{
|
||||
_controllers[(int)LookAndFeel.CapType].CapSlider2D(sliderDirection, sliderEndPt);
|
||||
}
|
||||
|
||||
public void CapSlider2DInvert(Vector2 sliderDirection, Vector2 sliderEndPt)
|
||||
{
|
||||
_controllers[(int)LookAndFeel.CapType].CapSlider2DInvert(sliderDirection, sliderEndPt);
|
||||
}
|
||||
|
||||
public override void Render(Camera camera)
|
||||
{
|
||||
if (!IsVisible) return;
|
||||
|
||||
if (LookAndFeel.FillMode == GizmoFillMode2D.FilledAndBorder ||
|
||||
LookAndFeel.FillMode == GizmoFillMode2D.Filled)
|
||||
{
|
||||
Color fillColor = new Color();
|
||||
if (!_overrideFillColor.IsActive)
|
||||
{
|
||||
fillColor = LookAndFeel.Color;
|
||||
if (Gizmo.HoverHandleId == HandleId) fillColor = LookAndFeel.HoveredColor;
|
||||
}
|
||||
else fillColor = _overrideFillColor.Color;
|
||||
|
||||
GizmoSolidMaterial solidMaterial = GizmoSolidMaterial.Get;
|
||||
solidMaterial.ResetValuesToSensibleDefaults();
|
||||
solidMaterial.SetLit(false);
|
||||
solidMaterial.SetColor(fillColor);
|
||||
solidMaterial.SetPass(0);
|
||||
|
||||
Handle.Render2DSolid(camera);
|
||||
}
|
||||
|
||||
if (LookAndFeel.FillMode == GizmoFillMode2D.FilledAndBorder ||
|
||||
LookAndFeel.FillMode == GizmoFillMode2D.Border)
|
||||
{
|
||||
Color borderColor = new Color();
|
||||
if (!_overrideFillColor.IsActive)
|
||||
{
|
||||
borderColor = LookAndFeel.BorderColor;
|
||||
if (Gizmo.HoverHandleId == HandleId) borderColor = LookAndFeel.HoveredBorderColor;
|
||||
}
|
||||
else borderColor = _overrideBorderColor.Color;
|
||||
|
||||
GizmoLineMaterial lineMaterial = GizmoLineMaterial.Get;
|
||||
lineMaterial.ResetValuesToSensibleDefaults();
|
||||
lineMaterial.SetColor(borderColor);
|
||||
lineMaterial.SetPass(0);
|
||||
|
||||
Handle.Render2DWire(camera);
|
||||
}
|
||||
}
|
||||
|
||||
public void Refresh()
|
||||
{
|
||||
_controllers[(int)LookAndFeel.CapType].UpdateHandles();
|
||||
_controllers[(int)LookAndFeel.CapType].UpdateTransforms();
|
||||
}
|
||||
|
||||
protected override void OnVisibilityStateChanged()
|
||||
{
|
||||
_controllers[(int)LookAndFeel.CapType].UpdateHandles();
|
||||
_controllers[(int)LookAndFeel.CapType].UpdateTransforms();
|
||||
}
|
||||
|
||||
protected override void OnHoverableStateChanged()
|
||||
{
|
||||
Handle.SetHoverable(IsHoverable);
|
||||
}
|
||||
|
||||
private void OnGizmoPreUpdateBegin(Gizmo gizmo)
|
||||
{
|
||||
int controllerIndex = (int)LookAndFeel.CapType;
|
||||
_controllers[controllerIndex].UpdateHandles();
|
||||
_controllers[controllerIndex].UpdateTransforms();
|
||||
}
|
||||
|
||||
private void OnTransformChanged(GizmoTransform transform, GizmoTransform.ChangeData changeData)
|
||||
{
|
||||
if (changeData.TRSDimension == GizmoDimension.Dim2D ||
|
||||
changeData.ChangeReason == GizmoTransform.ChangeReason.ParentChange)
|
||||
{
|
||||
_controllers[(int)LookAndFeel.CapType].UpdateTransforms();
|
||||
}
|
||||
}
|
||||
|
||||
private void OnGizmoPostEnabled(Gizmo gizmo)
|
||||
{
|
||||
Refresh();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 947308123703f6c4aa2e18c36d6f0675
|
||||
timeCreated: 1517574844
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,78 @@
|
||||
using UnityEngine;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace RTG
|
||||
{
|
||||
public class GizmoCap2DCollection
|
||||
{
|
||||
private List<GizmoCap2D> _caps = new List<GizmoCap2D>();
|
||||
private Dictionary<int, GizmoCap2D> _handleIdToCap = new Dictionary<int, GizmoCap2D>();
|
||||
|
||||
public int Count { get { return _caps.Count; } }
|
||||
public GizmoCap2D this[int id] { get { return _handleIdToCap[id]; } }
|
||||
|
||||
public bool Contains(GizmoCap2D cap)
|
||||
{
|
||||
return _handleIdToCap.ContainsKey(cap.HandleId);
|
||||
}
|
||||
|
||||
public bool Contains(int capHandleId)
|
||||
{
|
||||
return _handleIdToCap.ContainsKey(capHandleId);
|
||||
}
|
||||
|
||||
public void Add(GizmoCap2D cap)
|
||||
{
|
||||
if (!Contains(cap))
|
||||
{
|
||||
_caps.Add(cap);
|
||||
_handleIdToCap.Add(cap.HandleId, cap);
|
||||
}
|
||||
}
|
||||
|
||||
public void Remove(GizmoCap2D cap)
|
||||
{
|
||||
if (Contains(cap))
|
||||
{
|
||||
_caps.Remove(cap);
|
||||
_handleIdToCap.Remove(cap.HandleId);
|
||||
}
|
||||
}
|
||||
|
||||
public void Make2DHoverPriorityLowerThan(Priority priority)
|
||||
{
|
||||
foreach (var cap in _caps)
|
||||
cap.HoverPriority2D.MakeLowerThan(priority);
|
||||
}
|
||||
|
||||
public void Make2DHoverPriorityHigherThan(Priority priority)
|
||||
{
|
||||
foreach (var cap in _caps)
|
||||
cap.HoverPriority2D.MakeHigherThan(priority);
|
||||
}
|
||||
|
||||
public void SetVisible(bool visible)
|
||||
{
|
||||
foreach (var cap in _caps)
|
||||
cap.SetVisible(visible);
|
||||
}
|
||||
|
||||
public void SetHoverable(bool hoverable)
|
||||
{
|
||||
foreach (var cap in _caps)
|
||||
cap.SetHoverable(hoverable);
|
||||
}
|
||||
|
||||
public void SetDragSession(IGizmoDragSession dragSession)
|
||||
{
|
||||
foreach (var cap in _caps)
|
||||
cap.DragSession = dragSession;
|
||||
}
|
||||
|
||||
public void Render(Camera camera)
|
||||
{
|
||||
foreach (var cap in _caps)
|
||||
cap.Render(camera);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 74ef9be37024f42438facd47363bd40e
|
||||
timeCreated: 1518546626
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,20 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace RTG
|
||||
{
|
||||
public abstract class GizmoCap2DController : IGizmoCap2DController
|
||||
{
|
||||
protected GizmoCap2DControllerData _data;
|
||||
|
||||
public GizmoCap2DController(GizmoCap2DControllerData controllerData)
|
||||
{
|
||||
_data = controllerData;
|
||||
}
|
||||
|
||||
public abstract void UpdateHandles();
|
||||
public abstract void UpdateTransforms();
|
||||
public abstract void CapSlider2D(Vector2 sliderDirection, Vector2 sliderEndPt);
|
||||
public abstract void CapSlider2DInvert(Vector2 sliderDirection, Vector2 sliderEndPt);
|
||||
public abstract float GetSliderAlignedRealLength();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 723ae6a73317ffc489374d3169c7b7ee
|
||||
timeCreated: 1518107354
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,17 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace RTG
|
||||
{
|
||||
public class GizmoCap2DControllerData
|
||||
{
|
||||
public Gizmo Gizmo;
|
||||
public GizmoCap2D Cap;
|
||||
public GizmoHandle CapHandle;
|
||||
public QuadShape2D Quad;
|
||||
public CircleShape2D Circle;
|
||||
public ConeShape2D Arrow;
|
||||
public int QuadIndex;
|
||||
public int CircleIndex;
|
||||
public int ArrowIndex;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 52585ce453d49b6419d725c53ddd3204
|
||||
timeCreated: 1518106174
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,48 @@
|
||||
using UnityEngine;
|
||||
using System;
|
||||
|
||||
namespace RTG
|
||||
{
|
||||
[Serializable]
|
||||
public class GizmoCap2DLookAndFeel
|
||||
{
|
||||
[SerializeField]
|
||||
private GizmoFillMode2D _fillMode = GizmoFillMode2D.FilledAndBorder;
|
||||
[SerializeField]
|
||||
private GizmoCap2DType _capType = GizmoCap2DType.Quad;
|
||||
|
||||
[SerializeField]
|
||||
private float _scale = 1.0f;
|
||||
[SerializeField]
|
||||
private float _circleRadius = 12.0f;
|
||||
[SerializeField]
|
||||
private float _quadWidth = 25.0f;
|
||||
[SerializeField]
|
||||
private float _quadHeight = 25.0f;
|
||||
[SerializeField]
|
||||
private float _arrowBaseRadius = 5.0f;
|
||||
[SerializeField]
|
||||
private float _arrowHeight = 20.0f;
|
||||
[SerializeField]
|
||||
private Color _color = Color.white;
|
||||
[SerializeField]
|
||||
private Color _hoveredColor = RTSystemValues.HoveredAxisColor;
|
||||
[SerializeField]
|
||||
private Color _borderColor = Color.white;
|
||||
[SerializeField]
|
||||
private Color _hoveredBorderColor = RTSystemValues.HoveredAxisColor;
|
||||
|
||||
public GizmoFillMode2D FillMode { get { return _fillMode; } set { _fillMode = value; } }
|
||||
public GizmoCap2DType CapType { get { return _capType; } set { _capType = value; } }
|
||||
public float Scale { get { return _scale; } set { _scale = Mathf.Max(0.0f, value); } }
|
||||
public float CircleRadius { get { return _circleRadius; } set { _circleRadius = value; } }
|
||||
public float QuadWidth { get { return _quadWidth; } set { _quadWidth = Mathf.Max(0.0f, value); } }
|
||||
public float QuadHeight { get { return _quadHeight; } set { _quadHeight = Mathf.Max(0.0f, value); } }
|
||||
public float ArrowBaseRadius { get { return _arrowBaseRadius; } set { _arrowBaseRadius = Mathf.Max(0.0f, value); } }
|
||||
public float ArrowHeight { get { return _arrowHeight; } set { _arrowHeight = Mathf.Max(0.0f, value); } }
|
||||
public Color Color { get { return _color; } set { _color = value; } }
|
||||
public Color HoveredColor { get { return _hoveredColor; } set { _hoveredColor = value; } }
|
||||
public Color BorderColor { get { return _borderColor; } set { _borderColor = value; } }
|
||||
public Color HoveredBorderColor { get { return _hoveredBorderColor; } set { _hoveredBorderColor = value; } }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 51da14fa999823945b2bdeddbaffa356
|
||||
timeCreated: 1517574478
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,9 @@
|
||||
namespace RTG
|
||||
{
|
||||
public enum GizmoCap2DType
|
||||
{
|
||||
Quad = 0,
|
||||
Circle,
|
||||
Arrow
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 11ea9313773f7e5479f63b8b3afdb097
|
||||
timeCreated: 1517574330
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,42 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace RTG
|
||||
{
|
||||
public class GizmoCircleCap2DController : GizmoCap2DController
|
||||
{
|
||||
public GizmoCircleCap2DController(GizmoCap2DControllerData controllerData)
|
||||
:base(controllerData)
|
||||
{}
|
||||
|
||||
public override void UpdateHandles()
|
||||
{
|
||||
_data.CapHandle.Set2DShapeVisible(_data.ArrowIndex, false);
|
||||
_data.CapHandle.Set2DShapeVisible(_data.QuadIndex, false);
|
||||
_data.CapHandle.Set2DShapeVisible(_data.CircleIndex, _data.Cap.IsVisible);
|
||||
}
|
||||
|
||||
public override void UpdateTransforms()
|
||||
{
|
||||
var cap = _data.Cap;
|
||||
_data.Circle.Radius = cap.GetRealCircleRadius();
|
||||
_data.Circle.Center = cap.Position;
|
||||
}
|
||||
|
||||
public override void CapSlider2D(Vector2 sliderDirection, Vector2 sliderEndPt)
|
||||
{
|
||||
_data.Cap.AlignTransformAxis(0, AxisSign.Positive, sliderDirection);
|
||||
_data.Cap.Position = sliderEndPt + sliderDirection.normalized * _data.Cap.GetRealCircleRadius();
|
||||
}
|
||||
|
||||
public override void CapSlider2DInvert(Vector2 sliderDirection, Vector2 sliderEndPt)
|
||||
{
|
||||
_data.Cap.AlignTransformAxis(0, AxisSign.Positive, -sliderDirection);
|
||||
_data.Cap.Position = sliderEndPt + sliderDirection.normalized * _data.Cap.GetRealCircleRadius();
|
||||
}
|
||||
|
||||
public override float GetSliderAlignedRealLength()
|
||||
{
|
||||
return _data.Cap.GetRealCircleRadius() * 2.0f;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 53a507550fc0f904288fc6792054d4e7
|
||||
timeCreated: 1518112602
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,44 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace RTG
|
||||
{
|
||||
public class GizmoQuadCap2DController : GizmoCap2DController
|
||||
{
|
||||
public GizmoQuadCap2DController(GizmoCap2DControllerData controllerData)
|
||||
:base(controllerData)
|
||||
{ }
|
||||
|
||||
public override void UpdateHandles()
|
||||
{
|
||||
_data.CapHandle.Set2DShapeVisible(_data.ArrowIndex, false);
|
||||
_data.CapHandle.Set2DShapeVisible(_data.CircleIndex, false);
|
||||
_data.CapHandle.Set2DShapeVisible(_data.QuadIndex, _data.Cap.IsVisible);
|
||||
}
|
||||
|
||||
public override void UpdateTransforms()
|
||||
{
|
||||
var cap = _data.Cap;
|
||||
_data.Quad.Width = cap.GetRealQuadWidth();
|
||||
_data.Quad.Height = cap.GetRealQuadHeight();
|
||||
_data.Quad.Center = cap.Position;
|
||||
_data.Quad.RotationDegrees = cap.RotationDegrees;
|
||||
}
|
||||
|
||||
public override void CapSlider2D(Vector2 sliderDirection, Vector2 sliderEndPt)
|
||||
{
|
||||
_data.Cap.AlignTransformAxis(0, AxisSign.Positive, sliderDirection);
|
||||
_data.Cap.Position = sliderEndPt + sliderDirection * _data.Cap.GetRealQuadWidth() * 0.5f;
|
||||
}
|
||||
|
||||
public override void CapSlider2DInvert(Vector2 sliderDirection, Vector2 sliderEndPt)
|
||||
{
|
||||
_data.Cap.AlignTransformAxis(0, AxisSign.Positive, -sliderDirection);
|
||||
_data.Cap.Position = sliderEndPt + sliderDirection * _data.Cap.GetRealQuadWidth() * 0.5f;
|
||||
}
|
||||
|
||||
public override float GetSliderAlignedRealLength()
|
||||
{
|
||||
return _data.Cap.GetRealQuadWidth();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d366ff3a96d42de409a7a5c2d0160f03
|
||||
timeCreated: 1518108619
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,13 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace RTG
|
||||
{
|
||||
public interface IGizmoCap2DController
|
||||
{
|
||||
void UpdateHandles();
|
||||
void UpdateTransforms();
|
||||
void CapSlider2D(Vector2 sliderDirection, Vector2 sliderEndPt);
|
||||
void CapSlider2DInvert(Vector2 sliderDirection, Vector2 sliderEndPt);
|
||||
float GetSliderAlignedRealLength();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ed842505ec81e6d47b697b8704188362
|
||||
timeCreated: 1518106278
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 99b9b1c6457ef414395476b179ac87e2
|
||||
folderAsset: yes
|
||||
timeCreated: 1516117217
|
||||
licenseType: Store
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,47 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace RTG
|
||||
{
|
||||
public class GizmoBoxCap3DController : GizmoCap3DController
|
||||
{
|
||||
public GizmoBoxCap3DController(GizmoCap3DControllerData controllerData)
|
||||
:base(controllerData)
|
||||
{
|
||||
}
|
||||
|
||||
public override void UpdateHandles()
|
||||
{
|
||||
_data.CapHandle.Set3DShapeVisible(_data.PyramidIndex, false);
|
||||
_data.CapHandle.Set3DShapeVisible(_data.TrPrismIndex, false);
|
||||
_data.CapHandle.Set3DShapeVisible(_data.ConeIndex, false);
|
||||
_data.CapHandle.Set3DShapeVisible(_data.SphereIndex, false);
|
||||
_data.CapHandle.Set3DShapeVisible(_data.BoxIndex, _data.Cap.IsVisible);
|
||||
}
|
||||
|
||||
public override void UpdateTransforms(float zoomFactor)
|
||||
{
|
||||
var cap = _data.Cap;
|
||||
|
||||
_data.Box.Center = cap.Position;
|
||||
_data.Box.Rotation = cap.Rotation;
|
||||
_data.Box.Size = cap.GetRealBoxSize(zoomFactor);
|
||||
}
|
||||
|
||||
public override void CapSlider3D(Vector3 sliderDirection, Vector3 sliderEndPt, float zoomFactor)
|
||||
{
|
||||
_data.Cap.AlignTransformAxis(0, AxisSign.Positive, sliderDirection);
|
||||
_data.Cap.Position = sliderEndPt + sliderDirection * _data.Box.Size[0] * 0.5f;
|
||||
}
|
||||
|
||||
public override void CapSlider3DInvert(Vector3 sliderDirection, Vector3 sliderEndPt, float zoomFactor)
|
||||
{
|
||||
_data.Cap.AlignTransformAxis(0, AxisSign.Positive, -sliderDirection);
|
||||
_data.Cap.Position = sliderEndPt + sliderDirection * GetSliderAlignedRealLength(zoomFactor) * 0.5f;
|
||||
}
|
||||
|
||||
public override float GetSliderAlignedRealLength(float zoomFactor)
|
||||
{
|
||||
return _data.Cap.GetRealBoxWidth(zoomFactor);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2bd3568bbdba772479f44cce799a32f2
|
||||
timeCreated: 1516303063
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,290 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace RTG
|
||||
{
|
||||
public class GizmoCap3D : GizmoCap
|
||||
{
|
||||
private int _coneIndex;
|
||||
private ConeShape3D _cone = new ConeShape3D();
|
||||
private int _pyramidIndex;
|
||||
private PyramidShape3D _pyramid = new PyramidShape3D();
|
||||
private int _boxIndex;
|
||||
private BoxShape3D _box = new BoxShape3D();
|
||||
private int _sphereIndex;
|
||||
private SphereShape3D _sphere = new SphereShape3D();
|
||||
private int _trPrismIndex;
|
||||
private TriangPrismShape3D _trPrism = new TriangPrismShape3D();
|
||||
|
||||
private GizmoCap3DControllerData _controllerData = new GizmoCap3DControllerData();
|
||||
private IGizmoCap3DController[] _controllers = new IGizmoCap3DController[System.Enum.GetValues(typeof(GizmoCap3DType)).Length];
|
||||
|
||||
private GizmoTransform _transform = new GizmoTransform();
|
||||
private GizmoOverrideColor _overrideColor = new GizmoOverrideColor();
|
||||
|
||||
private GizmoCap3DLookAndFeel _lookAndFeel = new GizmoCap3DLookAndFeel();
|
||||
private GizmoCap3DLookAndFeel _sharedLookAndFeel;
|
||||
|
||||
public Vector3 Position { get { return _transform.Position3D; } set { _transform.Position3D = value; } }
|
||||
public Quaternion Rotation { get { return _transform.Rotation3D; } set { _transform.Rotation3D = value; } }
|
||||
public GizmoOverrideColor OverrideColor { get { return _overrideColor; } }
|
||||
public IGizmoDragSession DragSession { get { return Handle.DragSession; } set { Handle.DragSession = value; } }
|
||||
public GizmoCap3DLookAndFeel LookAndFeel { get { return _sharedLookAndFeel != null ? _sharedLookAndFeel : _lookAndFeel; } }
|
||||
public GizmoCap3DLookAndFeel SharedLookAndFeel { get { return _sharedLookAndFeel; } set { _sharedLookAndFeel = value; } }
|
||||
|
||||
public GizmoCap3D(Gizmo gizmo, int handleId)
|
||||
:base(gizmo, handleId)
|
||||
{
|
||||
_coneIndex = Handle.Add3DShape(_cone);
|
||||
_pyramidIndex = Handle.Add3DShape(_pyramid);
|
||||
_boxIndex = Handle.Add3DShape(_box);
|
||||
_sphereIndex = Handle.Add3DShape(_sphere);
|
||||
_trPrismIndex = Handle.Add3DShape(_trPrism);
|
||||
|
||||
SetZoomFactorTransform(_transform);
|
||||
|
||||
_controllerData.Gizmo = Gizmo;
|
||||
_controllerData.Cap = this;
|
||||
_controllerData.CapHandle = Handle;
|
||||
_controllerData.Cone = _cone;
|
||||
_controllerData.ConeIndex = _coneIndex;
|
||||
_controllerData.Pyramid = _pyramid;
|
||||
_controllerData.PyramidIndex = _pyramidIndex;
|
||||
_controllerData.Box = _box;
|
||||
_controllerData.BoxIndex = _boxIndex;
|
||||
_controllerData.Sphere = _sphere;
|
||||
_controllerData.SphereIndex = _sphereIndex;
|
||||
_controllerData.TrPrism = _trPrism;
|
||||
_controllerData.TrPrismIndex = _trPrismIndex;
|
||||
|
||||
_controllers[(int)GizmoCap3DType.Cone] = new GizmoConeCap3DController(_controllerData);
|
||||
_controllers[(int)GizmoCap3DType.Pyramid] = new GizmoPyramidCap3DController(_controllerData);
|
||||
_controllers[(int)GizmoCap3DType.Box] = new GizmoBoxCap3DController(_controllerData);
|
||||
_controllers[(int)GizmoCap3DType.Sphere] = new GizmoSphereCap3DController(_controllerData);
|
||||
_controllers[(int)GizmoCap3DType.TriangPrism] = new GizmoTriPrismCap3DController(_controllerData);
|
||||
|
||||
_transform.Changed += OnTransformChanged;
|
||||
_transform.SetParent(Gizmo.Transform);
|
||||
Gizmo.PreUpdateBegin += OnGizmoPreUpdateBegin;
|
||||
Gizmo.PostEnabled += OnGizmoPostEnabled;
|
||||
Gizmo.PostDisabled += OnGizmoPostDisabled;
|
||||
}
|
||||
|
||||
public void RegisterTransformAsDragTarget(IGizmoDragSession dragSession)
|
||||
{
|
||||
dragSession.AddTargetTransform(_transform);
|
||||
}
|
||||
|
||||
public void UnregisterTransformAsDragTarget(IGizmoDragSession dragSession)
|
||||
{
|
||||
dragSession.RemoveTargetTransform(_transform);
|
||||
}
|
||||
|
||||
public void AlignTransformAxis(int axisIndex, AxisSign axisSign, Vector3 axis)
|
||||
{
|
||||
_transform.AlignAxis3D(axisIndex, axisSign, axis);
|
||||
}
|
||||
|
||||
public void SetZoomFactorTransform(GizmoTransform transform)
|
||||
{
|
||||
Handle.SetZoomFactorTransform(transform);
|
||||
}
|
||||
|
||||
public void CapSlider3D(Vector3 sliderDirection, Vector3 sliderEndPt)
|
||||
{
|
||||
_controllers[(int)LookAndFeel.CapType].CapSlider3D(sliderDirection, sliderEndPt, GetZoomFactor(Gizmo.GetWorkCamera()));
|
||||
}
|
||||
|
||||
public void CapSlider3DInvert(Vector3 sliderDirection, Vector3 sliderEndPt)
|
||||
{
|
||||
_controllers[(int)LookAndFeel.CapType].CapSlider3DInvert(sliderDirection, sliderEndPt, GetZoomFactor(Gizmo.GetWorkCamera()));
|
||||
}
|
||||
|
||||
public float GetSliderAlignedRealLength(float zoomFactor)
|
||||
{
|
||||
return _controllers[(int)LookAndFeel.CapType].GetSliderAlignedRealLength(zoomFactor);
|
||||
}
|
||||
|
||||
public float GetZoomFactor(Camera camera)
|
||||
{
|
||||
if (!LookAndFeel.UseZoomFactor) return 1.0f;
|
||||
return Handle.GetZoomFactor(camera);
|
||||
}
|
||||
|
||||
public float GetRealConeHeight(float zoomFactor)
|
||||
{
|
||||
if (!LookAndFeel.UseZoomFactor) zoomFactor = 1.0f;
|
||||
return LookAndFeel.ConeHeight * LookAndFeel.Scale * zoomFactor;
|
||||
}
|
||||
|
||||
public float GetRealConeRadius(float zoomFactor)
|
||||
{
|
||||
if (!LookAndFeel.UseZoomFactor) zoomFactor = 1.0f;
|
||||
return LookAndFeel.ConeRadius * LookAndFeel.Scale * zoomFactor;
|
||||
}
|
||||
|
||||
public float GetRealPyramidWidth(float zoomFactor)
|
||||
{
|
||||
if (!LookAndFeel.UseZoomFactor) zoomFactor = 1.0f;
|
||||
return LookAndFeel.PyramidWidth * LookAndFeel.Scale * zoomFactor;
|
||||
}
|
||||
|
||||
public float GetRealPyramidDepth(float zoomFactor)
|
||||
{
|
||||
if (!LookAndFeel.UseZoomFactor) zoomFactor = 1.0f;
|
||||
return LookAndFeel.PyramidDepth * LookAndFeel.Scale * zoomFactor;
|
||||
}
|
||||
|
||||
public float GetRealPyramidHeight(float zoomFactor)
|
||||
{
|
||||
if (!LookAndFeel.UseZoomFactor) zoomFactor = 1.0f;
|
||||
return LookAndFeel.PyramidHeight * LookAndFeel.Scale * zoomFactor;
|
||||
}
|
||||
|
||||
public float GetRealBoxWidth(float zoomFactor)
|
||||
{
|
||||
if (!LookAndFeel.UseZoomFactor) zoomFactor = 1.0f;
|
||||
return LookAndFeel.BoxWidth * LookAndFeel.Scale * zoomFactor;
|
||||
}
|
||||
|
||||
public float GetRealBoxHeight(float zoomFactor)
|
||||
{
|
||||
if (!LookAndFeel.UseZoomFactor) zoomFactor = 1.0f;
|
||||
return LookAndFeel.BoxHeight * LookAndFeel.Scale * zoomFactor;
|
||||
}
|
||||
|
||||
public float GetRealBoxDepth(float zoomFactor)
|
||||
{
|
||||
if (!LookAndFeel.UseZoomFactor) zoomFactor = 1.0f;
|
||||
return LookAndFeel.BoxDepth * LookAndFeel.Scale * zoomFactor;
|
||||
}
|
||||
|
||||
public Vector3 GetRealBoxSize(float zoomFactor)
|
||||
{
|
||||
if (!LookAndFeel.UseZoomFactor) zoomFactor = 1.0f;
|
||||
return new Vector3(LookAndFeel.BoxWidth, LookAndFeel.BoxHeight, LookAndFeel.BoxDepth) * LookAndFeel.Scale * zoomFactor;
|
||||
}
|
||||
|
||||
public float GetRealSphereRadius(float zoomFactor)
|
||||
{
|
||||
if (!LookAndFeel.UseZoomFactor) zoomFactor = 1.0f;
|
||||
return LookAndFeel.SphereRadius * LookAndFeel.Scale * zoomFactor;
|
||||
}
|
||||
|
||||
public float GetRealTriPrismWidth(float zoomFactor)
|
||||
{
|
||||
if (!LookAndFeel.UseZoomFactor) zoomFactor = 1.0f;
|
||||
return LookAndFeel.TrPrismWidth * LookAndFeel.Scale * zoomFactor;
|
||||
}
|
||||
|
||||
public float GetRealTriPrismHeight(float zoomFactor)
|
||||
{
|
||||
if (!LookAndFeel.UseZoomFactor) zoomFactor = 1.0f;
|
||||
return LookAndFeel.TrPrismHeight * LookAndFeel.Scale * zoomFactor;
|
||||
}
|
||||
|
||||
public float GetRealTriPrismDepth(float zoomFactor)
|
||||
{
|
||||
if (!LookAndFeel.UseZoomFactor) zoomFactor = 1.0f;
|
||||
return LookAndFeel.TrPrismDepth * LookAndFeel.Scale * zoomFactor;
|
||||
}
|
||||
|
||||
public void ApplyZoomFactor(Camera camera)
|
||||
{
|
||||
if (LookAndFeel.UseZoomFactor)
|
||||
{
|
||||
_controllers[(int)LookAndFeel.CapType].UpdateTransforms(GetZoomFactor(camera));
|
||||
}
|
||||
}
|
||||
|
||||
public override void Render(Camera camera)
|
||||
{
|
||||
if (!IsVisible) return;
|
||||
|
||||
Color color = new Color();
|
||||
if (!OverrideColor.IsActive)
|
||||
{
|
||||
if (Gizmo.IsHovered && Gizmo.HoverInfo.HandleId == HandleId) color = LookAndFeel.HoveredColor;
|
||||
else color = LookAndFeel.Color;
|
||||
}
|
||||
else color = OverrideColor.Color;
|
||||
|
||||
if (LookAndFeel.FillMode == GizmoFillMode3D.Filled)
|
||||
{
|
||||
bool isLit = LookAndFeel.ShadeMode == GizmoShadeMode.Lit;
|
||||
|
||||
GizmoSolidMaterial solidMaterial = GizmoSolidMaterial.Get;
|
||||
solidMaterial.ResetValuesToSensibleDefaults();
|
||||
solidMaterial.SetLit(isLit);
|
||||
if (isLit) solidMaterial.SetLightDirection(camera.transform.forward);
|
||||
solidMaterial.SetColor(color);
|
||||
solidMaterial.SetPass(0);
|
||||
|
||||
Handle.Render3DSolid();
|
||||
}
|
||||
else
|
||||
{
|
||||
GizmoLineMaterial lineMaterial = GizmoLineMaterial.Get;
|
||||
lineMaterial.ResetValuesToSensibleDefaults();
|
||||
lineMaterial.SetColor(color);
|
||||
lineMaterial.SetPass(0);
|
||||
|
||||
Handle.Render3DWire();
|
||||
}
|
||||
|
||||
if (LookAndFeel.CapType == GizmoCap3DType.Sphere && LookAndFeel.IsSphereBorderVisible)
|
||||
{
|
||||
GizmoLineMaterial lineMaterial = GizmoLineMaterial.Get;
|
||||
lineMaterial.ResetValuesToSensibleDefaults();
|
||||
lineMaterial.SetColor(LookAndFeel.SphereBorderColor);
|
||||
lineMaterial.SetPass(0);
|
||||
|
||||
GLRenderer.DrawSphereBorder(camera, Position, GetRealSphereRadius(GetZoomFactor(camera)), LookAndFeel.NumSphereBorderPoints);
|
||||
}
|
||||
}
|
||||
|
||||
public void Refresh()
|
||||
{
|
||||
Camera camera = Gizmo.GetWorkCamera();
|
||||
float zoomFactor = GetZoomFactor(camera);
|
||||
|
||||
_controllers[(int)LookAndFeel.CapType].UpdateHandles();
|
||||
_controllers[(int)LookAndFeel.CapType].UpdateTransforms(zoomFactor);
|
||||
}
|
||||
|
||||
protected override void OnVisibilityStateChanged()
|
||||
{
|
||||
_controllers[(int)LookAndFeel.CapType].UpdateHandles();
|
||||
|
||||
Camera camera = Gizmo.GetWorkCamera();
|
||||
_controllers[(int)LookAndFeel.CapType].UpdateTransforms(GetZoomFactor(camera));
|
||||
}
|
||||
|
||||
protected override void OnHoverableStateChanged()
|
||||
{
|
||||
Handle.SetHoverable(IsHoverable);
|
||||
}
|
||||
|
||||
private void OnGizmoPreUpdateBegin(Gizmo gizmo)
|
||||
{
|
||||
int controllerIndex = (int)LookAndFeel.CapType;
|
||||
_controllers[controllerIndex].UpdateHandles();
|
||||
_controllers[controllerIndex].UpdateTransforms(GetZoomFactor(Gizmo.FocusCamera));
|
||||
}
|
||||
|
||||
private void OnTransformChanged(GizmoTransform transform, GizmoTransform.ChangeData changeData)
|
||||
{
|
||||
if (changeData.ChangeReason == GizmoTransform.ChangeReason.ParentChange ||
|
||||
changeData.TRSDimension == GizmoDimension.Dim3D) _controllers[(int)LookAndFeel.CapType].UpdateTransforms(GetZoomFactor(Gizmo.GetWorkCamera()));
|
||||
}
|
||||
|
||||
private void OnGizmoPostEnabled(Gizmo gizmo)
|
||||
{
|
||||
Refresh();
|
||||
}
|
||||
|
||||
private void OnGizmoPostDisabled(Gizmo gizmo)
|
||||
{
|
||||
OverrideColor.IsActive = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 09e86b20128a85c4f99b77684b20665c
|
||||
timeCreated: 1516118014
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,88 @@
|
||||
using UnityEngine;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace RTG
|
||||
{
|
||||
public class GizmoCap3DCollection
|
||||
{
|
||||
private List<GizmoCap3D> _caps = new List<GizmoCap3D>();
|
||||
private Dictionary<int, GizmoCap3D> _handleIdToCap = new Dictionary<int, GizmoCap3D>();
|
||||
|
||||
public int Count { get { return _caps.Count; } }
|
||||
public GizmoCap3D this[int id] { get { return _handleIdToCap[id]; } }
|
||||
|
||||
public bool Contains(GizmoCap3D cap)
|
||||
{
|
||||
return _handleIdToCap.ContainsKey(cap.HandleId);
|
||||
}
|
||||
|
||||
public bool Contains(int capHandleId)
|
||||
{
|
||||
return _handleIdToCap.ContainsKey(capHandleId);
|
||||
}
|
||||
|
||||
public void Add(GizmoCap3D cap)
|
||||
{
|
||||
if (!Contains(cap))
|
||||
{
|
||||
_caps.Add(cap);
|
||||
_handleIdToCap.Add(cap.HandleId, cap);
|
||||
}
|
||||
}
|
||||
|
||||
public void Remove(GizmoCap3D cap)
|
||||
{
|
||||
if (Contains(cap))
|
||||
{
|
||||
_caps.Remove(cap);
|
||||
_handleIdToCap.Remove(cap.HandleId);
|
||||
}
|
||||
}
|
||||
|
||||
public void ApplyZoomFactor(Camera camera)
|
||||
{
|
||||
foreach (var cap in _caps)
|
||||
cap.ApplyZoomFactor(camera);
|
||||
}
|
||||
|
||||
public void SetZoomFactorTransform(GizmoTransform zoomFactorTransform)
|
||||
{
|
||||
foreach (var cap in _caps)
|
||||
cap.SetZoomFactorTransform(zoomFactorTransform);
|
||||
}
|
||||
|
||||
public void Make3DHoverPriorityLowerThan(Priority priority)
|
||||
{
|
||||
foreach (var cap in _caps)
|
||||
cap.HoverPriority3D.MakeLowerThan(priority);
|
||||
}
|
||||
|
||||
public void Make3DHoverPriorityHigherThan(Priority priority)
|
||||
{
|
||||
foreach (var cap in _caps)
|
||||
cap.HoverPriority3D.MakeHigherThan(priority);
|
||||
}
|
||||
|
||||
public void SetVisible(bool visible)
|
||||
{
|
||||
foreach (var cap in _caps)
|
||||
cap.SetVisible(visible);
|
||||
}
|
||||
|
||||
public List<GizmoCap3D> GetRenderSortedCaps(Camera renderCamera)
|
||||
{
|
||||
var sortedCaps = new List<GizmoCap3D>(_caps);
|
||||
Vector3 cameraPos = renderCamera.transform.position;
|
||||
|
||||
sortedCaps.Sort(delegate(GizmoCap3D c0, GizmoCap3D c1)
|
||||
{
|
||||
float d0 = (c0.Position - cameraPos).sqrMagnitude;
|
||||
float d1 = (c1.Position - cameraPos).sqrMagnitude;
|
||||
|
||||
return d1.CompareTo(d0);
|
||||
});
|
||||
|
||||
return sortedCaps;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a98ace8985317e64f8b50ef9fad4174f
|
||||
timeCreated: 1518546366
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,20 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace RTG
|
||||
{
|
||||
public abstract class GizmoCap3DController : IGizmoCap3DController
|
||||
{
|
||||
protected GizmoCap3DControllerData _data;
|
||||
|
||||
public GizmoCap3DController(GizmoCap3DControllerData controllerData)
|
||||
{
|
||||
_data = controllerData;
|
||||
}
|
||||
|
||||
public abstract void UpdateHandles();
|
||||
public abstract void UpdateTransforms(float zoomFactor);
|
||||
public abstract void CapSlider3D(Vector3 sliderDirection, Vector3 sliderEndPt, float zoomFactor);
|
||||
public abstract void CapSlider3DInvert(Vector3 sliderDirection, Vector3 sliderEndPt, float zoomFactor);
|
||||
public abstract float GetSliderAlignedRealLength(float zoomFactor);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3cafdbd6e9e6b5c4e8fdfdc8f8162960
|
||||
timeCreated: 1516139492
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,21 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace RTG
|
||||
{
|
||||
public class GizmoCap3DControllerData
|
||||
{
|
||||
public Gizmo Gizmo;
|
||||
public GizmoCap3D Cap;
|
||||
public GizmoHandle CapHandle;
|
||||
public ConeShape3D Cone;
|
||||
public PyramidShape3D Pyramid;
|
||||
public BoxShape3D Box;
|
||||
public SphereShape3D Sphere;
|
||||
public TriangPrismShape3D TrPrism;
|
||||
public int ConeIndex;
|
||||
public int PyramidIndex;
|
||||
public int BoxIndex;
|
||||
public int SphereIndex;
|
||||
public int TrPrismIndex;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b9b3fcb2021505d46afa2d4e7b629b52
|
||||
timeCreated: 1516137754
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,91 @@
|
||||
using UnityEngine;
|
||||
using System;
|
||||
|
||||
namespace RTG
|
||||
{
|
||||
[Serializable]
|
||||
public class GizmoCap3DLookAndFeel
|
||||
{
|
||||
[SerializeField]
|
||||
private GizmoCap3DType _capType = GizmoCap3DType.Cone;
|
||||
[SerializeField]
|
||||
private GizmoFillMode3D _fillMode = GizmoFillMode3D.Filled;
|
||||
[SerializeField]
|
||||
private GizmoShadeMode _shadeMode = GizmoShadeMode.Lit;
|
||||
|
||||
[SerializeField]
|
||||
private float _scale = 1.0f;
|
||||
[SerializeField]
|
||||
private bool _useZoomFactor = true;
|
||||
|
||||
[SerializeField]
|
||||
private float _coneHeight = 1.65f;
|
||||
[SerializeField]
|
||||
private float _coneRadius = 0.5f;
|
||||
|
||||
[SerializeField]
|
||||
private float _pyramidHeight = 1.65f;
|
||||
[SerializeField]
|
||||
private float _pyramidWidth = 0.8f;
|
||||
[SerializeField]
|
||||
private float _pyramidDepth = 0.8f;
|
||||
|
||||
[SerializeField]
|
||||
private float _boxWidth = 0.7f;
|
||||
[SerializeField]
|
||||
private float _boxHeight = 0.7f;
|
||||
[SerializeField]
|
||||
private float _boxDepth = 0.7f;
|
||||
|
||||
[SerializeField]
|
||||
private float _sphereRadius = 0.45f;
|
||||
|
||||
[SerializeField]
|
||||
private float _trPrismWidth = 1.0f;
|
||||
[SerializeField]
|
||||
private float _trPrismHeight = 1.0f;
|
||||
[SerializeField]
|
||||
private float _trPrismDepth = 1.0f;
|
||||
|
||||
[SerializeField]
|
||||
private bool _isSphereBorderVisible;
|
||||
[SerializeField]
|
||||
private Color _sphereBorderColor = Color.white;
|
||||
[SerializeField]
|
||||
private int _numSphereBorderPoints = 100;
|
||||
|
||||
[SerializeField]
|
||||
private Color _color = RTSystemValues.XAxisColor;
|
||||
[SerializeField]
|
||||
private Color _hoveredColor = RTSystemValues.HoveredAxisColor;
|
||||
|
||||
public GizmoCap3DType CapType { get { return _capType; } set { _capType = value; } }
|
||||
public GizmoFillMode3D FillMode { get { return _fillMode; } set { _fillMode = value; } }
|
||||
public GizmoShadeMode ShadeMode { get { return _shadeMode; } set { _shadeMode = value; } }
|
||||
public float Scale { get { return _scale; } set { _scale = Mathf.Max(0.0f, value); } }
|
||||
public bool UseZoomFactor { get { return _useZoomFactor; } set { _useZoomFactor = value; } }
|
||||
public float ConeHeight { get { return _coneHeight; } set { _coneHeight = Mathf.Max(1e-5f, value); } }
|
||||
public float ConeRadius { get { return _coneRadius; } set { _coneRadius = Mathf.Max(1e-5f, value); } }
|
||||
public float PyramidHeight { get { return _pyramidHeight; } set { _pyramidHeight = Mathf.Max(1e-5f, value); } }
|
||||
public float PyramidWidth { get { return _pyramidWidth; } set { _pyramidWidth = Mathf.Max(1e-5f, value); } }
|
||||
public float PyramidDepth { get { return _pyramidDepth; } set { _pyramidDepth = Mathf.Max(1e-5f, value); } }
|
||||
public float BoxWidth { get { return _boxWidth; } set { _boxWidth = Mathf.Max(1e-5f, value); } }
|
||||
public float BoxHeight { get { return _boxHeight; } set { _boxHeight = Mathf.Max(1e-5f, value); } }
|
||||
public float BoxDepth { get { return _boxDepth; } set { _boxDepth = Mathf.Max(1e-5f, value); } }
|
||||
public float SphereRadius { get { return _sphereRadius; } set { _sphereRadius = Mathf.Max(1e-5f, value); } }
|
||||
public float TrPrismWidth { get { return _trPrismWidth; } set { _trPrismWidth = Mathf.Max(1e-5f, value); } }
|
||||
public float TrPrismHeight { get { return _trPrismHeight; } set { _trPrismHeight = Mathf.Max(1e-5f, value); } }
|
||||
public float TrPrismDepth { get { return _trPrismDepth; } set { _trPrismDepth = Mathf.Max(1e-5f, value); } }
|
||||
public bool IsSphereBorderVisible { get { return _isSphereBorderVisible; } set { _isSphereBorderVisible = value; } }
|
||||
public Color SphereBorderColor { get { return _sphereBorderColor; } set { _sphereBorderColor = value; } }
|
||||
public int NumSphereBorderPoints { get { return _numSphereBorderPoints; } set { _numSphereBorderPoints = Mathf.Max(3, value); } }
|
||||
public Color Color { get { return _color; } set { _color = value; } }
|
||||
public Color HoveredColor { get { return _hoveredColor; } set { _hoveredColor = value; } }
|
||||
|
||||
public static float DefaultConeHeight { get { return 1.65f; } }
|
||||
public static float DefaultConeRadius { get { return 0.5f; } }
|
||||
public static float DefaultPyramidHeight { get { return 1.65f; } }
|
||||
public static float DefaultPyramidWidth { get { return 0.8f; } }
|
||||
public static float DefaultPyramidDepth { get { return 0.8f; } }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4e869ebaf836cb2449eea63987702b98
|
||||
timeCreated: 1516118047
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,11 @@
|
||||
namespace RTG
|
||||
{
|
||||
public enum GizmoCap3DType
|
||||
{
|
||||
Cone = 0,
|
||||
Pyramid,
|
||||
Box,
|
||||
Sphere,
|
||||
TriangPrism
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 324688d0140c7924a93b4ec894016f8f
|
||||
timeCreated: 1516117476
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,48 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace RTG
|
||||
{
|
||||
public class GizmoConeCap3DController : GizmoCap3DController
|
||||
{
|
||||
public GizmoConeCap3DController(GizmoCap3DControllerData controllerData)
|
||||
:base(controllerData)
|
||||
{
|
||||
}
|
||||
|
||||
public override void UpdateHandles()
|
||||
{
|
||||
_data.CapHandle.Set3DShapeVisible(_data.PyramidIndex, false);
|
||||
_data.CapHandle.Set3DShapeVisible(_data.TrPrismIndex, false);
|
||||
_data.CapHandle.Set3DShapeVisible(_data.BoxIndex, false);
|
||||
_data.CapHandle.Set3DShapeVisible(_data.SphereIndex, false);
|
||||
_data.CapHandle.Set3DShapeVisible(_data.ConeIndex, _data.Cap.IsVisible);
|
||||
}
|
||||
|
||||
public override void UpdateTransforms(float zoomFactor)
|
||||
{
|
||||
var cap = _data.Cap;
|
||||
|
||||
_data.Cone.BaseCenter = cap.Position;
|
||||
_data.Cone.Rotation = cap.Rotation;
|
||||
_data.Cone.BaseRadius = cap.GetRealConeRadius(zoomFactor);
|
||||
_data.Cone.Height = cap.GetRealConeHeight(zoomFactor);
|
||||
}
|
||||
|
||||
public override void CapSlider3D(Vector3 sliderDirection, Vector3 sliderEndPt, float zoomFactor)
|
||||
{
|
||||
_data.Cap.AlignTransformAxis(1, AxisSign.Positive, sliderDirection);
|
||||
_data.Cap.Position = sliderEndPt;
|
||||
}
|
||||
|
||||
public override void CapSlider3DInvert(Vector3 sliderDirection, Vector3 sliderEndPt, float zoomFactor)
|
||||
{
|
||||
_data.Cap.AlignTransformAxis(1, AxisSign.Positive, -sliderDirection);
|
||||
_data.Cap.Position = sliderEndPt + sliderDirection * GetSliderAlignedRealLength(zoomFactor);
|
||||
}
|
||||
|
||||
public override float GetSliderAlignedRealLength(float zoomFactor)
|
||||
{
|
||||
return _data.Cap.GetRealConeHeight(zoomFactor);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fd6132795c3e49849b0bc8cfa2153271
|
||||
timeCreated: 1516139331
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,49 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace RTG
|
||||
{
|
||||
public class GizmoPyramidCap3DController : GizmoCap3DController
|
||||
{
|
||||
public GizmoPyramidCap3DController(GizmoCap3DControllerData controllerData)
|
||||
:base(controllerData)
|
||||
{
|
||||
}
|
||||
|
||||
public override void UpdateHandles()
|
||||
{
|
||||
_data.CapHandle.Set3DShapeVisible(_data.ConeIndex, false);
|
||||
_data.CapHandle.Set3DShapeVisible(_data.TrPrismIndex, false);
|
||||
_data.CapHandle.Set3DShapeVisible(_data.BoxIndex, false);
|
||||
_data.CapHandle.Set3DShapeVisible(_data.SphereIndex, false);
|
||||
_data.CapHandle.Set3DShapeVisible(_data.PyramidIndex, _data.Cap.IsVisible);
|
||||
}
|
||||
|
||||
public override void UpdateTransforms(float zoomFactor)
|
||||
{
|
||||
var cap = _data.Cap;
|
||||
|
||||
_data.Pyramid.BaseCenter = cap.Position;
|
||||
_data.Pyramid.Rotation = cap.Rotation;
|
||||
_data.Pyramid.BaseWidth = cap.GetRealPyramidWidth(zoomFactor);
|
||||
_data.Pyramid.BaseDepth = cap.GetRealPyramidDepth(zoomFactor);
|
||||
_data.Pyramid.Height = cap.GetRealPyramidHeight(zoomFactor);
|
||||
}
|
||||
|
||||
public override void CapSlider3D(Vector3 sliderDirection, Vector3 sliderEndPt, float zoomFactor)
|
||||
{
|
||||
_data.Cap.AlignTransformAxis(1, AxisSign.Positive, sliderDirection);
|
||||
_data.Cap.Position = sliderEndPt;
|
||||
}
|
||||
|
||||
public override void CapSlider3DInvert(Vector3 sliderDirection, Vector3 sliderEndPt, float zoomFactor)
|
||||
{
|
||||
_data.Cap.AlignTransformAxis(1, AxisSign.Positive, -sliderDirection);
|
||||
_data.Cap.Position = sliderEndPt + sliderDirection * GetSliderAlignedRealLength(zoomFactor);
|
||||
}
|
||||
|
||||
public override float GetSliderAlignedRealLength(float zoomFactor)
|
||||
{
|
||||
return _data.Cap.GetRealPyramidHeight(zoomFactor);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7d87710c58597484f933597dc0bf3678
|
||||
timeCreated: 1516299808
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,47 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace RTG
|
||||
{
|
||||
public class GizmoSphereCap3DController : GizmoCap3DController
|
||||
{
|
||||
public GizmoSphereCap3DController(GizmoCap3DControllerData controllerData)
|
||||
:base(controllerData)
|
||||
{
|
||||
}
|
||||
|
||||
public override void UpdateHandles()
|
||||
{
|
||||
_data.CapHandle.Set3DShapeVisible(_data.ConeIndex, false);
|
||||
_data.CapHandle.Set3DShapeVisible(_data.TrPrismIndex, false);
|
||||
_data.CapHandle.Set3DShapeVisible(_data.BoxIndex, false);
|
||||
_data.CapHandle.Set3DShapeVisible(_data.PyramidIndex, false);
|
||||
_data.CapHandle.Set3DShapeVisible(_data.SphereIndex, _data.Cap.IsVisible);
|
||||
}
|
||||
|
||||
public override void UpdateTransforms(float zoomFactor)
|
||||
{
|
||||
var cap = _data.Cap;
|
||||
|
||||
_data.Sphere.Center = cap.Position;
|
||||
_data.Sphere.Rotation = cap.Rotation;
|
||||
_data.Sphere.Radius = cap.GetRealSphereRadius(zoomFactor);
|
||||
}
|
||||
|
||||
public override void CapSlider3D(Vector3 sliderDirection, Vector3 sliderEndPt, float zoomFactor)
|
||||
{
|
||||
_data.Cap.AlignTransformAxis(0, AxisSign.Positive, sliderDirection);
|
||||
_data.Cap.Position = sliderEndPt + sliderDirection * _data.Sphere.Radius;
|
||||
}
|
||||
|
||||
public override void CapSlider3DInvert(Vector3 sliderDirection, Vector3 sliderEndPt, float zoomFactor)
|
||||
{
|
||||
_data.Cap.AlignTransformAxis(0, AxisSign.Positive, -sliderDirection);
|
||||
_data.Cap.Position = sliderEndPt + sliderDirection * _data.Cap.GetRealSphereRadius(zoomFactor);
|
||||
}
|
||||
|
||||
public override float GetSliderAlignedRealLength(float zoomFactor)
|
||||
{
|
||||
return _data.Cap.GetRealSphereRadius(zoomFactor) * 2.0f;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5101bd69f586bf94aba9d24b828ce987
|
||||
timeCreated: 1516304344
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,51 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace RTG
|
||||
{
|
||||
public class GizmoTriPrismCap3DController : GizmoCap3DController
|
||||
{
|
||||
public GizmoTriPrismCap3DController(GizmoCap3DControllerData controllerData)
|
||||
:base(controllerData)
|
||||
{
|
||||
}
|
||||
|
||||
public override void UpdateHandles()
|
||||
{
|
||||
_data.CapHandle.Set3DShapeVisible(_data.ConeIndex, false);
|
||||
_data.CapHandle.Set3DShapeVisible(_data.SphereIndex, false);
|
||||
_data.CapHandle.Set3DShapeVisible(_data.BoxIndex, false);
|
||||
_data.CapHandle.Set3DShapeVisible(_data.PyramidIndex, false);
|
||||
_data.CapHandle.Set3DShapeVisible(_data.TrPrismIndex, _data.Cap.IsVisible);
|
||||
}
|
||||
|
||||
public override void UpdateTransforms(float zoomFactor)
|
||||
{
|
||||
var cap = _data.Cap;
|
||||
|
||||
_data.TrPrism.Rotation = cap.Rotation;
|
||||
_data.TrPrism.Width = cap.GetRealTriPrismWidth(zoomFactor);
|
||||
_data.TrPrism.Height = cap.GetRealTriPrismHeight(zoomFactor);
|
||||
_data.TrPrism.Depth = cap.GetRealTriPrismDepth(zoomFactor);
|
||||
_data.TrPrism.FrontCenter = cap.Position;
|
||||
}
|
||||
|
||||
public override void CapSlider3D(Vector3 sliderDirection, Vector3 sliderEndPt, float zoomFactor)
|
||||
{
|
||||
_data.Cap.Rotation = Quaternion.identity;
|
||||
_data.Cap.AlignTransformAxis(2, AxisSign.Positive, sliderDirection);
|
||||
_data.Cap.Position = sliderEndPt;
|
||||
}
|
||||
|
||||
public override void CapSlider3DInvert(Vector3 sliderDirection, Vector3 sliderEndPt, float zoomFactor)
|
||||
{
|
||||
_data.Cap.Rotation = Quaternion.identity;
|
||||
_data.Cap.AlignTransformAxis(2, AxisSign.Positive, -sliderDirection);
|
||||
_data.Cap.Position = sliderEndPt + sliderDirection * GetSliderAlignedRealLength(zoomFactor);
|
||||
}
|
||||
|
||||
public override float GetSliderAlignedRealLength(float zoomFactor)
|
||||
{
|
||||
return _data.Cap.GetRealTriPrismDepth(zoomFactor);
|
||||
}
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user