首页 > 其他分享 >Unity手写模拟DoTween中的To功能

Unity手写模拟DoTween中的To功能

时间:2024-06-21 19:29:17浏览次数:8  
标签:float DoTween DT Action Unity 手写 action dt public

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class DT : MonoBehaviour
{
    public float beginValue, endValue;
    public float beginTime, times;
    public Action<float> action;
    public Action onComplete;
    public static DT To(Action<float> action, float beginvalue, float endvalue, float time)
    {
        GameObject go = new GameObject("DT");
        DT dt = go.AddComponent<DT>();
        dt.beginValue = beginvalue;
        dt.endValue = endvalue;
        dt.times = time;
        dt.action = action;
        dt.beginTime = Time.time;
        return dt;
    }

    public DT OnComplete(Action action)
    {
        onComplete = action;
        return this;
    }
    // Update is called once per frame
    void Update()
    {
        if (Time.time - beginTime <= times)
        {
            float value = Mathf.Lerp(beginValue, endValue, (Time.time - beginTime) / times);
            action?.Invoke(value);
        }
        else
        {
            onComplete?.Invoke();
            Destroy(gameObject);
        }
    }
}

标签:float,DoTween,DT,Action,Unity,手写,action,dt,public
From: https://blog.csdn.net/djrjnfjdjejb/article/details/139868074

相关文章

  • Unity3D轮转图(有回正效果)
    注意:MainCamera需要挂载PhysicsRayCaster      Hierarchy中添加UI里面的EventSystem对象(用来相应拖拽事件)usingDG.Tweening;usingSystem.Collections.Generic;usingUnityEngine;usingUnityEngine.EventSystems;usingSystem.Linq;publicclassRotat......
  • Unity初始位置初始化设置
    一、Transform面板介绍参数说明:        Position:位置;        Rotation:角度;        Scale:   比例。二、在Transform面板填写参数,如图所示:三、编写代码转换物体位置、角度、比例   1、位置转换:代码说明:        将目前游戏......
  • Unity相机及物体的移动步骤
    一、在Scenes场景文件夹建立游戏场景 二、在游戏场景里面建立游戏对象并且初始化位置1、建立游戏对象  2、初始化位置 3、把相机拉到游戏对象上(Reset一下位置)【注:这一步是操作相机的移动,物品的操作不用此步骤。】  三、建立CharacterController组件1、有Ca......
  • 【Unity动画系统】Amimator Controller的概念及其使用示例
    Unity的AnimatorController是动画系统中的一个核心组件,它负责管理和控制动画状态机(AnimationStateMachine)的行为。AnimatorController包含了动画状态、转换规则、以及用于控制动画流程的参数。AnimatorController的概念:动画状态(AnimationStates):代表单个动画剪辑(Animati......
  • 【名词解释】Unity中的3D物理系统:触发器
    在Unity的3D物理系统中,触发器(Trigger)是一种特殊的碰撞体,用于检测物体进入或离开一个特定区域的事件,但它不会像普通碰撞体那样产生物理碰撞反应。触发器通常用于实现非物理交互,如检测玩家进入特定区域、开启门、触发事件等。名词解释:Trigger:一种特殊的碰撞体,用于检测物体的进......
  • Pytorch搭建MyNet实现MNIST手写数字识别
    视频:https://www.bilibili.com/video/BV1Wf421B74f/?spm_id_from=333.880.my_history.page.click1.1Model类importtorchimporttorch.nnasnn#改进的三层神经网络classMyNet(nn.Module):def__init__(self):super().__init__()#定义全连接......
  • Unity3D 八叉树划分空间和可视化
    也许更好的阅读体验成果展示代码OctreeNodeusingSystem.Collections;usingSystem.Collections.Generic;usingUnityEngine;publicclassOctreeNode{//空间内包含的物体publicList<GameObject>areaObjects;//空间中心publicVector3center;......
  • Unity3D 用贝塞尔曲线进行弹道追踪
    usingSystem.Collections;usingSystem.Collections.Generic;usingUnity.Collections.LowLevel.Unsafe;usingUnityEngine;usingUnityEngine.UI;publicclassBulletLogic:MonoBehaviour{//Startiscalledbeforethefirstframeupdate//飞行速度最大......
  • 【名词解释】Unity3D物理射线(Physics Ray)含义及其用法
    Unity3D是一款流行的游戏开发引擎,它提供了一套强大的工具和功能来帮助开发者创建交互式3D内容。在Unity中,"物理射线"(PhysicsRay)通常指的是使用射线检测(Raycasting)来检测物体之间的碰撞或者检测射线与物体的交点。这在游戏开发中非常常见,用于实现如射击、视线检测、物体碰撞检......
  • Unity制作透明材质直接方法——6.15山大软院项目实训
    之前没有在unity里面接触过材质的问题,一般都是在maya或这是其他建模软件里面直接得到编辑好材质的模型,然后将他导入Unity里面,然后现在碰到了需要自己在Unity制作透明材质的情况,所以先搜索了一下有没有现成的方法,很多博客都是使用自己手搓shader的方法,如果对于透明材质的投射折......