コード例 #1
0
    public IEnumerator MoveToPositionI(Vector3 position, Vector2Int newCell)
    {
        if (_animator != null)
        {
            _animator.SetBool("IsWalking", true);
        }

        isMoving = true;
        var from = transform.position;

        float time = 0;

        while (time < 0.4f)
        {
            yield return(0);

            time += Time.deltaTime;
            transform.position = from + (position - from) * (time / 0.4f);
            ZOrdering.SetZOrdering(transform);
        }


        transform.position = position;
        cell = newCell;
        ZOrdering.SetZOrdering(transform);
        isMoving = false;

        if (_animator != null)
        {
            _animator.SetBool("IsWalking", false);
        }
    }
コード例 #2
0
ファイル: DisplayEngine.cs プロジェクト: m9ra/MEFEditor_v2.0
        /// <summary>
        /// Register item to be displayed after next <see cref="Display"/> call
        /// </summary>
        /// <param name="item">Registered item</param>
        internal void RegisterItem(DiagramItem item)
        {
            //attach items behaviours
            ItemHighlighting.Attach(item);
            ZOrdering.Attach(item, _orderingGroup);
            DragAndDrop.Attach(item, GetPosition, SetPosition);
            UpdateGlobalPosition.Attach(item);

            _items.Add(item.Definition.ID, item);

            if (item.IsRootItem)
            {
                _rootItems.Add(item);
            }
        }
コード例 #3
0
    public void MoveToCellNoCollisions(Tilemap tilemap, Vector2Int newCell)
    {
        if (isMoving || isRotating)
        {
            return;
        }
        var newPosition = tilemap.GetCellCenterWorld(new Vector3Int(newCell.x, newCell.y, -1));

        if (!tilemap.GetTile(new Vector3Int(newCell.x, newCell.y, 0)))
        {
            return;
        }

        transform.position = newPosition;
        cell = newCell;

        ZOrdering.SetZOrdering(transform);
    }
コード例 #4
0
    public void MoveToCell(Tilemap tilemap, Vector2Int newCell)
    {
        if (isMoving || isRotating)
        {
            return;
        }
        var newPosition = tilemap.GetCellCenterWorld(new Vector3Int(newCell.x, newCell.y, -1));

        if (Physics2D.OverlapPoint(new Vector2(newPosition.x, newPosition.y), ~LayerMask.GetMask("Zone")))
        {
            return;
        }
        if (!tilemap.GetTile(new Vector3Int(newCell.x, newCell.y, 0)))
        {
            return;
        }

        transform.position = newPosition;
        cell = newCell;

        ZOrdering.SetZOrdering(transform);
    }
コード例 #5
0
    // Update is called once per frame
    void Update()
    {
        var inventory = GetComponent <PlayerInventory>();
        var handItem  = inventory.HandItem();

        if (handItem)
        {
            var inventoryTileObject = handItem.GetComponent <TileObject>();

            if (Input.GetKeyDown(KeyCode.RightArrow))
            {
                inventoryTileObject.RotateRight();
            }
            if (Input.GetKeyDown(KeyCode.LeftArrow))
            {
                inventoryTileObject.RotateLeft();
            }
        }
        else
        {
            if (Input.GetKey(KeyCode.RightArrow))
            {
                tileObject.RotateRight();
            }
            if (Input.GetKey(KeyCode.LeftArrow))
            {
                tileObject.RotateLeft();
            }
            if (Input.GetKey(KeyCode.UpArrow))
            {
                tileObject.Step(tilemap, tileObject.GetRotation());
            }
            if (Input.GetKey(KeyCode.DownArrow))
            {
                tileObject.Step(tilemap, tileObject.GetRotation().RotateLeft().RotateLeft());
            }
            if (Input.GetKey(KeyCode.Escape))
            {
                Application.Quit();
            }

            var cellPoint  = tileObject.Cell.Step(tileObject.GetRotation());
            var worldPoint = tilemap.GetCellCenterWorld(new Vector3Int(cellPoint.x, cellPoint.y, 0));

            foreach (GameObject o in inventory.Inventory)
            {
                if (!o)
                {
                    continue;
                }
                o.transform.position = worldPoint;
                ZOrdering.SetZOrdering(o.transform);
            }
        }

        if (Input.GetKeyDown(KeyCode.Space))
        {
            Interact();
        }

        if (Input.GetKeyDown(KeyCode.Z))
        {
            inventory.SpinInventory();
        }
    }