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. DevExpress TreeList使用

    using System; using System.Collections.Generic; using System.Drawing; using System.Windows.Forms; us ...

  2. MongoDB数据库设计中6条重要的经验法则

    Part 1 原文:6 Rules of Thumb for MongoDB Schema Design: Part 1 By William Zola, Lead Technical Support ...

  3. vue - config(index.js)

    描述:我想,这是调用最多的一个文件了吧(无论是dev,还是prod) 'use strict' // Template version: 1.3.1 // see http://vuejs-templ ...

  4. [学习笔记—Objective-C]《Objective-C-基础教程 第2版》第九章 内存管理

    内存管理: 确保在须要的时候分配内存,在程序运行结束时释放占用的内存 假设仅仅分配内存而不释放内存,则会发生内存泄漏(leak memory),程序的内存占用量不断添加.终于会被耗尽并导致程序崩溃. ...

  5. 投票ajax请求代码(点赞代码)

    function vote(url, arr) { jq.ajax({ cache: false, async: false, url: url, type: 'post', data: {info_ ...

  6. Tomcat源代码解析系列

    学web也有一段时间了.为了从底层了解web应用在Tomcat中的执行,决定看一下Tomcat的源代码參见<How Tomcat works>    和大牛博客.对大体架构有了一定的了解, ...

  7. 【Python】学习笔记十:字典

    字典是Python中唯一的映射类型(哈希表) 字典的对象时可变的,但字典的键值必须是用不可变对象,并且一个字典中可以使用不同类型的键值 1.定义字典 dict={key1:value1,key2:va ...

  8. Python 入门demo第二篇

    循环执行逻辑 #-*- coding: UTF-8 -*- import time import urllib2 def task(i): urlstr='http://baidu.com' html ...

  9. Thread.sleep(0)的作用

    我们可能经常会用到 Thread.Sleep 函数来使线程挂起一段时间.那么你有没有正确的理解这个函数的用法呢?思考下面这两个问题: 假设现在是 2008-4-7 12:00:00.000,如果我调用 ...

  10. Difference between End-to-end testing and System testing

    www.guru99.com/end-to-end-testing.html