/// <summary> /// /// </summary> public void UpdatePress() { if (!IsReady) { return; } _updateRayAndHit(); if (Physics.Raycast(_ray, out _hit)) { Vector3 pos = _hit.collider.gameObject.transform.position - _ray.origin; _distance = Mathf.Min(_maxDistance, pos.magnitude); } if (_hit.collider != null) { _obj = _hit.collider.GetComponent <SWindow>(); } _position = _ray.origin + _ray.direction * _distance; if (_obj != null) { Vector3 pos = _obj.transform.position - _ray.origin; _maxDistance = pos.magnitude; _obj.OnClicked(_position, -_ray.direction); } Debug.DrawLine(_ray.origin, _position, Color.magenta); }
//Listeners /// <summary> /// Collider Manager (Enter) /// </summary> /// <param name="other"></param> private void OnTriggerEnter(Collider other) { if (other.transform == _parent) { return; } if (_updateLogic == null) { return; } if (!other.gameObject) { return; } SWindow cmpt = other.gameObject.GetComponent <SWindow>(); if (!cmpt) { return; } _listCollidedSWindows.Add(cmpt); }
/// <summary> /// /// </summary> public void UpdateRelease() { if (!IsReady) { return; } _updateRayAndHit(); if (Physics.Raycast(_ray, out _hit)) { Vector3 pos = _hit.collider.gameObject.transform.position - _ray.origin; _distance = Mathf.Min(_maxDistance, pos.magnitude); } _maxDistance = 10.0f; _position = _ray.origin + _ray.direction * _distance; if (_obj != null) { _obj.OnReleased(_position, -_ray.direction); _obj.Blurring(); _obj = null; } Debug.DrawLine(_ray.origin, _ray.origin + _ray.direction, Color.magenta); }
public void AddSWindow(SWindow child) { _childrenList.Add(child); child.DoGrouping(transform); Refresh(); }
// Use this for initialization public SPointerLogic() { _primaryHand = null; _position = Vector3.zero; _maxDistance = _distance = 10.0f; _ray = new Ray(); _obj = null; }
public void Refresh() { //All children Assignment Index for Sorting for (int idx = 0; idx < _childrenList.Count; idx++) { SWindow sw = _childrenList[idx]; sw.SetID(idx, _childrenList.Count); } }
public void UpdateCheckingGrouping() { if (_group == GROUP.Done) { return; } _ray.origin = transform.position + _rayPosition; _ray.direction = -transform.forward; //Search Object For Grouping if (_group == GROUP.Ready && Physics.Raycast(_ray, out _hit, 1.0f) && _hit.transform != null && _hit.transform.GetComponent <SWindow>()._group != GROUP.Done) { SWindow coord = _hit.transform.GetComponent <SWindow>(); if (coord != null && coord == _groupingCoord) { _groupingTimer += Time.deltaTime; if (_groupingTimer > 1.0f) { if (_groupingCoord is SWindowGroup) { _swTmp = _groupingCoord as SWindowGroup; } else { Vector3 targetPosition = (transform.position + _groupingCoord.transform.position) * 0.5f; Quaternion targetRotation = Quaternion.Lerp(transform.rotation, _groupingCoord.transform.rotation, 0.5f); Transform parent = GameObject.Find("_Windows").transform; GameObject go = Instantiate(_prefabGroup, targetPosition, targetRotation, parent); _swTmp = go.GetComponent <SWindowGroup>(); go.SetActive(true); } _groupingTimer = 0.0f; _updateGrouping = UpdateCreatingGrouping; } } else { _groupingCoord = coord; _groupingTimer = 0.0f; } } else { _groupingCoord = null; } }
public void UpdateCreatingGrouping() { _ray.origin = transform.position + _rayPosition; _ray.direction = -transform.forward; //Search Object For Grouping if (_group == GROUP.Ready) { if ( Physics.Raycast(_ray, out _hit, 1.0f) && _hit.transform != null && (_hit.transform.GetComponent <SWindow>() == _groupingCoord || _hit.transform.GetComponent <SWindow>() == _swTmp)) { return; } else { if (_groupingCoord != _swTmp) { _swTmp.Remove(); _swTmp = null; } _groupingCoord = null; _updateGrouping = UpdateCheckingGrouping; return; } } else { if (_groupingCoord != _swTmp) { _swTmp.AddSWindow(_groupingCoord); } _swTmp.AddSWindow(this); _swTmp.Setup(); //Fix & _swTmp = null; _groupingCoord = null; _updateGrouping = UpdateCheckingGrouping; return; } }
/// <summary> /// /// </summary> public void UpdateIdle() { if (!IsReady) { return; } _updateRayAndHit(); if (Physics.Raycast(_ray, out _hit)) { _distance = Mathf.Min(_maxDistance, _hit.distance); } else { if (_obj != null) { _obj.Blurring(); } _obj = null; } if (_hit.collider != null) { _obj = _hit.collider.GetComponent <SWindow>(); } _position = _ray.origin + _ray.direction * _distance; if (_obj != null) { Vector3 pos = _obj.transform.position - _ray.origin; _maxDistance = pos.magnitude; _obj.Focusing(); } Debug.DrawLine(_ray.origin, _position, Color.gray); }
/// <summary> /// Collider Manager (Exit) /// </summary> /// <param name="other"></param> private void OnTriggerExit(Collider other) { if (other.transform == _parent) { return; } if (!other.gameObject) { return; } SWindow cmpt = other.gameObject.GetComponent <SWindow>(); if (!cmpt) { return; } if (!_listCollidedSWindows.Remove(cmpt)) { return; } }