资源简介
Unity3d 实现屏幕自动适配,里面有一个完整的小Dmeo可以学习下。
代码片段和文件信息
using UnityEngine;
using System.Collections;
//[ExecuteInEditMode]
public class BKAnchor : MonoBehaviour {
public enum Anchor
{
Anchor_x
Anchor_y
Anchor_x_y
}
private MyAnchorCamera MyAnchorCamera;
private Transform MyTransform;
private float MyWidth;
private float MyHight;
private float scale_x = 0;
private float scale_y = 0;
public Anchor anchor;
// Use this for initialization
void Start () {
MyAnchorCamera = Gameobject.FindWithTag(“MainCamera“).GetComponent();
MyTransform = transform;
MyWidth = MyTransform.renderer.material.mainTexture.width * MyTransform.localScale.x;
MyHight = MyTransform.renderer.material.mainTexture.height * MyTransform.localScale.y;
scale_x = ((Screen.width - MyWidth)) / MyWidth;
scale_y = ((Screen.height - MyHight)) / MyHight;
// Debug.Log(MyWidth + “ “+ MyHight);
BKAdapt();
}
// Update is called once per frame
void Update () {
}
public void BKAdapt()
{
switch(anchor)
{
case Anchor.Anchor_x: MyTransform.localScale = new Vector3((MyTransform.localScale.x + scale_x) / MyAnchorCamera.scale
MyTransform.localScale.yMyTransform.localScale.z);break;
case Anchor.Anchor_y: MyTransform.localScale = new Vector3(MyTransform.localScale.x
(MyTransform.localScale.y + scale_y) / MyAnchorCamera.scaleMyTransform.localScale.z);break;
case Anchor.Anchor_x_y: MyTransform.localScale = new Vector3((MyTransform.localScale.x + scale_x) / MyAnchorCamera.scale
(MyTransform.localScale.y + scale_y) / MyAnchorCamera.scaleMyTransform.localScale.z);break;
}
}
}
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2013-04-15 14:30 MyCameraAnchor\
文件 1589 2013-01-26 14:13 MyCameraAnchor\BKAnchor.cs
目录 0 2013-04-15 14:30 MyCameraAnchor\Editor\
文件 789 2013-03-28 16:07 MyCameraAnchor\Editor\MyAnchorCameraEditor.cs
文件 1756 2013-01-25 09:26 MyCameraAnchor\MyAnchorCamera.cs
文件 3692 2013-02-16 10:42 MyCameraAnchor\MyUIAnchor.cs
文件 22 2013-03-26 16:40 MyCameraAnchor\readme.txt
评论
共有 条评论