Unity3D脚本:C#计时类脚本
 unity3D更多资源教程免费下载,群153442627
using UnityEngine;
using System.Collections;
/// <summary>
/// C# timer 改编自Jeff 'PsychicParrot' Murray 的js的timer
/// </summary>
public class Timer : MonoBehaviour {
private float timeElapsed = 0.0f;
private float currentTime = 0.0f;
private float lastTime = 0.0f;
private float cdTime = 0.0f;
private float timeScaleFactor = 1.0f;
private bool isTimerRunning;
private bool doneCallback;
private float parseTime;
private GameObject callback;
private float aHour;
private float aMinute;
private float aSecond;
private float aMillis;
private string seconds;
private string minutes;
private string hour;
private string mills;
private string timeString;
void Update ()
{
timeElapsed=Time.time-lastTime;
if(isTimerRunning){
currentTime+=timeElapsed*timeScaleFactor;
}
lastTime=Time.time;
}
public void StartTimer()
{
isTimerRunning=true;
doneCallback=false;
lastTime=Time.time;
}
public void StopTimer()
{
isTimerRunning=false;
}
public void ResetTimer()
{
doneCallback=false;
timeElapsed=0.0f;
lastTime=0.0f;
currentTime=0.0f;
lastTime=Time.time;
}
public void SetCountdownTime(float aTime)
{
cdTime=aTime;
}
public void SetCallback(GameObject aRef)
{
callback=aRef;
doneCallback=false;
}
public float GetTime()
{
return currentTime;
}
public string GetFormattedTime(int returnType)
{
if(cdTime>0){
// if a countdown time has been set, we parse the reverse time value
parseTime=cdTime-currentTime;
if(parseTime<0){
if(!doneCallback){
// SOUND THE ALARM!!!!! WE HIT 0!
callback.SendMessage("alarmDone");
// set our doneCallback flag so as not to repeat call alarmDone()
doneCallback=true;
}
parseTime=0;
}
} else {
// if no countdown time has been set, we just parse the regular time
parseTime=currentTime;
}
// grab hours
aHour = parseTime/3600;
aHour=aHour%24;
// grab minutes
aMinute=parseTime/60;
aMinute=aMinute%60;
// grab seconds
aSecond=parseTime%60;
// grab milliseconds
aMillis=(parseTime*100)%100;
// format string into mm:ss:mm
seconds=Mathf.Round(aSecond).ToString();
if(seconds.Length<2)
seconds="0"+seconds;
minutes=Mathf.Round(aMinute).ToString();
if(minutes.Length<2)
minutes="0"+minutes;
hour=Mathf.Round(aHour).ToString();
if(hour.Length<2)
hour="0"+hour;
mills=Mathf.Round(aMillis).ToString();
if(mills.Length<2)
mills="0"+mills;
switch(returnType){
case 1:
timeString=minutes+":"+seconds+":"+mills;
break;
case 2:
timeString=minutes+":"+seconds;
break;
default:
timeString=hour+":"+minutes+":"+seconds+":"+mills;
break;
}
return timeString;
}
public float GetHours()
{
if(cdTime>0){
// if a countdown time has been set, we parse the reverse time value
parseTime=cdTime-currentTime;
if(parseTime<0){
parseTime=0;
}
} else {
// if no countdown time has been set, we just parse the regular time
parseTime=currentTime;
}
// grab hours
aHour = parseTime/3600;
return aHour;
}
public float GetMinutes()
{
if(cdTime>0){
// if a countdown time has been set, we parse the reverse time value
parseTime=cdTime-currentTime;
if(parseTime<0){
parseTime=0;
}
} else {
// if no countdown time has been set, we just parse the regular time
parseTime=currentTime;
}
// grab minutes
aMinute=parseTime/60;
aMinute=aMinute%60;
return aMinute;
}
public float GetSeconds()
{
if(cdTime>0){
// if a countdown time has been set, we parse the reverse time value
parseTime=cdTime-currentTime;
if(parseTime<0){
parseTime=0;
}
} else {
// if no countdown time has been set, we just parse the regular time
parseTime=currentTime;
}
// grab seconds
aSecond=parseTime%60;
return aSecond;
}
public int getClockTimeHour()
{
int aTime=System.DateTime.Now.Hour;
return aTime;
}
public int getClockTimeMinute()
{
int aTime=System.DateTime.Now.Minute;
return aTime;
}
public int getClockTimeSeconds()
{
int aTime=System.DateTime.Now.Second;
return aTime;
}
public string GetClockFormattedTime(int returnType)
{
int aHour =System.DateTime.Now.Hour;
int aMinute =System.DateTime.Now.Minute;
int aSecond =System.DateTime.Now.Second;
int aMillis =System.DateTime.Now.Millisecond;
// format string into mm:ss:mm
seconds=Mathf.Round(aSecond).ToString();
if(seconds.Length<2)
seconds="0"+seconds;
minutes=Mathf.Round(aMinute).ToString();
if(minutes.Length<2)
minutes="0"+minutes;
hour=Mathf.Round(aHour).ToString();
if(hour.Length<2)
hour="0"+hour;
mills=Mathf.Round(aMillis).ToString();
if(mills.Length<2)
mills="0"+mills;
if(mills.Length>2)
mills=mills.Substring(0,2);
switch(returnType){
case 1:
timeString=minutes+":"+seconds+":"+mills;
break;
case 2:
timeString=minutes+":"+seconds;
break;
default:
timeString=hour+":"+minutes+":"+seconds+":"+mills;
break;
}
return timeString;
}
}
Unity3D脚本:边缘高光脚本
Posted on 2013年02月16日 by U3d / Unity3D脚本/插件/被围观 240 次
Shader着色器,边缘高光,只需一个shader文件,直接可用。
Shader "Example/Rim" {
Properties {
_MainTex ("Texture", 2D) = "white" {}
_BumpMap ("Bumpmap", 2D) = "bump" {}
_RimColor ("Rim Color", Color) = (0.26,0.19,0.16,0.0)
_RimPower ("Rim Power", Range(0.5,8.0)) = 3.0
}
SubShader {
Tags { "RenderType" = "Opaque" }
CGPROGRAM
#pragma surface surf Lambert
struct Input {
float2 uv_MainTex;
float2 uv_BumpMap;
float3 viewDir;
};
sampler2D _MainTex;
sampler2D _BumpMap;
float4 _RimColor;
float _RimPower;
void surf (Input IN, inout SurfaceOutput o) {
o.Albedo = tex2D (_MainTex, IN.uv_MainTex).rgb;
o.Normal = UnpackNormal (tex2D (_BumpMap, IN.uv_BumpMap));
half rim = 1.0 - saturate(dot (normalize(IN.viewDir), o.Normal));
o.Emission = _RimColor.rgb * pow (rim, _RimPower);
}
ENDCG
}
Fallback "Diffuse"
}

Unity3D脚本:C#计时类脚本的更多相关文章

  1. unity3d 特殊文件夹和脚本编译顺序

    unity3d 特殊文件夹和脚本编译顺序 转自http://blog.csdn.net/u010019717/article/details/40474631 大多数情况下,您可以选择任何你喜欢的文件 ...

  2. Unity3D第三人称摄像机控制脚本

    好久没有敲Blog该.感谢您的留言.注意.私人信件和其他支持,但我似乎没有办法继续自己曾经写了一篇博客系列,因为我在网上找到有关unity3D太少的内容,U3D相关的文章!.. 第三人称视角 第三人称 ...

  3. 远程shell脚本执行工具类

    /** * 远程shell脚本执行工具类 */public class RemoteShellExecutorUtils { private static final Logger logger = ...

  4. CodeSmith生成SQL Server视图的实体类脚本/对应的生成模板

    C#生成sql视图的实体类 using System;using System.Text;using CodeSmith.Engine;using SchemaExplorer;using Syste ...

  5. (转)Unity3D研究院之游戏架构脚本该如何来写(三十九)

     这篇文章MOMO主要想大家说明一下我在Unity3D游戏开发中是如何写游戏脚本的,对于Unity3D这套游戏引擎来说入门极快,可是要想做好却非常的难.这篇文章的目的是让哪些已经上手Unity3D游戏 ...

  6. java调用python脚本并向python脚本传递参数

    1.安装Eclipse 先安装jdk,再安装Eclipse,成功后开始建立py_java项目,在这个项目的存储目录SRC下建立test包,在test包中New-Class,新建MyDemo类,建好完成 ...

  7. 使用Badboy录制Web脚本 JMeter运行jmx脚本

    1.下载JDK 1.1 官网地址:https://www.oracle.com/technetwork/java/javase/downloads/index.html 在官网下载最新版本的JDK 1 ...

  8. Tomcat重启脚本restart.sh停止脚本stop.sh

    Tomcat重启脚本restart.sh停止脚本stop.sh Tomcat本身提供了 startup.sh(启动)shutdown.sh(关闭)脚本,我们在部署中经常会出现死进程形象,无法杀掉进程需 ...

  9. shell脚本分为三类:登录脚本、交互式脚本、非交互式脚本

    shell脚本分为三类:登录脚本.交互式脚本.非交互式脚本 一. 登录脚本类似于windows下的计算机设置中的登录脚本和账户设置下的登录脚本的合集(我是这么理解的哈). 其配置文件的关键词为pref ...

随机推荐

  1. activemq订阅发布模式(非持久订阅)

    生产者JMSProducer: package com.sun.test.aircraft.activemq.topic; import org.apache.activemq.ActiveMQCon ...

  2. java实现归并排序算法

    归并排序算法思想:分而治之(divide - conquer);每个递归过程涉及三个步骤第一, 分解: 把待排序的 n 个元素的序列分解成两个子序列, 每个子序列包括 n/2 个元素.第二, 治理: ...

  3. Out of office 模板

    I am out of the office until 0X/0X/201X. I will be checking my email regularly.  Please leave a comp ...

  4. Js、JQuery脚本兼容

    1.获取属性值 IE:$("#xxx").prop("title"); chrome:$("#xxx").attr("title& ...

  5. 关于JSP乱码问题

    关于jsp乱码问题的解决. 1 最基本的乱码问题. 这个乱码问题是最简单的乱码问题.一般新会出现.就是页面编码不一致导致的乱码. <%@ page language="java&quo ...

  6. vue打包后出现一些map文件的解决方法

    Vue打包后出现一些map文件的解决办法: 问题: 可能很多人在做vue项目打包,打包之后js中,会自动生成一些map文件,那我们怎么把它去掉不要呢? 1.运行  cnpm run build  开始 ...

  7. Java中Object转化为int类型

    转自:http://blog.sina.com.cn/s/blog_5f8421fb010162kb.html Java中由Object类型转化为int类型时,不能直接转化,先是将Object类型转化 ...

  8. 尚学堂 hadoop

    mr spark storm 都是分布式计算框架,他们之间不是谁替换谁的问题,是谁适合做什么的问题. mr特点,移动计算,而不移动数据. 把我们的计算程序下发到不同的机器上面运行,但是不移动数据. 每 ...

  9. Popup.js

    test.html <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><HTML> ...

  10. 在 Flash ActionScript 2.0 中调用 Javascript 方法

    本篇文章由:http://xinpure.com/call-the-javascript-method-in-flash-actionscript-2-0/ 在 Flash ActionScript ...