/// <summary> /// This will begin holding the passed in attachable. /// </summary> public void BeginHoldingAttachable(Attachable attachable) { _attached.Add(attachable); switch (_holdBehaviour) { case HoldBehaviour.UpdateLock: if (null != attachable.AttachedRigidbody) { attachable.AttachedRigidbody.isKinematic = true; attachable.MovementInteraction.RetainIsKinematic = true; } break; case HoldBehaviour.Child: //is this really the only way? rigidbody needs to be added back on remove if (null != attachable.AttachedRigidbody) { // Destroy(attachable.AttachedRigidbody); //causes a pauses or will it without meshcolliders? attachable.AttachedRigidbody.isKinematic = true; attachable.MovementInteraction.RetainIsKinematic = true; attachable.AttachedRigidbody.transform.SetParent(transform); } else { attachable.transform.SetParent(transform); } break; } _attachableEvents.Attached.Invoke(attachable, this); }
private void Start() { _attachable = GetComponent <Attachable>(); _attachable.MovementInteraction.Events.ButtonDown.AddListener(ButtonDown); _attachable.MovementInteraction.Events.ButtonsHeld.AddListener(ButtonsHeld); _attachable.MovementInteraction.Events.ButtonUp.AddListener(ButtonUp); _sweepMesh.GetComponent <MeshRenderer>().enabled = false; _stepLength = (int)(1f / stepSize); _sweepVertices = _sweepMesh.sharedMesh.vertices; _lineVertices = new Vector3[_sweepVertices.Length][]; _lineRenderers = new LineRenderer[_sweepVertices.Length]; for (int i = 0; i < _sweepVertices.Length; ++i) { GameObject lineRendererGame = new GameObject("LineRenderer" + i); lineRendererGame.hideFlags = HideFlags.HideAndDontSave; _lineRenderers[i] = lineRendererGame.AddComponent <LineRenderer>(); _lineRenderers[i].castShadows = false; _lineRenderers[i].receiveShadows = false; _lineRenderers[i].colorGradient = _lineGradient.Gradient; _lineRenderers[i].widthMultiplier = _lineWidth; _lineRenderers[i].material = _lineMaterial; _lineRenderers[i].positionCount = _stepLength; _lineRenderers[i].textureMode = LineTextureMode.Tile; _lineRenderers[i].enabled = false; _lineVertices[i] = new Vector3[_stepLength]; } }
public override void Intialize(GuideSequence guideSequence, int index) { base.Intialize(guideSequence, index); _attachable = GetComponent <Attachable>(); _attachable.Events.Attached.AddListener(Attached); _attachable.Events.Entered.AddListener(Entered); _attachable.MovementInteraction.Events.ButtonDown.AddListener(ButtonDown); _attachable.MovementInteraction.Events.ButtonUp.AddListener(ButtonUp); _renderers = _attachable.ParentTransform.GetComponentsInChildren <MeshRenderer>(); if (null != _guideVisual) { _guideVisual.gameObject.SetActive(false); } foreach (AttachableHolder attachableHolder in _attachable.CanAttachTo) { attachableHolder.enabled = false; } if (null != _highlightMaterial) { _highlightMaterial = new Material(_highlightMaterial); _meshFilters = _attachable.MovementInteraction.GetComponentsInChildren <MeshFilter>(); } }
private void Attached(Attachable attachable, AttachableHolder holder) { enabled = false; if (null != _guideVisual) { _guideVisual.gameObject.SetActive(false); } _drawHighlight = false; OnStepCompleted(); Analytics.Add("attachment_accuracy", _enteredRotation / 36f); Debug.Log("attachment_accuracy " + _enteredRotation / 36f); Analytics.Add("drops", Mathf.Clamp(_grabCount, 0, 5)); Debug.Log("drops " + _grabCount); }
/// <summary> /// This will stop holding the passed in attachable. /// </summary> public void StopHoldingAttachable(Attachable attachable) { _attached.Remove(attachable); switch (_holdBehaviour) { case HoldBehaviour.UpdateLock: attachable.ResetIsKinematicState(); break; case HoldBehaviour.Child: throw new NotImplementedException(); //add rigidbody back on if it existed } _attachableEvents.Detached.Invoke(attachable, this); }
public bool CanHold(Attachable attachable) { if (!enabled) { return(false); } if (_canHoldTags.CompareTags(attachable.Tags)) { return(true); } if (attachable.CanAttachTo.Contains(this)) { return(true); } return(false); }
private void Entered(Attachable attachable, AttachableHolder holder) { _enteredRotation = Vector3.Angle(attachable.ParentTransform.up, holder.transform.up); }