Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[2017.2.1.4] Fix building on Unity 5.6 and 2017.1 #1963

Merged
merged 5 commits into from
Apr 17, 2018
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,14 @@ namespace HoloToolkit.Unity
/// </summary>
public static class InteractionSourceExtensions
{
#if UNITY_2017_2_OR_NEWER
#if UNITY_EDITOR_WIN && UNITY_WSA
[DllImport("EditorMotionController")]
private static extern bool StartHaptics([In] uint controllerId, [In] float intensity, [In] float durationInSeconds);

[DllImport("EditorMotionController")]
private static extern bool StopHaptics([In] uint controllerId);
#endif
#endif // UNITY_EDITOR_WIN && UNITY_WSA

// This value is standardized according to www.usb.org/developers/hidpage/HUTRR63b_-_Haptics_Page_Redline.pdf
private const ushort ContinuousBuzzWaveform = 0x1004;
Expand All @@ -52,7 +53,7 @@ public static void StartHaptics(this InteractionSource interactionSource, float
return;
}

#if !UNITY_EDITOR && UNITY_2017_2_OR_NEWER
#if !UNITY_EDITOR
UnityEngine.WSA.Application.InvokeOnUIThread(() =>
{
IReadOnlyList<SpatialInteractionSourceState> sources = SpatialInteractionManager.GetForCurrentView().GetDetectedSourcesAtTimestamp(PerceptionTimestampHelper.FromHistoricalTargetTime(DateTimeOffset.Now));
Expand Down Expand Up @@ -80,9 +81,9 @@ public static void StartHaptics(this InteractionSource interactionSource, float
}
}
}, true);
#elif UNITY_EDITOR_WIN && UNITY_2017_2_OR_NEWER
#elif UNITY_EDITOR_WIN
StartHaptics(interactionSource.id, intensity, durationInSeconds);
#endif
#endif // !UNITY_EDITOR
}

public static void StopHaptics(this InteractionSource interactionSource)
Expand All @@ -92,7 +93,7 @@ public static void StopHaptics(this InteractionSource interactionSource)
return;
}

#if !UNITY_EDITOR && UNITY_2017_2_OR_NEWER
#if !UNITY_EDITOR
UnityEngine.WSA.Application.InvokeOnUIThread(() =>
{
IReadOnlyList<SpatialInteractionSourceState> sources = SpatialInteractionManager.GetForCurrentView().GetDetectedSourcesAtTimestamp(PerceptionTimestampHelper.FromHistoricalTargetTime(DateTimeOffset.Now));
Expand All @@ -105,12 +106,12 @@ public static void StopHaptics(this InteractionSource interactionSource)
}
}
}, true);
#elif UNITY_EDITOR_WIN && UNITY_2017_2_OR_NEWER
#elif UNITY_EDITOR_WIN
StopHaptics(interactionSource.id);
#endif
#endif // !UNITY_EDITOR
}

#if !UNITY_EDITOR && UNITY_2017_2_OR_NEWER
#if !UNITY_EDITOR
public static IAsyncOperation<IRandomAccessStreamWithContentType> TryGetRenderableModelAsync(this InteractionSource interactionSource)
{
IAsyncOperation<IRandomAccessStreamWithContentType> returnValue = null;
Expand All @@ -133,7 +134,8 @@ public static IAsyncOperation<IRandomAccessStreamWithContentType> TryGetRenderab

return returnValue;
}
#endif
#endif
#endif // !UNITY_EDITOR
#endif // UNITY_WSA
#endif // UNITY_2017_2_OR_NEWER
}
}
6 changes: 5 additions & 1 deletion Assets/HoloToolkit/Input/Scripts/Focus/FocusManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,11 @@ public GameObject TryGetFocusedObject(BaseEventData eventData)
TryGetPointingSource(eventData, out pointingSource);
PointerInputEventData pointerInputEventData = GetSpecificPointerEventData(pointingSource);

Debug.Assert(pointerInputEventData != null);
// GetSpecificPointerEventData can return null. Be sure to handle that case.
if (pointerInputEventData == null)
{
return null;
}
return pointerInputEventData.selectedObject;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ private void ApplyScale(Vector3 currentHandPosition)
}
private void ApplyRotation(Quaternion currentHandOrientation)
{
#if UNITY_2017_1_OR_NEWER
Matrix4x4 m = Matrix4x4.Rotate(initialHandOrientation);
Vector3 initRay = new Vector3(0, 0, 1);
initRay = m.MultiplyPoint(initRay);
Expand Down Expand Up @@ -260,6 +261,9 @@ private void ApplyRotation(Quaternion currentHandOrientation)
transformToAffect.localRotation = initialRotation;
transformToAffect.Rotate(axis, angle * 5.0f);
}
#else
#warning "ApplyRotation(Quaternion currentHandOrientation) is not supported on this version of Unity. Recommend updating to 2017.1 or newer."
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if we should warn people about this, in this way.

#endif // UNITY_2017_1_OR_NEWER
}
private void ApplyRotation(Vector3 currentHandPosition)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -489,13 +489,16 @@ private List<Vector3> GetBounds()
BoundingBox.GetMeshFilterBoundsPoints(clone, bounds, mask);
Vector3 centroid = boxInstance.TargetBoundsCenter;
GameObject.Destroy(clone);
#if UNITY_2017_1_OR_NEWER
Matrix4x4 m = Matrix4x4.Rotate(objectToBound.transform.rotation);
for (int i = 0; i < bounds.Count; ++i)
{
bounds[i] = m.MultiplyPoint(bounds[i]);
bounds[i] += boxInstance.TargetBoundsCenter;
}

#else
#warning "GetBounds() using rotation is not supported on this version of Unity. Recommend updating to 2017.1 or newer."
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if we should warn people about this, in this way.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair enough. I can remove those.

#endif // UNITY_2017_1_OR_NEWER
return bounds;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@
// Licensed under the MIT License. See LICENSE in the project root for license information.
using System.Collections.Generic;
using UnityEngine;
#if UNITY_2017_1_OR_NEWER
using UnityEngine.U2D;
#endif // UNITY_2017_1_OR_NEWER

namespace HoloToolkit.Unity
{
public class AtlasPrefabReference : ScriptableObject
{
#if UNITY_2017_1_OR_NEWER
[SerializeField] public List<GameObject> Prefabs;
[SerializeField] public SpriteAtlas Atlas;
#endif // UNITY_2017_1_OR_NEWER
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ namespace HoloToolkit.Unity
[InitializeOnLoad]
public class AtlasReferenceUpdater : UnityEditor.AssetModificationProcessor
{
#if UNITY_2017_1_OR_NEWER
private static readonly List<AtlasPrefabReference> References = new List<AtlasPrefabReference>();

static AtlasReferenceUpdater()
Expand Down Expand Up @@ -115,5 +116,6 @@ private static IEnumerable<Sprite> GetDistinctSprites(IEnumerable<GameObject> pr
return prefabs.SelectMany(p => p.GetComponentsInChildren<Image>())
.Select(img => img.sprite).Where(img => img != null).Distinct();
}
#endif // UNITY_2017_1_OR_NEWER
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ namespace HoloToolkit.Unity
{
public static class SpriteAtlasExtensions
{
// SpriteAtlast requires Unity 2017.1 or later
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: typo: SpriteAtlast

#if UNITY_2017_1_OR_NEWER
public const string SpritePackables = "m_EditorData.packables";

public static void SetSprites(this SpriteAtlas spriteAtlas, IList<Sprite> sprites)
Expand All @@ -31,5 +33,6 @@ public static bool ContainsSprite(this SpriteAtlas spriteAtlas, Sprite sprite)
}
return false;
}
#endif // UNITY_2017_1_OR_NEWER
}
}