zoukankan      html  css  js  c++  java
  • 简易时钟

    内容来源于开发者社区

    用到的代码如下:

    using UnityEngine;
    using System.Collections;
    using System;
    
    public class ClockAnimator : MonoBehaviour
    {
        private const float
            hoursToDegrees = 360f / 12f,
            minutesToDegrees = 360f / 60f,
            secondsToDegrees = 360f / 60f;
    
        public Transform hours, minutes, seconds;
    
        public bool analog = false;
    
        // Use this for initialization
        void Start()
        {
        }
    
        // Update is called once per frame
        void Update()
        {
            if (analog)
            {
                TimeSpan timeSpan = DateTime.Now.TimeOfDay;
                hours.localRotation = Quaternion.Euler(0f, 0f, (float)timeSpan.TotalHours * -hoursToDegrees);
                minutes.localRotation = Quaternion.Euler(0f, 0f, (float)timeSpan.TotalMinutes * -minutesToDegrees);
                seconds.localRotation = Quaternion.Euler(0f, 0f, (float)timeSpan.TotalSeconds * -secondsToDegrees);
                Debug.Log(secondsToDegrees.ToString());
            }
            else
            {
                DateTime time = DateTime.Now;
                hours.localRotation = Quaternion.Euler(0f, 0f, time.Hour * -hoursToDegrees);
                minutes.localRotation = Quaternion.Euler(0f, 0f, time.Minute * -minutesToDegrees);
                seconds.localRotation = Quaternion.Euler(0f, 0f, time.Second * -secondsToDegrees);
                Debug.Log(time.Second * -secondsToDegrees);
            }
        }
    }

    //为了获得和场景视图相机相似的视角,选择相机,然后从菜单中选择GameObject / Align View to Selected。

    //为了使指针旋转起来,我们需要改变他们的局部旋转。直接设置指针的localRotation就可以,这要使用四元数。四元数可以定义任意的旋转。 Quaternion.Euler

  • 相关阅读:
    单例模式
    自旋锁与互斥锁
    CAS无锁机制原理
    乐观锁和悲观锁
    读写锁
    Java锁机制-重入锁
    原 Linux搭建SVN 服务器2
    原 Linux搭建SVN 服务器
    Sublime Text 3 破解版 + 注册机 + 汉化包 + 教程
    Sublime Text 3 常用插件以及安装方法(转)
  • 原文地址:https://www.cnblogs.com/hometown/p/3736934.html
Copyright © 2011-2022 走看看