2D Toolkit Forum

2D Toolkit => Support => Topic started by: famadori on May 31, 2014, 02:47:23 am

Title: Prefab with TK2DCameraAnchor?
Post by: famadori on May 31, 2014, 02:47:23 am
CameraAnchor'm adding to my prefab, however it does not apply. How do I do that?
Title: Re: Prefab with TK2DCameraAnchor?
Post by: unikronsoftware on May 31, 2014, 07:00:59 pm
I don't understand how you've got this set up. Please post screenshots or a repro case.
Title: Re: Prefab with TK2DCameraAnchor?
Post by: famadori on May 31, 2014, 07:52:13 pm
I'm adding to my prefab tk2dCameraAnchor the script and dragging the camera to camera property, however when I close the unity or throw an build prefab loses Anchor. This prefab is added to the screen by script so do not know if this will be the right way to do.

Title: Re: Prefab with TK2DCameraAnchor?
Post by: famadori on May 31, 2014, 07:53:21 pm
Able to resolve the problem added anchors the main camera and adding to this GameObject anchora scripted. I created this class to help me. This is the correct path?

Code: [Select]
public enum enumPosition
{
    LowerLeft,
    MiddleCenter
}

public static class Extensions
{
    /// <summary>
    /// Adiciona objeto na posição da tk2dCameraAnchor especificada.
    /// </summary>
    /// <param name="gameObject">GameObject que será posicionado</param>
    /// <param name="ePos">Posição onde ficará o gameobject</param>
    /// <param name="newLocalPosition">Nova posição de deslocamento do objeto</param>
    public static void AddCamera(this GameObject gameObject, enumPosition ePos, Vector2 newLocalPosition = new Vector2())
    {
        var cam = GameObject.Find("tk2dCamera").transform.FindChild(ePos.ToString());
        gameObject = GameObject.Instantiate(gameObject, cam.transform.position, cam.transform.rotation) as GameObject;

        gameObject.transform.parent = cam.transform;
        if (newLocalPosition != default(Vector2))
        {
            gameObject.transform.localPosition = newLocalPosition;
        }
    }
}
Title: Re: Prefab with TK2DCameraAnchor?
Post by: unikronsoftware on May 31, 2014, 08:56:26 pm
The tk2danchor needs to be linked to a camera, either create a prefab with the camera, or link it up the way you have. It should also be a child of the camera when initialized.
Title: Re: Prefab with TK2DCameraAnchor?
Post by: famadori on May 31, 2014, 09:06:41 pm
I have to pre configure a prefab with a TK2CameraAnchor and add for instance? Or need to add the anchor after instantiating this way gameObject.transform.parent = cam.transform;
Title: Re: Prefab with TK2DCameraAnchor?
Post by: unikronsoftware on May 31, 2014, 09:16:53 pm
anchor.transform.parent = camera.transform;
anchor.AnchorCamera = camera;
Title: Re: Prefab with TK2DCameraAnchor?
Post by: famadori on May 31, 2014, 09:36:04 pm
Perfect. Thanks.