// Copyright © 2018, Meta Company. All rights reserved.
//
// Redistribution and use of this software (the "Software") in binary form, without modification, is
// permitted provided that the following conditions are met:
//
// 1. Redistributions of the unmodified Software in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
// 2. The name of Meta Company (“Meta”) may not be used to endorse or promote products derived
// from this Software without specific prior written permission from Meta.
// 3. LIMITATION TO META PLATFORM: Use of the Software is limited to use on or in connection
// with Meta-branded devices or Meta-branded software development kits. For example, a bona
// fide recipient of the Software may incorporate an unmodified binary version of the
// Software into an application limited to use on or in connection with a Meta-branded
// device, while he or she may not incorporate an unmodified binary version of the Software
// into an application designed or offered for use on a non-Meta-branded device.
//
// For the sake of clarity, the Software may not be redistributed under any circumstances in source
// code form, or in the form of modified binary code – and nothing in this License shall be construed
// to permit such redistribution.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
// INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
// PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL META COMPANY BE LIABLE FOR ANY DIRECT,
// INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
using Meta.Extensions;
using UnityEngine;
namespace Meta
{
/// <summary>
/// Interaction to scale model by placing two hands into the model and grabbing.
/// </summary>
[AddComponentMenu("Meta/Interaction/TwoHandGrabScaleInteraction")]
public class TwoHandGrabScaleInteraction : TwoHandInteraction
{
/// <summary>
/// Minimum scale
/// </summary>
[SerializeField]
private Vector2 _minSize = new Vector2(.3f, .3f);
/// <summary>
/// Maximum scale
/// </summary>
[SerializeField]
private Vector2 _maxSize = new Vector2(2, 2);
public GameObject bottomPos;
/// <summary>
/// Whether to size delta for the TargetTransform should be changed. If false, the local scale will be used.
/// </summary>
[SerializeField]
private bool _scaleSizeDelta = false;
[SerializeField]
private Vector3UnityEvent _scaleChanged = new Vector3UnityEvent();
[Tooltip("Make objects scale exponentially using a gamma scale power rather than linearly")]
[SerializeField]
private bool _exponentialScaling = false;
public new Vector3 newScaleP;
public new Vector3 newCenterPos;
public float localScaleY;
private float _priorDistance;
private RectTransform _rectTransform;
private const float _gammaScalePower = 1.4f;
/// <summary>
/// Minimum scale
/// </summary>
public Vector2 MinSize
{
get { return _minSize; }
set { _minSize = value; }
}
/// <summary>
/// Maximum scale
/// </summary>
public Vector2 MaxSize
{
get { return _maxSize; }
set { _maxSize = value; }
}
public Vector3UnityEvent ScaleChanged
{
get { return _scaleChanged; }
}
protected override void Engage()
{
_priorDistance = Vector3.Distance(FirstGrabbingHand.transform.position,SecondGrabbingHand.transform.position);
PrepareRigidbodyForInteraction();
base.Engage();
}
protected override void Disengage()
{
RestoreRigidbodySettingsAfterInteraction();
base.Disengage();
}
protected override void Manipulate()
{
newCenterPos = TargetTransform.position;
newCenterPos.y = (FirstGrabbingHand.transform.position.y + bottomPos.transform.position.y) / 2f;
Vector3 center = newCenterPos;
//(FirstGrabbingHand.transform.position + SecondGrabbingHand.transform.position) / 2f;
Vector3 offset = Vector3.zero;
//TargetTransform.position - center;
float currentDistance = Vector3.Distance(FirstGrabbingHand.transform.position,
SecondGrabbingHand.transform.position);
float multiplier = currentDistance / _priorDistance;
multiplier = Mathf.Clamp(multiplier, .5f, 1.5f);
if (_exponentialScaling)
{
multiplier = Mathf.Pow(multiplier, _gammaScalePower);
}
RectTransform rectTransform = TargetTransform as RectTransform;
if (rectTransform != null && _scaleSizeDelta)
{
Vector2 newSize = rectTransform.sizeDelta * multiplier;
if (newSize.IsNaN())
{
return;
}
if (newSize.x < _maxSize.x && newSize.y < _maxSize.y && newSize.x > _minSize.x && newSize.y > _minSize.y)
{
rectTransform.sizeDelta = newSize;
OnScaleChanged(newSize);
Move(center + (offset * multiplier));
}
}
else
{
Vector3 newScale = TargetTransform.localScale * multiplier;
if (newScale.IsNaN())
{
return;
}
if (newScale.x < _maxSize.x && newScale.y < _maxSize.y && newScale.x > _minSize.x && newScale.y > _minSize.y)
{
newScaleP = TargetTransform.localScale;
newScaleP.y = newScale.y;
TargetTransform.localScale = newScaleP;
OnScaleChanged(newScale);
Move(center + (offset * multiplier));
}
}
_priorDistance = currentDistance;
}
private void OnScaleChanged(Vector3 scale)
{
_scaleChanged.Invoke(scale);
}
}
}
// Copyright © 2018, Meta Company. All rights reserved.
//
// Redistribution and use of this software (the "Software") in binary form, without modification, is
// permitted provided that the following conditions are met:
//
// 1. Redistributions of the unmodified Software in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
// 2. The name of Meta Company (“Meta”) may not be used to endorse or promote products derived
// from this Software without specific prior written permission from Meta.
// 3. LIMITATION TO META PLATFORM: Use of the Software is limited to use on or in connection
// with Meta-branded devices or Meta-branded software development kits. For example, a bona
// fide recipient of the Software may incorporate an unmodified binary version of the
// Software into an application limited to use on or in connection with a Meta-branded
// device, while he or she may not incorporate an unmodified binary version of the Software
// into an application designed or offered for use on a non-Meta-branded device.
//
// For the sake of clarity, the Software may not be redistributed under any circumstances in source
// code form, or in the form of modified binary code – and nothing in this License shall be construed
// to permit such redistribution.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
// INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
// PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL META COMPANY BE LIABLE FOR ANY DIRECT,
// INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
using Meta.HandInput;
using Meta.Extensions;
using UnityEngine;
namespace Meta
{
/// <summary>
/// Interaction to grab the model to translate its position.
/// </summary>
[AddComponentMenu("Meta/Interaction/GrabInteraction")]
public class GrabInteraction : Interaction
{
private HandFeature _handFeature;
public GameObject bottomPosition;
public Vector3 newCenterPos;
private float _PriorDistance;
public Vector3 newScaleP;
private Vector3UnityEvent _scaleChanged = new Vector3UnityEvent();
private Vector3 _localOffset;
protected override bool CanEngage(Hand handProxy)
{
return GrabbingHands.Count == 1;
}
protected override void Engage()
{
_handFeature = GrabbingHands[0];
PrepareRigidbodyForInteraction();
_PriorDistance = Vector3.Distance(_handFeature.transform.position, bottomPosition.transform.position);
// Store the offset of the object local to the hand feature. This will be used to keep the object at the same distance from the hand when being moved.
SetHandOffsets();
}
public Vector3UnityEvent ScaleChanged
{
get { return _scaleChanged; }
}
protected override bool CanDisengage(Hand handProxy)
{
if (_handFeature != null && handProxy.Palm == _handFeature)
{
foreach (var hand in GrabbingHands)
{
if (hand != _handFeature)
{
_handFeature = hand;
SetHandOffsets();
return false;
}
}
return true;
}
return false;
}
protected override void Disengage()
{
Manipulate();
RestoreRigidbodySettingsAfterInteraction();
_handFeature = null;
}
protected override void Manipulate()
{
Move((TransformedHandPos() + bottomPosition.transform.position) / 2f);
newCenterPos = TargetTransform.position;
newCenterPos.y = (_handFeature.transform.position.y + bottomPosition.transform.position.y) / 2f;
float currentDistance = Vector3.Distance(_handFeature.transform.position, bottomPosition.transform.position);
float multiplier = currentDistance / _PriorDistance;
multiplier = Mathf.Clamp(multiplier, 0.5f, 1.5f);
Vector3 newScale = TargetTransform.localScale * multiplier;
newScaleP = TargetTransform.localScale;
newScaleP.y = newScale.y;
TargetTransform.localScale = newScaleP;
OnScaleChanged(newScale);
//Vector3 center = newCenterPos;
}
private Vector3 TransformedHandPos()
{
// This complements obtaining the offset - used to convert back to world space.
Vector3 offset = _handFeature.transform.TransformDirection(_localOffset);
Vector3 grabPosition = _handFeature.transform.position + offset;
return grabPosition;
}
private void SetHandOffsets()
{
_localOffset = _handFeature.transform.InverseTransformDirection(TargetTransform.position - _handFeature.Position);
SetGrabOffset(TransformedHandPos());
}
private void OnScaleChanged(Vector3 scale)
{
_scaleChanged.Invoke(scale);
}
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ScaleController : MonoBehaviour {
public GameObject cube;
public GameObject top;
public GameObject bottom;
public Vector3 newScale;
public float defaultDistance;
// Use this for initialization
void Start () {
defaultDistance = Vector3.Distance(top.transform.position, bottom.transform.position);
}
// Update is called once per frame
void Update () {
float currentDistance = Vector3.Distance(top.transform.position, bottom.transform.position);
float multiplier = currentDistance / defaultDistance;
multiplier = Mathf.Clamp(multiplier, 0.5f, 1.5f);
cube.transform.localScale = newScale;
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class TestTarget : MonoBehaviour {
public GameObject cube;
public UnityEngine.AI.NavMeshSurface naveMeshSurface;
public bool hasPath;
private UnityEngine.AI.NavMeshAgent agent;
//UnityEngine.AI.NavMeshPath path;
// Use this for initialization
void Start () {
agent = GetComponent<UnityEngine.AI.NavMeshAgent>();
Debug.Log(hasPath);
}
// Update is called once per frame
void Update () {
GetComponent<UnityEngine.AI.NavMeshAgent>().destination = cube.transform.position;
if(Input.GetKeyDown(KeyCode.A))
{
Debug.Log("A");
naveMeshSurface.BuildNavMesh();
}
//hasPath = agent.CalculatePath(cube.transform.position, path);
if(agent.hasPath == true)
{
Debug.Log("A");
}
else
{
UnityEngine.AI.NavMeshHit navHit;
if (agent.Raycast(cube.transform.position, out navHit))
{
agent.SetDestination(navHit.position);
}
}
//if (agent.pathStatus == UnityEngine.AI.NavMeshPathStatus.PathComplete)
//{
// Debug.Log("A");
//}
//else if (agent.pathStatus == UnityEngine.AI.NavMeshPathStatus.PathInvalid)
//{
// Debug.Log("B");
//}
//else if (agent.pathStatus == UnityEngine.AI.NavMeshPathStatus.PathPartial)
//{
// Debug.Log("C");
//}
}
}