コード例 #1
0
    void GetAllPossibleActions(List <GameAction> possibleActions)
    {
        Collider[] colliders = Physics.OverlapSphere(transform.position, interactionRadius, interactionLayers);

        foreach (var c in colliders)
        {
            InteractiveObject interactiveObject = c.GetComponentInChildren <InteractiveObject>();
            if (interactiveObject == null)
            {
                interactiveObject = c.GetComponentInParent <InteractiveObject>();
            }

            if (interactiveObject != null)
            {
                if (!interactiveObject.enabled)
                {
                    continue;
                }

                Vector3 playerPos     = transform.position + Vector3.up * 1.8f;
                Vector3 objectPos     = interactiveObject.GetCenter();
                Vector3 toInteractive = objectPos - playerPos;
                Ray     ray           = new Ray(playerPos, toInteractive.normalized);

                bool         collision = false;
                RaycastHit[] hits      = Physics.RaycastAll(ray, toInteractive.magnitude, environmentMask);
                foreach (var hit in hits)
                {
                    collision = true;
                }

                if (!collision)
                {
                    // Get all possible actions
                    GameAction[] actions = interactiveObject.GetComponentsInChildren <GameAction>();
                    foreach (var a in actions)
                    {
                        if (a.enabled)
                        {
                            possibleActions.Add(a);
                        }
                    }
                }
            }
        }
    }
コード例 #2
0
    void UpdatePosition()
    {
        if ((floating) && (lockedObject))
        {
            if (floating)
            {
                if (gameCamera.targetTexture)
                {
                    srcWidth  = gameCamera.targetTexture.width;
                    srcHeight = gameCamera.targetTexture.height;
                }
                else
                {
                    srcWidth  = Screen.width;
                    srcHeight = Screen.height;
                }

                Vector3 centerPos = lockedObject.position;

                InteractiveObject io = lockedObject.GetComponent <InteractiveObject>();
                if (io != null)
                {
                    centerPos = io.GetCenter();
                }

                Vector3 pos = gameCamera.WorldToScreenPoint(centerPos);

                pos.x = Mathf.Round(pos.x);
                pos.y = Mathf.Round(pos.y);

                pos.x /= srcWidth; pos.y /= srcHeight;

                pos.x *= canvasWidth; pos.y *= canvasHeight;

                rectTransform.anchoredPosition = pos + floatingOffset;
            }
        }
    }