Unity + NGUI开发2D游戏的笔记。

来源:互联网 发布:sacdiso mac播放 编辑:程序博客网 时间:2024/05/16 19:47

1、没法加Anchor

使用复制吧


2、多分辨率如何弄。(尤其差很远的情况下)

控制UIRoot的高,可以设置缩放


3、如何使得一个面板及其子都不可以有事件。

NGUITools.SetActive(this.transform.parent.gameObject, false);


4、算出实时屏幕宽高度

UIRoot uiroot = (UIRoot)GameObject.FindObjectOfType(typeof(UIRoot));
int height = uiroot.manualHeight;
int width = Mathf.CeilToInt(Screen.width * 1.0f / Screen.height * heightb);


5、鼠标位置,转成NGUI Plane空间。
Transform.InverseTransformPoint, TransformPoint正向,反向位置

1、没法加Anchor

使用复制吧

2、多分辨率如何弄。(尤其差很远的情况下)

控制UIRoot的高,可以设置缩放

3、如何使得一个面板及其子都不可以有事件。

NGUITools.SetActive(this.transform.parent.gameObject, false);

4、算出实时屏幕宽高度

UIRoot uiroot = (UIRoot)GameObject.FindObjectOfType(typeof(UIRoot));
int height = uiroot.manualHeight;
int width = Mathf.CeilToInt(Screen.width * 1.0f / Screen.height * heightb);

5、鼠标位置,转成NGUI Plane空间。
Transform.InverseTransformPoint, TransformPoint正向,反向位置

Plane.Raycast 光线投射

function Raycast (ray : Ray, out enter : float) : bool

Description描述

Intersects a ray with the plane.

一条射线和平面相交。

This function sets enter to the distance along the ray, where it intersects the plane. If the ray is parallel to the plane, function returns false and sets enter to zero.

这个函数设置out enter沿着射线,相交平面的距离,如果该射线是平行于平面,函数返回false,并且设置out enter到0。

1、===========================================

没法加Anchor

使用复制吧


2、===========================================

多分辨率如何弄。(尤其差很远的情况下)

控制UIRoot的高,可以设置缩放


3、===========================================

如何使得一个面板及其子都不可以有事件。

NGUITools.SetActive(this.transform.parent.gameObject, false);


4、===========================================

算出实时屏幕宽高度

UIRoot uiroot = (UIRoot)GameObject.FindObjectOfType(typeof(UIRoot));
int height = uiroot.manualHeight;
int width = Mathf.CeilToInt(Screen.width * 1.0f / Screen.height * heightb);


5、===========================================
鼠标位置,转成NGUI Plane空间。
Transform.InverseTransformPoint,
Transform.TransformPoint
正向,反向位置

http://game.ceeger.com/Manual/CameraRays.html

// Create a plane
Transform trans = cachedTransform;
Plane plane = new Plane(trans.rotation * Vector3.back, trans.position);


// If the ray doesn't hit the plane, do nothing
float dist;
Ray ray = cachedCamera.ScreenPointToRay(screenPos);
if (!plane.Raycast(ray, out dist)) return;


// Transform the point from world space to local space
CenterOnPos(trans.InverseTransformPoint(ray.GetPoint(dist)));

6、====================================================

原创粉丝点击