world to ngui

Unity3D 2015. 10. 2. 17:07
반응형

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using HedgehogTeam.EasyTouch;
 
public class TestMain : MonoBehaviour {
 
    public UIJoystick joystick;
    public UIRoot uiRoot;
 
    void Start () {
        EasyTouch.On_TouchStart += EasyTouch_On_TouchStart;    
    }
 
 
    private void EasyTouch_On_TouchStart(Gesture gesture)
    {
        var pos = UICamera.mainCamera.ScreenToWorldPoint(gesture.position);
        pos = UICamera.mainCamera.WorldToScreenPoint(pos);
        this.joystick.transform.localPosition = pos;
    }
    
    // Update is called once per frame
    void Update () {
        
    }
}
 
cs


 // world to ngui 


            var target = GameObject.Find("LeftGate");

            Camera worldCam = NGUITools.FindCameraForLayer(target.layer);

            Camera guiCam = NGUITools.FindCameraForLayer(uiBinds.Indicators.HouseIcon.layer);

            var pos = guiCam.ViewportToWorldPoint(worldCam.WorldToViewportPoint(target.transform.position));

            pos.z = 0;

            uiBinds.Indicators.HouseIcon.transform.position = pos;


            // end 




//방법1

        var pos = UICamera.mainCamera.ScreenToWorldPoint(gesture.position);

        pos = UICamera.mainCamera.WorldToScreenPoint(pos);



        //방법2 

        var target = GameObject.Find("LeftGate");


        Camera worldCam = NGUITools.FindCameraForLayer(target.layer);


        Camera guiCam = NGUITools.FindCameraForLayer(uiBinds.Indicators.HouseIcon.layer);


        var pos = guiCam.ViewportToWorldPoint(worldCam.WorldToViewportPoint(target.transform.position));


        pos.z = 0;


        uiBinds.Indicators.HouseIcon.transform.position = pos;




     


        //방법3 

        Vector3 mainCamera_ScreenPos = Camera.main.WorldToScreenPoint(world_pos);

        Vector3 uiCamera_WorldPos = UICamera.mainCamera.ScreenToWorldPoint(mainCamera_ScreenPos);







Camera worldCam = NGUITools.FindCameraForLayer(LayerMask.NameToLayer("player"));

        //GUI객체의 카메라 객체입니다.

        Camera guiCam = NGUITools.FindCameraForLayer(LayerMask.NameToLayer("UI"));


        //타겟의 포지션을 월드좌표에서 ViewPort좌표로 변환하고 다시 ViewPort좌표를 NGUI월드좌표로 변환합니다.

        Vector3 pos = guiCam.ViewportToWorldPoint(worldCam.WorldToViewportPoint(initPoint.transform.position));

        //Z는 0으로...

        pos.z = 0f;


        //Label의 좌표를 설정합니다.

        hud.transform.position = pos;



        hud.gameObject.SetActive(true);

반응형
: