Ejemplo n.º 1
0
    private Vector3 ConvertToAnchorTop(Vector3 position, InterfaceAnchors baseAnchor)
    {
        Vector3 transformedPosition = position;

        switch (baseAnchor)
        {
        case InterfaceAnchors.Center:
            //vTransformed.x += nativeWidth / 2; //Jason: This doesn't make sense for center to top conversion
            // so i commented it out. center to top has the same x only the
            //Y change...not sure why this was here in the beginning. hope i
            //didn't break more code
            transformedPosition.y -= nativeHeight / 2;
            break;

        case InterfaceAnchors.BottomLeft:
            transformedPosition.x -= nativeWidth / 2;
            transformedPosition.y -= nativeHeight;
            break;

        case InterfaceAnchors.TopLeft:
            transformedPosition.x -= nativeWidth / 2;
            break;

        default:
            Debug.LogError("Sorry not implemented yet.");
            break;
        }

        return(transformedPosition);
    }
Ejemplo n.º 2
0
    // Pass by reference
    static public void SetAnchor(ref RectTransform rect, InterfaceAnchors anchor)
    {
        switch (anchor)
        {
        case InterfaceAnchors.BottomLeft:
            rect.anchorMax = Vector2.zero;
            rect.anchorMin = Vector2.zero;
            break;

        case InterfaceAnchors.Right:
            rect.anchorMax = new Vector2(1f, 0.5f);
            rect.anchorMin = new Vector2(1f, 0.5f);
            break;

        default:
            // Nothing implemented yet
            Debug.LogWarning("NOTHING IMPLEMENTED");
            break;
        }
    }
Ejemplo n.º 3
0
    protected void ShowFingerHint(GameObject goTarget, bool isGUI = false, InterfaceAnchors GUIanchor = InterfaceAnchors.Center,
                                  BedroomTutFingerController.FingerState fingerState = BedroomTutFingerController.FingerState.Press,
                                  float offsetX = 0.0f, float offsetY = 60.0f, bool flipX = false)
    {
        RemoveFingerHint();

        // get the proper location of the object we are going to focus on
        Vector3 focusPos = Vector3.zero;

        if (!isGUI)
        {
            // WorldToScreen returns screen coordinates based on 0,0 being bottom left, so we need to transform those into NGUI center
            focusPos = CameraManager.Instance.WorldToScreen(CameraManager.Instance.CameraMain, goTarget.transform.position);
            // Camera.main.WorldToScreenPoint( goTarget.transform.position );

            focusPos = CameraManager.Instance.TransformAnchorPosition(focusPos,
                                                                      InterfaceAnchors.BottomLeft, InterfaceAnchors.Center);
        }

        GameObject fingerHintResource = (GameObject)Resources.Load("BedroomTutFinger");

        goFingerHint = GameObjectUtils.AddChildGUI(TutorialManager.Instance.UICanvasParent, fingerHintResource);
        focusPos.x   = focusPos.x + offsetX;
        focusPos.y   = focusPos.y + offsetY;       //offset in Y so the finger hint doesn't overlap the image
        focusPos.z   = 0f;
        goFingerHint.transform.localPosition = focusPos;

        if (isGUI)
        {
            RectTransform rect = goFingerHint.GetComponent <RectTransform>();
            GameObjectUtils.SetAnchor(ref rect, GUIanchor);
            rect.anchoredPosition = new Vector2(offsetX, offsetY);
        }

        if (flipX)
        {
            goFingerHint.transform.localScale = new Vector3(-1, 1, 1);
        }

        goFingerHint.GetComponent <BedroomTutFingerController>().PlayState(fingerState);
    }
Ejemplo n.º 4
0
    private Vector3 ConvertToAnchorTopLeft(Vector3 position, InterfaceAnchors baseAnchor)
    {
        Vector3 transformedPosition = position;

        switch (baseAnchor)
        {
        case InterfaceAnchors.Center:
            transformedPosition.x += nativeWidth / 2;
            transformedPosition.y -= nativeHeight / 2;
            break;

        case InterfaceAnchors.BottomLeft:
            transformedPosition.y -= nativeHeight;
            break;

        default:
            Debug.LogError("Sorry not implemented yet.");
            break;
        }

        return(transformedPosition);
    }
Ejemplo n.º 5
0
    /// <summary>
    /// Transforms the anchor position.
    /// Strictly for use with NGUI, takes a vector and the
    /// anchor that vector is in (baseAnchor) and transforms
    /// that position to coordinates as if the position were
    /// in the target anchor. Note: NGUI's coordinate system is (0,0) at top-right
    /// and (nativeWidht, nativeHeight) at bottom-left
    /// </summary>
    /// <returns>The new position in target anchor.</returns>
    /// <param name="position">Position.</param>
    /// <param name="baseAnchor">Base anchor.</param>
    /// <param name="targetAnchor">Target anchor.</param>
    public Vector3 TransformAnchorPosition(Vector3 position, InterfaceAnchors baseAnchor, InterfaceAnchors targetAnchor)
    {
        // no need to do any transforming if the two anchors are the same
        if (baseAnchor == targetAnchor)
        {
            return(position);
        }

        Vector3 transformedPosition = position;

        switch (targetAnchor)
        {
        case InterfaceAnchors.Center:
            transformedPosition = ConvertToAnchorCenter(position, baseAnchor);
            break;

        case InterfaceAnchors.Top:
            transformedPosition = ConvertToAnchorTop(position, baseAnchor);
            break;

        case InterfaceAnchors.TopLeft:
            transformedPosition = ConvertToAnchorTopLeft(position, baseAnchor);
            break;

        case InterfaceAnchors.TopRight:
            transformedPosition = ConvertToAnchorTopRight(position, baseAnchor);
            break;

        case InterfaceAnchors.BottomRight:
            transformedPosition = ConvertToAnchorBottomRight(position, baseAnchor);
            break;

        default:
            Debug.LogError("Sorry, anchor not supported yet");
            break;
        }

        return(transformedPosition);
    }
Ejemplo n.º 6
0
    /// <summary>
    /// <para>Puts a spotlight around the incoming object to
    /// draw attention to it.
    /// eAnchor is the incoming anchor of the object/where
    /// the spotlight should be created.  For 3D objects
    /// the anchor should be center, and for GUI elements
    /// the anchor should be whatever anchor the element
    /// is in.</para>
    ///
    /// Params:
    ///		goTarget (GameObject): the target that you want the spotlight to spawn on
    ///
    ///
    /// NOTE: If it is 3D object goTarget needs to != null
    /// </summary>
    protected void SpotlightObject(GameObject goTarget    = null, bool isGUI = false, InterfaceAnchors GUIanchor = InterfaceAnchors.Center,
                                   bool hasFingerHint     = false, BedroomTutFingerController.FingerState fingerState = BedroomTutFingerController.FingerState.Press,
                                   float spotlightOffsetX = 0f, float spotlightOffsetY = 0f,
                                   float fingerOffsetX    = 0f, float fingerOffsetY    = 60f,
                                   bool fingerHintFlip    = false, float delay         = -1f)
    {
        RemoveSpotlight();
        RemoveFingerHint();

        // get the proper location of the object we are going to focus on
        Vector3 focusPos = Vector3.zero;

        if (!isGUI)
        {
            // WorldToScreen returns screen coordinates based on 0,0 being bottom left, so we need to transform those into NGUI center
            focusPos = CameraManager.Instance.WorldToScreen(CameraManager.Instance.CameraMain, goTarget.transform.position);
            focusPos = CameraManager.Instance.TransformAnchorPosition(focusPos, InterfaceAnchors.BottomLeft, InterfaceAnchors.Center);
        }

        // Adjust for custom offset
        focusPos = new Vector3(focusPos.x + spotlightOffsetX, focusPos.y + spotlightOffsetY, focusPos.z);

        // Create the spotlight
        GameObject goResource = Resources.Load("TutorialSpotlight") as GameObject;

        goSpotlight = GameObjectUtils.AddChildGUI(TutorialManager.Instance.UICanvasParent, goResource);

        // Set the delay if defined
        if (delay > 0)
        {
            goSpotlight.GetComponent <AlphaTweenToggle>().showDelay = delay;
        }

        // Move the spotlight into position
        goSpotlight.transform.localPosition = focusPos;

        if (isGUI)
        {
            RectTransform rect = goSpotlight.GetComponent <RectTransform>();
            GameObjectUtils.SetAnchor(ref rect, GUIanchor);
            rect.anchoredPosition = new Vector2(spotlightOffsetX, spotlightOffsetY);
        }

        // Spawn finger hint
        if (hasFingerHint)
        {
            if (isGUI)
            {
                ShowFingerHint(goTarget, isGUI: isGUI, GUIanchor: GUIanchor, fingerState: fingerState,
                               offsetX: fingerOffsetX + spotlightOffsetX, offsetY: fingerOffsetY + spotlightOffsetY,
                               flipX: fingerHintFlip);
            }
            else
            {
                ShowFingerHint(goTarget, isGUI: isGUI, GUIanchor: GUIanchor, fingerState: fingerState,
                               offsetX: fingerOffsetX, offsetY: fingerOffsetY,
                               flipX: fingerHintFlip);
            }
        }

        // Show the backdrop
        goSpotlight.GetComponent <AlphaTweenToggle>().ShowAfterInit();
    }