Exemplo n.º 1
0
 private void ClearCurrentInternal()
 {
     if (_current != null)
     {
         UICenterTarget.Clear();
         _current.OnControlHovered(false);
     }
     _current           = null;
     _currentGameObject = null;
 }
Exemplo n.º 2
0
 public void CancelDrag()
 {
     _dragging = false;
     UICenterTarget.Clear();
     if (_springJoint == null || _springJoint.connectedBody == null)
     {
         return;
     }
     _springJoint.connectedBody.drag        = _oldDrag;
     _springJoint.connectedBody.angularDrag = _oldAngularDrag;
     _springJoint.connectedBody             = null;
 }
Exemplo n.º 3
0
        void FixedUpdate()
        {
            if (!_dragging)
            {
                return;
            }
            UICenterTarget.SetText("Dragging");
            //      Vector3 point = new Vector3(PlayerInput.LookInput.x, PlayerInput.LookInput.y, _screenPoint.z);
            //Vector3 dest = Player.Camera.ScreenToWorldPoint(point) + _offset;
            //_rigidbody.AddForce((dest - _rigidbody.position) * _pushForce);
            var ray = PlayerInputSystem.GetLookTargetRay;

            _rigidbody.MovePosition(ray.GetPoint(_hitDistance));
        }
Exemplo n.º 4
0
 private void SetNewCurrent(IWorldControl newCurrent, GameObject newGo)
 {
     _foundControl         = true;
     _clearTimer.Triggered = false;
     if (_current == newCurrent)
     {
         return;
     }
     if (_current != null)
     {
         UICenterTarget.Clear();
         _current.OnControlHovered(false);
     }
     _currentGameObject = newGo;
     _current           = newCurrent;
     UICenterTarget.SetText(_current.OnControlHovered(true));
 }
Exemplo n.º 5
0
 void Awake()
 {
     _main = this;
 }
Exemplo n.º 6
0
        void Update()
        {
            if (!Game.GameActive)
            {
                return;
            }
            //if (_debug) {
            //    DebugText.UpdatePermText("World Control", "Game Not Active");
            //}
            //if (GenericDraggableController.Dragging) {
            //    if (_debug) {
            //        DebugText.UpdatePermText("World Control", "Dragging");
            //    }
            //    return;
            //}
            _foundControl = false;
            //_eventData.position = Input.mousePosition;
            //EventSystem.current.RaycastAll(_eventData, _result);
            if (PlayerInput.IsCursorOverUI)
            {
                SetCurrentNull();
                //if (_debug) {
                //    var go = PlayerInput.CurrentInput != null ? PlayerInput.CurrentInput.GameObjectUnderPointer() : null;
                //    DebugText.UpdatePermText("World Control", string.Format("Over UI: {0}", go != null ? go.name :
                //        EventSystem.current.currentSelectedGameObject != null ? EventSystem.current.currentSelectedGameObject.name : " null ?"));
                //}
                return;
            }
            _mouseRay = Cam.ScreenPointToRay(Input.mousePosition);
            Entity currentActor = null;
            var    cnt          = Physics.RaycastNonAlloc(_mouseRay, _hits, _currentEnemyRayDistance, _worldControlsMask);

            _hits.SortByDistanceAsc(cnt);
            for (int i = 0; i < cnt; i++)
            {
                var hit = _hits[i];
                if (!_foundControl)
                {
                    if (hit.transform.gameObject == _currentGameObject)
                    {
                        _foundControl = true;
                        continue;
                    }
                    if (hit.distance <= _currentRayDistance)
                    {
                        hit.transform.GetComponentsInChildren(_tempControls);
                        for (int j = 0; j < _tempControls.Count; j++)
                        {
                            if (_tempControls[j] == null)
                            {
                                continue;
                            }
                            if (_tempControls[j].WorldControlActive)
                            {
                                SetNewCurrent(_tempControls[j], hit.transform.gameObject);
                                _foundControl = true;
                                break;
                            }
                        }
                    }
                }
                if (currentActor == null)
                {
                    currentActor = MonoBehaviourToEntity.GetEntity(hit.collider);
                }
                if (LayerMasks.Environment.ContainsLayer(hit.transform.gameObject.layer))
                {
                    if (_debug)
                    {
                        DebugText.UpdatePermText("World Control", "Environment " + cnt);
                    }
                    break;
                }
            }

            if (currentActor != null)
            {
                if (_debug)
                {
                    DebugText.UpdatePermText("World Control", currentActor.Id.ToString());
                }
            }
            //RaycastHit hit;
            //if (Physics.Raycast(_mouseRay, out hit, _enemyDistance, _worldControlsMask)) {
            //    if (hit.transform.gameObject == _currentGameObject) {
            //        _foundControl = true;
            //    }
            //    else {
            //        if (hit.distance <= _rayDistance) {
            //            var newCurrent = hit.transform.GetComponent<IWorldControl>();
            //            if (newCurrent != null) {
            //                SetNewCurrent(newCurrent, hit.transform.gameObject);
            //                _foundControl = true;
            //            }
            //        }
            //        else {
            //            if (currentActor == null) {
            //                Actor.Actors.TryGetValue(hit.collider, out currentActor);
            //            }
            //        }
            //    }
            //}
            UICenterTarget.SetTargetActor(currentActor.GetNode <VisibleNode>());
            if (!_foundControl || currentActor != null)
            {
                SetCurrentNull();
            }
            if (_debug)
            {
                DebugText.UpdatePermText("World Control", string.Format("Current: {0}", _currentGameObject != null ? _currentGameObject.name : "None"));
            }
            //if (_current == null && AlternativeUse == null) {
            //    var wasActive = GenericDraggableController.HasTarget;
            //    if (GenericDraggableController.main.CanDrag()) {
            //        UICenterTarget.SetText("Drag");
            //    }
            //    else if (wasActive){
            //        UICenterTarget.Clear();
            //    }
            //}
            //else {
            //    GenericDraggableController.ClearTarget();
            //}
        }