コード例 #1
0
    private void HandHandler(GameObject target)
    {
        //First get the possible interactable components out
        InteractiveObject     targetInteractive    = null;
        ObjectPlacementVolume targetPlacement      = null;
        SceneTransitionZone   targetTransitionZone = null;

        if (target != null)
        {
            targetInteractive    = target.GetComponent <InteractiveObject>();
            targetPlacement      = target.GetComponent <ObjectPlacementVolume>();
            targetTransitionZone = target.GetComponent <SceneTransitionZone>();
            if (targetInteractive != null && targetInteractive.enabled)
            {
                targetInteractive.Highlight();
            }
        }

        //Click behaviors
        if (!magnifyingGlass.isEnabled)
        {
            if (Input.GetMouseButtonDown(0))
            {
                if (targetTransitionZone != null && targetTransitionZone.notNeedMagGlass)
                {
                    transform.position = targetTransitionZone.target.spawnPoint;
                    return;
                }

                if (targetInteractive != null && heldObject == null)
                {
                    if (targetInteractive.IsSpawner)
                    {
                        heldObject = targetInteractive.GenerateSpawnedObject();
                    }
                    else if (targetInteractive.InteractionIsHeld)
                    {
                        heldObject = targetInteractive;
                    }
                    targetInteractive.Interact(handTF);
                }
                else if (heldObject != null)
                {
                    if (targetPlacement != null)
                    {
                        if (targetPlacement.requiredObject == heldObject.gameObject || heldObject.gameObject.tag == targetPlacement.requiredTag)
                        {
                            heldObject.ReleaseTo(targetPlacement.transform);
                            targetPlacement.PlacementTrigger(heldObject);
                            heldObject = null;
                            return;
                        }
                    }
                    heldObject.Release();
                    heldObject = null;
                }
            }
        }
    }