Hello Guest

Author Topic: Prefab with TK2DCameraAnchor?  (Read 7102 times)

famadori

  • Newbie
  • *
  • Posts: 12
    • View Profile
Prefab with TK2DCameraAnchor?
« on: May 31, 2014, 02:47:23 am »
CameraAnchor'm adding to my prefab, however it does not apply. How do I do that?

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Prefab with TK2DCameraAnchor?
« Reply #1 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.

famadori

  • Newbie
  • *
  • Posts: 12
    • View Profile
Re: Prefab with TK2DCameraAnchor?
« Reply #2 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.


famadori

  • Newbie
  • *
  • Posts: 12
    • View Profile
Re: Prefab with TK2DCameraAnchor?
« Reply #3 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;
        }
    }
}

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Prefab with TK2DCameraAnchor?
« Reply #4 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.

famadori

  • Newbie
  • *
  • Posts: 12
    • View Profile
Re: Prefab with TK2DCameraAnchor?
« Reply #5 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;

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Prefab with TK2DCameraAnchor?
« Reply #6 on: May 31, 2014, 09:16:53 pm »
anchor.transform.parent = camera.transform;
anchor.AnchorCamera = camera;

famadori

  • Newbie
  • *
  • Posts: 12
    • View Profile
Re: Prefab with TK2DCameraAnchor?
« Reply #7 on: May 31, 2014, 09:36:04 pm »
Perfect. Thanks.