Esempio n. 1
0
        private void HandleItemCreation()
        {
            if (Input.GetKeyUp(KeyCode.LeftShift))
            {
                _selected = null;
            }
            if (!Input.GetMouseButtonDown(0) || _selected == null)
            {
                return;
            }

            var        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            RaycastHit hit;

            if (!Physics.Raycast(ray, out hit))
            {
                return;
            }

            var go = MapLoader.Instance.CreateItem(new MapItem {
                PrefabName = _selected.ItemName
            });

            go.transform.position   = hit.point;
            _dragging               = go.GetComponent <MapItemHolder>();
            _dragging.Item.Position = go.transform.position;

            MapLoader.Instance.BindItem(go);

            if (!Input.GetKey(KeyCode.LeftShift))
            {
                _selected = null;
            }
        }
Esempio n. 2
0
 private void HandleDragging()
 {
     if (Input.GetMouseButtonDown(0) && _selected == null)
     {
         _dragging = GetObjectUnderCursor();
     }
     if (_dragging != null)
     {
         var delta = Input.mousePosition - (Vector3)_lastMousePos;
         if (!Input.GetKey(KeyCode.LeftControl))
         {
             delta.z = delta.y;
             delta.y = 0;
         }
         var rotation = Quaternion.AngleAxis(
             Camera.main.transform.rotation.eulerAngles.y,
             Vector3.up
             );
         _dragging.Translate(rotation * delta * DragFactor);
     }
     if (Input.GetMouseButtonUp(0))
     {
         _dragging = null;
     }
 }
Esempio n. 3
0
        private void Update()
        {
            HandleRotation();
            HandleItemCreation();
            HandleDragging();
            HandleItemDeletion();

            if (_dragging != null)
            {
                LastSelected = _dragging;
            }
            _lastMousePos = Input.mousePosition;
        }
Esempio n. 4
0
        private void Update()
        {
            var notNull = Selector.LastSelected != null;

            _name.interactable      = notNull;
            _scale.interactable     = notNull;
            _rotation.interactable  = notNull;
            _threshold.interactable = notNull;
            _target.interactable    = notNull;

            if (Selector.LastSelected == _holder || !notNull)
            {
                return;
            }
            _holder         = Selector.LastSelected;
            _title.text     = _holder.Item.PrefabName;
            _name.text      = _holder.Item.Name;
            _scale.text     = _holder.Item.Scale.ToString(CultureInfo.CurrentCulture);
            _rotation.text  = _holder.Item.YRotation.ToString(CultureInfo.CurrentCulture);
            _threshold.text = _holder.Item.ActivationThreshold.ToString();
            _target.text    = _holder.Item.ActivationTarget;
        }