unity一种简单的计算某一方法的耗时操作

2018-12-04  本文已影响0人  小巃

主要是用到Stopwatch,使用方法 如下

using UnityEngine;
/// <summary>
/// 自动加载
/// </summary>
public class AAutoLoad : MonoBehaviour {
    /// <summary>
    /// 计时器
    /// </summary>
    private float ff_timer;

    public GameObject ff_Target;
    /// <summary>
    /// 克隆物体的计数器
    /// </summary>
    public float ff_ProfabCounter;

    /// <summary>
    /// 时间间隔
    /// </summary>
    public float ff_TimeInterval = 10;
    /// <summary>
    /// 时间累加
    /// </summary>
    public float ff_Timer_Playing;
   Stopwatch ItSelf;

    // Use this for initialization
    void Start () {
        //首次加载
         ItSelf = new Stopwatch();
        ItSelf.Start();
        FFInstanceProfab();
        ItSelf.Stop();
        print(ItSelf.ElapsedMilliseconds); //毫秒
    }

    /// <summary>
    /// 实例化物体
    /// </summary>
    public void FFInstanceProfab()
    {

        GameObject _game = Instantiate(ff_Target) as GameObject;
        //_game.transform.SetParent(transform);
        _game.transform.parent = transform;
        _game.transform.localPosition = Vector3.zero;
        _game.transform.name = ff_ProfabCounter+"";
    }
}
上一篇下一篇

猜你喜欢

热点阅读