Пример #1
0
    public void SetTarget(int uniqueID)
    {
        target = GridData.GetExtensible(uniqueID);
        if (target != null)
        {
            targetUniqueID = target.uniqueID;
        }
        else
        {
            targetUniqueID = -1;
            return;
        }

        if (switchT == null)
        {
            return;
        }

        DoorData doorData = (DoorData)target.GetExtension(PStrings.door);

        if (doorData == null)
        {
            return;
        }

        if (doorData.key == DoorKey.Null)
        {
            offMaterial = Statics.green;
            onMaterial  = Statics.greenLight;
        }
        else if (doorData.key == DoorKey.RedCard || doorData.key == DoorKey.RedSkull)
        {
            offMaterial = Statics.red;
            onMaterial  = Statics.redLight;
        }
        else if (doorData.key == DoorKey.BlueCard || doorData.key == DoorKey.BlueSkull)
        {
            offMaterial = Statics.blue;
            onMaterial  = Statics.blueLight;
        }
        else if (doorData.key == DoorKey.YellowCard || doorData.key == DoorKey.YellowSkull)
        {
            offMaterial = Statics.yellow;
            onMaterial  = Statics.yellowLight;
        }
    }
    private void Interact()
    {
        if (input.interactRequest == true)
        {
            CellData interactCell = GridData.GetCellAt(Coordinates.FromWorldSpace(input.interactPosition));

            if (interactCell != null)
            {
                ExtensibleData extensible = null;

                if (interactCell.obstacle != null)
                {
                    extensible = interactCell.obstacle;
                }
                else if (interactCell.item != null)
                {
                    extensible = interactCell.item;
                }
                else if (interactCell.entity != null)
                {
                    extensible = interactCell.entity;
                }

                if (extensible != null)
                {
                    InteractableData interactable = (InteractableData)extensible.GetExtension(PStrings.interactable);

                    if (interactable != null)
                    {
                        float   sqrDistanceThreshold = 2.0f;
                        Vector3 interactablePosition = new Vector3(extensible.gameObject.transform.position.x, 0, extensible.gameObject.transform.position.z);
                        Vector3 interactorPosition   = new Vector3(rigidbody.position.x, 0, rigidbody.position.z);
                        if ((interactablePosition - interactorPosition).sqrMagnitude <= (sqrDistanceThreshold * sqrDistanceThreshold))
                        {
                            interactable.Switch();
                        }
                    }
                }
            }
        }
    }