public void Show(ReferenceCallback onReferenceChanged, ReferenceCallback onSelectionConfirmed, NameGetter referenceNameGetter, NameGetter referenceDisplayNameGetter, object[] references, object initialReference, bool includeNullReference, string title, Canvas referenceCanvas)
        {
            initialValue = initialReference;

            this.onReferenceChanged         = onReferenceChanged;
            this.onSelectionConfirmed       = onSelectionConfirmed;
            this.referenceNameGetter        = referenceNameGetter ?? ((reference) => reference.GetNameWithType());
            this.referenceDisplayNameGetter = referenceDisplayNameGetter ?? ((reference) => reference.GetNameWithType());

            if (referenceCanvas && this.referenceCanvas != referenceCanvas)
            {
                this.referenceCanvas = referenceCanvas;

                Canvas canvas = GetComponent <Canvas>();
                canvas.CopyValuesFrom(referenceCanvas);
                canvas.sortingOrder = Mathf.Max(1000, referenceCanvas.sortingOrder + 100);
            }

            panel.rectTransform.anchoredPosition = Vector2.zero;
            gameObject.SetActive(true);

            selectPromptText.text   = title;
            currentlySelectedObject = initialReference;

            GenerateReferenceItems(references, includeNullReference);

#if UNITY_EDITOR || UNITY_STANDALONE || UNITY_WEBGL
            // On desktop platforms, automatically focus on search field
            // We don't do the same on mobile because immediately showing the on-screen keyboard after presenting the window wouldn't be nice
            searchBar.ActivateInputField();
#endif
        }
Example #2
0
    private void InputSpawn()
    {
        RayCast frontRayCast       = _moveWrapper.GetChild <RayCast>(1);
        RayCast frontGroundRayCast = _moveWrapper.GetChild <RayCast>(2);
        var     frontGround        = (Node)frontGroundRayCast.GetCollider();
        string  name = NameGetter.FromCollision(frontGround);

        //check the player requested a spawn on an empty tile above ground
        if (frontGround != null)
        {
            if (Input.IsActionJustPressed("ui_select") &&
                !frontRayCast.IsColliding() &&
                (name == "GridMap" || name == "pot"))
            {
                //spawn a flower in front of the player
                Spatial flowerInstance = (Spatial)_flowerPlatform.Instance();
                flowerInstance.Translation = Translation +
                                             _moveWrapper.Translation +
                                             moveWrapper.SPEED * FacingVec();
                GetParent().AddChild(flowerInstance);
                if (name == "pot")
                {
                    ((moveWrapper)frontGround).planted = true;
                }
            }
        }
    }
        public void Close()
        {
            onReferenceChanged         = null;
            onSelectionConfirmed       = null;
            referenceNameGetter        = null;
            referenceDisplayNameGetter = null;
            initialValue            = null;
            currentlySelectedObject = null;
            currentlySelectedItem   = null;

            references.Clear();
            filteredReferences.Clear();

            gameObject.SetActive(false);
        }
Example #4
0
    //provides grid based movement and handles collision information
    public KinematicCollision Move(Vector3 relVec)
    {
        if (!_collisionLoaded)
        {
            return(null);
        }
        relVec *= SPEED;
        KinematicCollision collision = MoveAndCollide(relVec, testOnly: true);

        //don't move if it would cause a collision and return that collision
        if (collision != null)
        {
            //handle the collision
            Node   collider = (Node)collision.Collider;
            string name     = NameGetter.FromCollision(collider);
            switch (name)
            {
            case "bambooPlatformStatic":
                Spatial staticBody = (StaticBody)collider;
                if (staticBody.Translation.y != 0)
                {
                    staticBody.Translation = Vector3.Zero;
                    relVec   += new Vector3(0, SPEED, 0);
                    collision = null;
                }
                break;

            case "pot":
                moveWrapper colliderMove = (moveWrapper)collider;
                if (colliderMove.Move(relVec / SPEED) == null)
                {
                    collision = null;
                }
                break;

            case "GridMap":
            case "flowerPlatform":
                break;

            default:
                GD.Print("Unhandled collision against " + name);
                break;
            }
        }
        //move if it wouldn't cause a collision
        if (collision == null)
        {
            Translation += relVec;
            if (planted)
            {
                var plant = (Spatial)plantRaycast.GetCollider();
                if (plant != null)
                {
                    plant.Translation += relVec;
                }
                else
                {
                    planted = false;
                }
            }
        }
        return(collision);
    }