//private NavMeshAgent agent; void Start() { objectVisible = false; if (GetComponent <SnappedObject>()) { snappedObject = GetComponent <SnappedObject> (); } if (type == ObjectType.ReferenceObject) { plane = new Plane(-Camera.main.transform.forward, GetComponent <Collider> ().bounds.center); } //else if (type == ObjectType.AR_Object) //plane = new Plane(-Camera.main.transform.forward, Vector3.zero); startScale = transform.localScale; // startRot = transform.rotation; startPos = transform.localPosition; //if (gameObject.name != "monkey") //{ // _originalColor = GetComponentInChildren<Renderer> ().sharedMaterial.color; //} //CHANGES: ADDED FOR NAVMESH //if(GetComponent<NavMeshAgent>() != null) //{ // agent = GetComponent<NavMeshAgent>(); // agent.enabled = false; //} }
/// <summary> /// This funcion is called when snapper exits the snapping region. /// It calls snappable object's OnSnappedExit if any. /// </summary> protected virtual void OnSnappedExit() { if (SnappedObject != null && !SnappedObject.Equals(null)) { SnappedObject.OnSnappedExit(this); } }
/// <summary> /// This function is called for every FixedUpdate cycle. It checks if /// snapper is now in any snapping region and if so, snaps itself to /// any snappable object. /// </summary> public virtual void SnapUpdate() { // Test if the snapped object is still there (i.e. not destroyed) if (SnappedObject != null && SnappedObject.Equals(null)) { IsSnapped = false; SnappedObject = null; return; } bool isSnappedToTheSameObject; ISnappable firstSnappedObject; IsSnapped = GetSnappingStatus(out isSnappedToTheSameObject, out firstSnappedObject); if (LastSnappingStatus) { if (IsSnapped) { if (isSnappedToTheSameObject) { // All is good. Don't need to do anything. } else { // Snapped to the different object. Do some finish up. // OnSnappedExit for the current snapped object. OnSnappedExit(); SnappedObject = firstSnappedObject; // OnSnappedEnter for the new snapped object. OnSnappedEnter(); } } else { // Not snapped to the object any more. OnSnappedExit(); SnappedObject = null; } } else { if (IsSnapped) { // Start to snap to the object. SnappedObject = firstSnappedObject; OnSnappedEnter(); } else { // Still not snap to anything. Do nothing here. } } if (IsSnapped) { OnSnappedStay(); } LastSnappingStatus = IsSnapped; }
/// <summary> /// Check if the snapper is still moving towards its target position. /// </summary> public void CheckHandMotionInTransition() { if (!IsSnapped) { return; } if (_handMotionInTransitionSnapping) { bool inSnappingTransition = SnappedObject.CheckInSnappingTransition(this); if (!inSnappingTransition) { StopTransition(); } } }