Skip to content

Commit

Permalink
Merge pull request #314 from Unity-Technologies/staging
Browse files Browse the repository at this point in the history
0.0.8 staging -> master
  • Loading branch information
AndrewTHEManeri authored Sep 30, 2017
2 parents 7254d60 + 03475c5 commit 64df4e6
Show file tree
Hide file tree
Showing 658 changed files with 31,562 additions and 7,274 deletions.
8 changes: 2 additions & 6 deletions Actions/Clone.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#if UNITY_EDITOR
using System;
using UnityEditor.Experimental.EditorVR.Utilities;
using UnityEngine;

Expand All @@ -10,23 +9,20 @@ sealed class Clone : BaseAction, IUsesSpatialHash, IUsesViewerScale
{
public override void ExecuteAction()
{
Unsupported.DuplicateGameObjectsUsingPasteboard();
var selection = Selection.transforms;
var clones = new GameObject[selection.Length];
var index = 0;
var bounds = ObjectUtils.GetBounds(selection);
foreach (var s in selection)
{
var clone = ObjectUtils.Instantiate(s.gameObject);
var clone = s.gameObject;
clone.hideFlags = HideFlags.None;
var cloneTransform = clone.transform;
var cameraTransform = CameraUtils.GetMainCamera().transform;
var viewDirection = cloneTransform.position - cameraTransform.position;
cloneTransform.position = cameraTransform.TransformPoint(Vector3.forward * viewDirection.magnitude / this.GetViewerScale())
+ cloneTransform.position - bounds.center;
this.AddToSpatialHash(clone);
clones[index++] = clone;
}
Selection.objects = clones;
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion Actions/Copy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ sealed class Copy : BaseAction
{
public override void ExecuteAction()
{
Paste.buffer = Selection.transforms;
Unsupported.CopyGameObjectsToPasteboard();
Paste.SetBufferDistance(Selection.transforms);
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion Actions/Cut.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,16 @@ public override void ExecuteAction()
var selection = Selection.transforms;
if (selection != null)
{
Unsupported.CopyGameObjectsToPasteboard();
Paste.SetBufferDistance(Selection.transforms);

foreach (var transform in selection)
{
var go = transform.gameObject;
go.hideFlags = HideFlags.HideAndDontSave;
go.SetActive(false);
}

Paste.buffer = selection;
Selection.activeGameObject = null;
}
}
Expand Down
56 changes: 19 additions & 37 deletions Actions/Paste.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#if UNITY_EDITOR
using System;
using UnityEditor.Experimental.EditorVR.Utilities;
using UnityEngine;

Expand All @@ -8,51 +7,34 @@ namespace UnityEditor.Experimental.EditorVR.Actions
[ActionMenuItem("Paste", ActionMenuItemAttribute.DefaultActionSectionName, 6)]
sealed class Paste : BaseAction, IUsesSpatialHash, IUsesViewerScale
{
public static Transform[] buffer
static float s_BufferDistance;

public static void SetBufferDistance(Transform[] transforms)
{
get
{
return s_Buffer;
}
set
if (transforms != null)
{
s_Buffer = value;
var bounds = ObjectUtils.GetBounds(transforms);

if (value != null)
{
var bounds = ObjectUtils.GetBounds(value);

s_BufferDistance = bounds.size != Vector3.zero ? (bounds.center - CameraUtils.GetMainCamera().transform.position).magnitude : 0f;
s_BufferDistance /= IUsesViewerScaleMethods.getViewerScale(); // Normalize this value, so if viewer scale changes when pasted
}
s_BufferDistance = bounds.size != Vector3.zero ? (bounds.center - CameraUtils.GetMainCamera().transform.position).magnitude : 1f;
s_BufferDistance /= IUsesViewerScaleMethods.getViewerScale(); // Normalize this value in case viewer scale changes before paste happens
}
}
static Transform[] s_Buffer;

static float s_BufferDistance;

public override void ExecuteAction()
{
if (buffer != null)
Unsupported.PasteGameObjectsFromPasteboard();
var transforms = Selection.transforms;
var bounds = ObjectUtils.GetBounds(transforms);
foreach (var transform in transforms)
{
var pastedGameObjects = new GameObject[buffer.Length];
var index = 0;
var bounds = ObjectUtils.GetBounds(buffer);
foreach (var transform in buffer)
{
var pasted = Instantiate(transform.gameObject);
var pastedTransform = pasted.transform;
pasted.hideFlags = HideFlags.None;
var cameraTransform = CameraUtils.GetMainCamera().transform;
pastedTransform.position = cameraTransform.TransformPoint(Vector3.forward * s_BufferDistance)
+ pastedTransform.position - bounds.center;
pasted.SetActive(true);
this.AddToSpatialHash(pasted);
pastedGameObjects[index++] = pasted;
}

if (pastedGameObjects.Length > 0)
Selection.objects = pastedGameObjects;
var pasted = transform.gameObject;
var pastedTransform = pasted.transform;
pasted.hideFlags = HideFlags.None;
var cameraTransform = CameraUtils.GetMainCamera().transform;
pastedTransform.position = cameraTransform.TransformPoint(Vector3.forward * s_BufferDistance)
+ pastedTransform.position - bounds.center;
pasted.SetActive(true);
this.AddToSpatialHash(pasted);
}
}
}
Expand Down
136 changes: 136 additions & 0 deletions Editor/HapticPulsesEditor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
using System.Collections.Generic;
using UnityEditor.Experimental.EditorVR.Core;
using UnityEditor.Experimental.EditorVR.Modules;
using UnityEngine;

namespace UnityEditor.Experimental.EditorVR.UI
{
sealed class HapticPulseEditor : EditorWindow
{
class Pulse
{
public HapticPulse pulse;
public SerializedObject serializedObject;
public SerializedProperty duration;
public SerializedProperty intensity;
}

readonly List<Pulse> m_HapticPulses = new List<Pulse>();

Vector2 m_Scroll;
float m_Multiplier = 1;

[MenuItem("Edit/Project Settings/EditorVR/Haptic Pulses")]
static void Init()
{
GetWindow<HapticPulseEditor>("Haptic Pulse Editor").Show();
}

void OnEnable()
{
Reset();

Undo.undoRedoPerformed += OnUndoRedo;
}

void Reset()
{
m_HapticPulses.Clear();
var pulses = AssetDatabase.FindAssets("t:HapticPulse");
foreach (var guid in pulses)
{
var pulse = AssetDatabase.LoadAssetAtPath<HapticPulse>(AssetDatabase.GUIDToAssetPath(guid));
if (pulse)
{
var serializedObject = new SerializedObject(pulse);
m_HapticPulses.Add(new Pulse
{
pulse = pulse,
serializedObject = serializedObject,
duration = serializedObject.FindProperty("m_Duration"),
intensity = serializedObject.FindProperty("m_Intensity")
});
}
}
}

void OnDisable()
{
Undo.undoRedoPerformed -= OnUndoRedo;
}

void OnGUI()
{
if (Event.current.Equals(Event.KeyboardEvent("^w")))
{
Close();
GUIUtility.ExitGUI();
}

const float nameColumnWidth = 250f;
const float floatFieldColumnWidth = 60f;

m_Scroll = GUILayout.BeginScrollView(m_Scroll);

GUILayout.BeginHorizontal();
m_Multiplier = EditorGUILayout.FloatField("Multiplier", m_Multiplier);
if (GUILayout.Button("Multiply Intensity"))
{
foreach (var pulse in m_HapticPulses)
{
pulse.intensity.floatValue *= m_Multiplier;
pulse.serializedObject.ApplyModifiedProperties();
}
}

if (GUILayout.Button("Multiply Duration"))
{
foreach (var pulse in m_HapticPulses)
{
pulse.duration.floatValue *= m_Multiplier;
pulse.serializedObject.ApplyModifiedProperties();
}
}
GUILayout.EndHorizontal();

GUILayout.BeginHorizontal();
GUILayout.Label("Haptic Pulses", EditorStyles.boldLabel, GUILayout.Width(nameColumnWidth));
GUILayout.Label("Duration");
GUILayout.Label("Intensity");
GUILayout.EndHorizontal();

foreach (var pulse in m_HapticPulses)
{
GUILayout.BeginHorizontal();
EditorGUILayout.ObjectField(pulse.pulse, typeof(HapticPulse), false, GUILayout.Width(nameColumnWidth));
EditorGUI.BeginChangeCheck();
var durationProperty = pulse.duration;
durationProperty.floatValue = GUILayout.HorizontalSlider(durationProperty.floatValue, 0, HapticsModule.MaxDuration);
durationProperty.floatValue = EditorGUILayout.FloatField(durationProperty.floatValue, GUILayout.Width(floatFieldColumnWidth));
durationProperty.floatValue = Mathf.Clamp(durationProperty.floatValue, 0, HapticsModule.MaxDuration);
var intensityProperty = pulse.intensity;
intensityProperty.floatValue = GUILayout.HorizontalSlider(intensityProperty.floatValue, 0, 1);
intensityProperty.floatValue = EditorGUILayout.FloatField(intensityProperty.floatValue, GUILayout.Width(floatFieldColumnWidth));
intensityProperty.floatValue = Mathf.Clamp01(intensityProperty.floatValue);
if (EditorGUI.EndChangeCheck())
pulse.serializedObject.ApplyModifiedProperties();

GUILayout.EndHorizontal();
}

GUILayout.EndScrollView();
}

void OnUndoRedo()
{
Reset();
Repaint();
}

void OnProjectChange()
{
Reset();
Repaint();
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions Editor/TooltipsEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@ void CollectTooltipAttributes(Type type)

void OnGUI()
{
if (Event.current.Equals(Event.KeyboardEvent("^w")))
{
Close();
GUIUtility.ExitGUI();
}

const float columnWidth = 250f;
EditorGUIUtility.labelWidth = columnWidth;

Expand Down
Loading

0 comments on commit 64df4e6

Please sign in to comment.