Unity3d 中计算日期和时间
作者:互联网
原文链接:http://www.cnblogs.com/WilliamJiang/archive/2013/06/04/3117267.html
使用方法:
void Start()
{
TimeOfDay.dayDuration = 10f;
}
void Update()
{
print( TimeOfDay.GetTimeOfDay() + " Days : " + TimeOfDay.Days() );
}
using UnityEngine;
using System.Collections;
[ExecuteInEditMode]
public class AnchorMultiResolution : MonoBehaviour
{
float screenY = 0;
float screenX = 0;
public float orthoSize = 1;
public Transform mainCamera;
// NOTE: If you don't want to use the camera (especially at Start()):
// 1. Remove the mainCamera line above and also remove the Get Camera Section in setAnchor().
// 2. Set the orthosize above to your main camera orthographic size.
// 3. Don't forget to change camX and camY values to your main camera X and Y values in setAnchor().
public bool viewOnUpdate = true;
public float pixelInsetX = 0, pixelInsetY =0;
private float privInsetX = 0, privInsetY = 0;
float pixelFactor = 1;
public enum ScreenAnchor
{
TopLeft, TopCenter, TopRight,
CenterLeft, Center, CenterRight,
BottomLeft, BottomCenter, BottomRight
}
public ScreenAnchor anchor = ScreenAnchor.Center;
public float xTransform = 0; //Use these two to tune the current transform in SceneView.
public float yTransform = 0; //They are called in setAnchor since Inspector transform is freezed due to the Update() in the editor section at the bottom of this script
private float initX = 0, initY = 0;
void setAnchor(){
screenY = Screen.height;
screenX = Screen.width;
// Get Camera section
if (Camera.main == null ){
Debug.Log ("Main Camera not found.");
Debug.Log ("If you do not want to use the camera, check the script comments for more info.");
}
if (Camera.main != null ){
if (Camera.main.isOrthoGraphic ){
mainCamera = Camera.main.transform;
orthoSize = Camera.main.orthographicSize;
}
else {Debug.Log ("Camera is not set to orthographic!");}
}
//End Section
pixelFactor = orthoSize / (screenY/2);
Transform currentTransform = this.gameObject.transform;
float posX = currentTransform.position.x;
float posY = currentTransform.position.y;
float nudgeX = screenX/2 * pixelFactor;
float nudgeY = screenY/2 * pixelFactor;
float camX = mainCamera.position.x; //You can assign your own values/other camera transforms here
float camY = mainCamera.position.y;
privInsetX = pixelInsetX * pixelFactor;
privInsetY = pixelInsetY * pixelFactor;
switch (anchor){
case ScreenAnchor.TopLeft:
posX = -nudgeX + privInsetX;
posY = nudgeY - privInsetY;
break;
case ScreenAnchor.CenterLeft:
posX = -nudgeX + privInsetX;
posY = 0 + privInsetY;
break;
case ScreenAnchor.BottomLeft:
posX = -nudgeX + privInsetX;
posY = -nudgeY + privInsetY;
break;
case ScreenAnchor.TopCenter:
posX = 0 + privInsetX;
posY = nudgeY - privInsetY;
break;
case ScreenAnchor.Center:
posX = 0 + privInsetX;
posY = 0 + privInsetY;
break;
case ScreenAnchor.BottomCenter:
posX = 0 + privInsetX;
posY = -nudgeY + privInsetY;
break;
case ScreenAnchor.TopRight:
posX = nudgeX - privInsetX;
posY = nudgeY - privInsetY;
break;
case ScreenAnchor.CenterRight:
posX = nudgeX - privInsetX;
posY = 0 + privInsetY;
break;
case ScreenAnchor.BottomRight:
posX = nudgeX - privInsetX;
posY = -nudgeY + privInsetY;
break;
}
currentTransform.position = new Vector2( posX + camX + xTransform, posY + camY + yTransform);
}
// Set Anchor at Start
void Start ()
{
setAnchor();
}
#if UNITY_EDITOR
void Update ()
{
if(viewOnUpdate){
this.setAnchor();
}
}
#endif
/// End section ///
}
转载于:https://www.cnblogs.com/WilliamJiang/archive/2013/06/04/3117267.html
标签:privInsetX,Unity3d,posX,privInsetY,float,日期,计算,posY,ScreenAnchor 来源: https://blog.csdn.net/weixin_30949361/article/details/99616951