Lynn

Lynn's Life


  • 首页

  • 归档

  • 随笔

  • 标签

  • 分类

  • 搜索

Unity 视频播放

发表于 2018-01-10 | 阅读次数:
Handheld.PlayFullScreenMovie播放视频

paste image

5.6新系统——Video Player(转载)

不久前Unity正式发布了5.6版本,作为5.x版本的最后一版还是有不少给力的更新的。其中新加入了一个Video Player控件,用以取代之前的MovieTexture。虽然还是alpha版本的功能,但是在视频导入编辑和播放等功能上比之前的MovieTexture已经好上很多。当然Unity还是保留了MovieTexture以防出现一个不可用的情况。

Video Player介绍(墙外的世界)
VideoPlayer API
首先导入视频,因为默认不进行编码转换,现在的视频导入速度比以前快很多。
paste image

paste image
在视频的Import Settings面板上,我们可以选择导入的版本是新的VideoClip或者是旧版的MovieTexture。同时可以设置编码转换,转换的速度视视频的大小而定。

Unity5.6提供了多种生成Video Player控件的方式:

  1. 新建一个空白的Video Player:选择菜单栏的GameObject->Video->Video Player或者在Hierarchy面板上选择Create->Video->Video Player或者右击Hierarchy面板空白处选择Video->Video Player。
  2. 直接将导入的VideoClip拖入场景或者Hierarchy面板,生成的VideoPlayer控件的VideoClip将会自动被赋值,如果场景中存在MainCamera,Camera也会被自动赋值为MainCamera。
  3. 将导入的VideoClip拖动到场景中的Camera物体上,生成的VideoPlayer控件的VideoClip和MainCamera将会自动被赋值,模式默认选择Camera Far Plane。
  4. 将导入的VideoClip拖动到场景中的2D或者3D物体上,生成的VideoPlayer控件的VideoClip和Renderer将会自动被赋值,模式默认选择Material Override。
  5. 将导入的VideoClip拖动到场景中的UI物体上,生成的VideoPlayer控件的VideoClip将会自动被赋值,模式默认选择Render Texture。
    paste image

VideoPlayer的Inspector面板提供了基本的播放设置。我们可以选择播放源是指定的视频资源或者url路径,路径可以是本地路径或者http路径。
paste image

paste image

paste image

下面是一些比较大众化的设置:

  • Play On Awake:脚本载入时自动播放。
  • Wait For First Frame:决定是否在第一帧加载完成后才播放,只有在Play On Awake被勾选是才有效。可以防止视频最前几帧被跳过。(使用过程中发现勾选后视频无法自动播放,原因不明)
  • Loop:循环。
  • Playback Speed:播放速度。
    Video Player还提供了多种视频渲染的方式,包括Camera Far Plane,Camera Near Plane,Render Texture,Material Override,Api Only。
    paste image

  • Camera Far Plane:基于摄像机的渲染,渲染在摄像机的远平面上,需要设置用于渲染的摄像机,同时可以修改alpha通道的值做透明效果,可用于背景播放器。
    paste image

  • Camera Near Plane:基于摄像机的渲染,渲染在摄像机的近平面上,需要设置用于渲染的摄像机,同时可以修改alpha通道的值做透明效果,可用作前景播放器。
    paste image

  • Render Texture:将视频画面保存在Render Texture上,以供物体或者RawImage使用,可以用来做基于UGUI的播放器。
    paste image

  • Material Override:将视频画面复制给所选Render的Material。需要选择具有Render组件的物体,可以选择赋值的材质属性。可制作360全景视频和VR视频。
    paste image

  • Api Only: 待研究。

其中Camera Far Plane,Camera Near Planehe和Render Texture可以通过设置Aspect Ratio来选择自适应分辨率的方式:
paste image

最后一个Audio Output Mode用于音频的播放,None表示不播放音频,Audio Source表示使用Audio Source进行播放,Direct字面理解应该是直接通过视频来播放,但是我选择这个选项的时候并没有声音。
paste image
我们需要新建一个AudioSource物体用于音频播放,Audio Source的Clip不需赋值,其余参数可调。

脚本控制(需引用UnityEngine.Video):
VideoPlayer的脚本控制与AudioSource相似,有常规的Play,Pause,Stop方法,也有用于进度控制的time,isPlaying,isLooping,frame,frameCount等属性。
VideoPlayer可以使用一系列事件来监听播放的各个动作:

errorReceived: 错误监听到时被执行。
frameDropped :有丢帧发生时被执行。
frameReady :新的一帧准备好时被执行。
loopPointReached :播放结束或播放到循环的点时被执行。
prepareCompleted :视频准备完成时被执行。
seekCompleted :查询帧操作完成时被执行。
started:在Play方法调用之后立刻调用。
下面是关于播放器的创建使用,loopPointReached和PrepareCompleted的用法介绍:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
using UnityEngine;
using UnityEngine.Video;
public class MyVideo : MonoBehaviour
{
public VideoPlayer vPlayer;
void Start () {
vPlayer.loopPointReached += EndReached;
vPlayer.Play();
}
void EndReached(VideoPlayer vPlayer)
{
Debug.Log("End reached!");
}
void Update () {
Debug.Log("Frame " + vPlayer.frame);
}
}

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
using UnityEngine;
using UnityEngine.Video;
public class HTTPVideoScript : MonoBehaviour
{
void Start () {
var vPlayer = gameObject.AddComponent<VideoPlayer>();
vPlayer.URL = "http://www.quirksmode.org/html5/videos/big_buck_bunny.mp4";
vPlayer.target = UnityEngine.Video.VideoTarget.CameraFrontPlane;
vPlayer.alpha = 0.5f;
vPlayer.prepareCompleted += Prepared;
vPlayer.Prepare();
}
void Prepared(VideoPlayer vPlayer)
{
Debug.Log("End reached!");
vPlayer.Play();
}
}

By: 蒋志杰

插件

现有比较常用的有AVPro,EasyMovieTexture,MobileMovieTexture

Unity3D之常见的路径(转载)
  1. Unity3D中的资源路径:
    Application.dataPath:此属性用于返回程序的数据文件所在文件夹的路径。例如在Editor中就是Assets了。
    Application.streamingAssetsPath:此属性用于返回流数据的缓存目录,返回路径为相对路径,适合设置一些外部数据文件的路径。
    Application.persistentDataPath:此属性用于返回一个持久化数据存储目录的路径,可以在此路径下存储一些持久化的数据文件。

  2. android平台
    Application.dataPath: /data/app/xxx.xxx.xxx.apk Application.streamingAssetsPath: jar:file:///data/app/xxx.xxx.xxx.apk/!/assets Application.persistentDataPath: /data/data/xxx.xxx.xxx/files Application.temporaryCachePath: /data/data/xxx.xxx.xxx/cache

  3. IOS平台
    Application.dataPath: Application/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/xxx.app/Data Application.streamingAssetsPath: Application/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/xxx.app/Data/Raw Application.persistentDataPath: Application/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/Documents Application.temporaryCachePath Application/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/Library/Caches 从上面的3张表格,我们可以看到 dataPath和streamingAssetsPath的路径位置一般是相对程序的安装目录位置,而

persistentDataPath和temporaryCachePath的路径位置一般是相对所在系统的固定位置

相关参考链接(Unity 视频播放方法,加载assetbundle和常用路径):
unity调用ios原生视频播放
Unity视频播放总结
StreamingAssets + WWW url not found
iOS Handheld.PlayFullScreenMovie Not working
AVPro Movie Capture Unity Asset Store
加载prefab

Unity 动画系统

发表于 2017-12-26 | 阅读次数:

在Unity 中 要加入旧动画系统,首先现在物体上加入Animation,然后在通过Animation面板添加动画。
反向播放动画:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
AnimationState clipState = _gameObject.animation["animationName"];
if(clipState != null)
{
if(obverse)
{
_gameObject.animation.Play (clipState.name);
clipState.speed = 1f;
clipState.time = 0f;
}
else // reverse
{
_gameObject.animation.Play (clipState.name);
clipState.speed = -1f;
clipState.time = clipState.length;
}
}

参考链接:http://www.ceeger.com/forum/read.php?tid=3647

VR fps 显示

发表于 2017-12-15 | 阅读次数:

VR FPS 帧率显示

  1. 找到你的VR Camera(或Center Eye Camera),创建 UI->Canvas
    设置Render Mode为 World Space;
    设置位置为(0,0,0.5)(push it out in front of the camera)
    设置Scale为(0.001,0.001,0.001)
  2. 点击Canvas,创建UI->Text
  3. Text加入下面的代码
    点击”F”键可以显示隐藏
    Note: It uses the new fancy Unity 5 Time.unscaledDeltaTime property !
    转载来自:http://talesfromtherift.com/vr-fps-counter/
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    using UnityEngine;
    using UnityEngine.UI;
    // Display FPS on a Unity UGUI Text Panel
    // To use: Drag onto a game object with Text component
    // Press 'F' key to toggle show/hide
    public class TextFPSCounter : MonoBehaviour
    {
    public Text text;
    public bool show = false;
    private const int targetFPS =
    #if UNITY_ANDROID // GEARVR
    60;
    #else
    75;
    #endif
    private const float updateInterval = 0.5f;
    private int framesCount;
    private float framesTime;
    void Start()
    {
    // no text object set? see if our gameobject has one to use
    if (text == null)
    {
    text = GetComponent<Text>();
    }
    }
    void Update()
    {
    if (Input.GetKeyDown(KeyCode.F))
    {
    show = !show;
    }
    // monitoring frame counter and the total time
    framesCount++;
    framesTime += Time.unscaledDeltaTime;
    // measuring interval ended, so calculate FPS and display on Text
    if (framesTime > updateInterval)
    {
    if (text != null)
    {
    if (show)
    {
    float fps = framesCount / framesTime;
    text.text = System.String.Format("{0:F2} FPS", fps);
    text.color = (fps > (targetFPS - 5) ? Color.green :
    (fps > (targetFPS - 30) ? Color.yellow :
    Color.red));
    }
    else
    {
    text.text = "";
    }
    }
    // reset for the next interval to measure
    framesCount = 0;
    framesTime = 0;
    }
    }
    }

OBI ROPE 插件的一些属性

发表于 2017-11-09 | 阅读次数:

paste image
前一段时间学习的obi插件,感觉挺强悍的,就是有些弄不懂参数都是什么,调了参数,根本不知所云。但也是学习了一下,上面的图片大概就是一些参数的作用,仅供参考。

Unity相机的旋转缩放

发表于 2017-10-30 | 分类于 Unity | 阅读次数:

摄像机的旋转,这里用的Rotate。
摄像机的缩放有两种方法,一种是filedOfView的改变,一种是改变摄像机Z轴的位置。都是可以的,下面是代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
public float zoomSpeed = 10; //缩放速度
public float rotateSpeed = 1; //旋转速度
private float delta_z;
private float delta_rotation_x, delta_rotation_y;
void Update()
{
//摄像机旋转
if (Input.GetMouseButton(0))
{
delta_rotation_x = -Input.GetAxis("Mouse X") * rotateSpeed;
delta_rotation_y = Input.GetAxis("Mouse Y") * rotateSpeed;
transform.Rotate(0, delta_rotation_x, 0, Space.World);
transform.Rotate(delta_rotation_y, 0, 0);
}
//摄像机缩放
if (Input.GetAxis("Mouse ScrollWheel") != 0)
{
delta_z = -Input.GetAxis("Mouse ScrollWheel") * zoomSpeed;
// //第一种方法,改变注摄像机的filedOfView
// Camera.main.fieldOfView += delta_z;
// if (Camera.main.fieldOfView < 10) Camera.main.fieldOfView = 10;
// if (Camera.main.fieldOfView > 100) Camera.main.fieldOfView = 100;
//第二种方法,改变摄像机的Z轴值
transform.Translate(0, 0, -delta_z);
if (transform.localPosition.z > -2)
{
transform.localPosition = new Vector3(transform.localPosition.x, transform.localPosition.y, -2);
}
if (transform.localPosition.z < -25)
{
transform.localPosition = new Vector3(transform.localPosition.x, transform.localPosition.y, -25);
}
}
}

Unity物体基本运动

发表于 2017-10-30 | 分类于 Unity | 阅读次数:

基础

1.获取方向键

1
2
3
4
Input.GetAxis("Horizontal") > 0; //右方向键
Input.GetAxis("Horizontal") < 0; //左方向键
Input.GetAxis("Vertical") > 0; //上方向键
Input.GetAxis("Vertical") < 0; //下方向键

2.获取键盘
KeyCode 列表请参考Unity官网:https://docs.unity3d.com/ScriptReference/KeyCode.html

1
2
3
4
5
Input.anyKeyDown //任意键按下
Input.anyKey //任意键按下不放
Input.GetKey(KeyCode.A) //字母“A”按下不放
Input.GetKeyDown(KeyCode.Space) //空格键按下
Input.GetKeyUp(KeyCode.Escape) //Esc键松开

3.获取鼠标点击

1
2
3
4
5
6
7
8
9
10
11
12
13
14
Input.GetMouseButton(0) //按压鼠标左键
Input.GetMouseButton(1) //按压鼠标右键
Input.GetMouseButton(2) //按压滚轮键(待验证)
Input.GetMouseButtonDown(0) //点击鼠标左键
Input.GetMouseButtonDown(1) //点击鼠标右键
Input.GetMouseButtonDown(2) //点击滚轮键(待验证)
Input.GetMouseButtonUp(0) //抬起鼠标左键
Input.GetMouseButtonUp(1) //抬起鼠标右键
Input.GetMouseButtonUp(2) //抬起滚轮键
Input.mousePosition //鼠标点击的像素位置
Input.GetAxis("Mouse X")>0 //鼠标沿着屏幕X移动时触发,向右
Input.GetAxis("Mouse X")<0 //鼠标沿着屏幕X移动时触发,向左
Input.GetAxis("Mouse Y")>0 //鼠标沿着屏幕Y移动时触发,向上
Input.GetAxis("Mouse Y")<0 //鼠标沿着屏幕Y移动时触发,向下

4.获取滚轮的滚动

1
2
Input.GetAxis("Mouse ScrollWheel")>0 //向上滚动
Input.GetAxis("Mouse ScrollWheel")<0 //向下滚动

5.获取触摸屏参数

1
2
3
4
Input.touchCount //触摸手指个数
Input.GetTouch(i) //得到第i个触摸手指
if (Input.GetTouch(0).phase == TouchPhase.Moved) //判断手指是否触摸移动
Input.GetTouch(0).deltaPosition //从上一帧开始获取手指的移动

TouchPhase类型:
paste image

物体移动

1.指定方向移动
2.全方向移动
3.坐标移动

指定方向移动和全方位移动,都是按照物体本身的轴所移动的,坐标移动是按照世界坐标移动的。
示例:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
public float speed = 1f;
void Update () {
//指定方向移动
if (Input.GetAxis("Horizontal") > 0) //左右方向键,>0为右方向键
{
transform.Translate(Vector3.forward * speed * Time.deltaTime);
}
if(Input.GetAxis("Vertical") < 0) //上下方向键,<0为下方向键
{
transform.Translate(Vector3.right * speed * Time.deltaTime);
}
//全方向移动
if (Input.GetKey(KeyCode.K))
{
transform.Translate(speed * Time.deltaTime,0, speed*Time.deltaTime);
}
//坐标移动
if (Input.GetKey(KeyCode.Z))
{
transform.localPosition += new Vector3(speed * Time.deltaTime, 0, speed * Time.deltaTime);
}
if(Input.GetKey(KeyCode.M))
{
transform.position += new Vector3(speed * Time.deltaTime, 0, speed * Time.deltaTime);
}
}

物体旋转

1.Rotate();
2.transform.localRotation,transform.rotation
3.RotateAround();RotateAroundLocal();

上面前两个比较常用,RotateAround 主要是围绕其他的物体做运动

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
public float speed = 2f;
public Transform roundTran;
public Vector3 rotateQua = Vector3.zero;
private void Start()
{
roundTran = this.transform.parent;
}
void Update () {
if(Input.GetKey(KeyCode.R))
{
transform.Rotate(Vector3.up * speed * Time.deltaTime);
}
if(Input.GetMouseButton(0)) //点击鼠标左键
{
transform.RotateAround(roundTran.transform.localPosition,Vector3.forward,speed *Time.deltaTime);
}
if(Input.touchCount>0 && Input.GetTouch(0).phase == TouchPhase.Moved) //触摸屏,点击一个手指,并且移动时
{
Vector2 touchDeltaPos = Input.GetTouch(0).deltaPosition;
transform.localRotation = Quaternion.Euler(touchDeltaPos.x * speed * Time.deltaTime, 0, touchDeltaPos.y * speed * Time.deltaTime);
}
if(Input.GetKey(KeyCode.L))
{
rotateQua += new Vector3(10 * speed * Time.deltaTime, 10 * speed * Time.deltaTime, 0);
transform.localRotation = Quaternion.Euler(rotateQua);
}
}

物体缩放

1.localScale
2.相机的拉近拉远,Camera的filedOfView

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
public float speed = 3;
RaycastHit hit;
private float scale = 1;
private float cameraField = 60;
void Start()
{
cameraField = Camera.main.fieldOfView;
}
void Update()
{
//从主摄像机发射一条射线
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast(ray, out hit))
{
if(hit.transform == this.transform)
{
if (Input.GetAxis("Mouse ScrollWheel") != 0)
{
scale += Input.GetAxis("Mouse ScrollWheel") * speed * Time.deltaTime;
transform.localScale = new Vector3(scale, scale, scale);
//设置Camera的fieldOfView来放大缩小物体,其实不太好,除非一开始摄像机就看向物体。
//cameraField += -1 * Input.GetAxis("Mouse ScrollWheel") * speed * Time.deltaTime;
//Camera.main.fieldOfView = cameraField;
//Camera.main.transform.LookAt(this.transform);
}
}
}
}

其中四元数是略懂,只是知道能够防止万向锁,希望在应用中深入理解吧

参考网址:
http://www.cnblogs.com/fortomorrow/archive/2012/10/30/unity05.html
四元数:http://blog.csdn.net/candycat1992/article/details/41254799
http://www.taikr.com/article/535

Unity 雷达图

发表于 2017-10-27 | 分类于 Unity | 阅读次数:

1.原理篇
UGUI是一个CanvasRenderer进行绘制,所有的控件和可显示的元素都是Graphic。
比方说Image,Text 都是继承Graphic,有Graphic肯定是要有CanvasRenderer的。关于Graphic的一些绘制原理可以查看参考网站的第一个网址。

我这里绘制的雷达图,也是在UGUI上,通过继承Graphic,连接中心点和多边形的顶点绘制三角形绘制的。

2.最后来上代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
using System.Collections.Generic;
/// <summary>
/// 绘制多边形雷达图
/// 以下是五边形的顶点示意图,以中心点为原点,绘制5个三角形,012,023,034,045,051
///
/// 2
///
/// 3 0 1
///
/// 4 5
/// </summary>
[AddComponentMenu("UI/Polygon")]
public class Polygon : Graphic
{
private List<Vector2> vertexList = new List<Vector2>(); //顶点的坐标,顶点数量必须大于2
public List<float> VertextRanges = new List<float>() { 1,1,1,1,1 };
private int PointCount = 5;
public float Max_Value = 100.0f;
private Vector2 OriPoint = new Vector2(0, 0);
protected override void Start()
{
base.Start();
Init();
}
private void Init()
{
vertexList.Clear();
for(int i=0;i<PointCount;i++)
{
float cornerAngle = 2.0f * Mathf.PI / 360 * (18 + (360/PointCount) * i);
vertexList.Add(new Vector2(Max_Value * VertextRanges[i] * Mathf.Cos(cornerAngle), Max_Value * VertextRanges[i] * Mathf.Sin(cornerAngle)));
}
}
protected override void OnPopulateMesh(VertexHelper vh)
{
base.OnPopulateMesh(vh);
Init();
List<UIVertex> targetVertexList = new List<UIVertex>();
for(int i=0;i<vertexList.Count;i++)
{
UIVertex oriVertex = new UIVertex();
oriVertex.position = OriPoint;
oriVertex.color = color;
targetVertexList.Add(oriVertex);
for (int j =0;j<2;j++)
{
UIVertex vertex = new UIVertex();
if(i+j >= vertexList.Count)
{
vertex.position = vertexList[i + j - vertexList.Count];
}else
{
vertex.position = vertexList[i + j];
}
vertex.color = color;
targetVertexList.Add(vertex);
}
}
vh.Clear();
vh.AddUIVertexTriangleStream(targetVertexList);
}
}

效果图:
paste image

参考网址:http://blog.csdn.net/langresser_king/article/details/46928197
http://www.xshadow.org/index.php/archives/73

科学上网的那些事

发表于 2017-10-27 | 分类于 网络 | 阅读次数:

ShadowSocks(影梭)不完全指南
影梭是我用的比较久的一个科学上网工具。13年和14年左右用到蓝灯,现在已经不太好用了。影梭也都是用免费的账号密码,不过这段时间也不好用。

DomeCross插件
穹顶穿越是最近才买的一个浏览器插件,适合基于Chrome浏览器的插件,一个月9块钱,还是挺便宜的,现在用了一两天,感觉速度也挺快。

搬瓦工
因为前两天无法科学上网,也没有DomeCross插件,导致我Hexo官网都无法打开,所以很想买个VPS,就瞄准了搬瓦工。搬瓦工的19.99美元一年的最低配的VPS,我感觉就可以满足我的需求。但就是没有货,所以先买个浏览器插件先用着,等什么时候有货了,一定要买一个VPS。
关于VPS,根据VPS大全中的说法,买KVM的机房是比较好的。搬瓦工全部套餐地址

搬瓦工优惠码和购买教程
也可以在买的时候重新查一下。

像早期的红杏买了一年,结果开发者被请去喝茶了,我只用了一个月不到就没得用了,钱也没退。希望DomeCross可以稳定些,也希望我能尽快买个VPS。

SteamVR和VRTK

发表于 2017-08-17 | 阅读次数:

SteamVR
最近又重新看了SteamVR,发现场景可以用一个代码过渡切换。所以常学常新还是有道理的。

VRTK
VRTK的所有例子我都做了一遍,看了一遍,然后写出了一些抓取的代码,现在使用的还有些少,希望能够用上。

关于SteamVR,感觉也就是相关的事件少一些,就是VRTK要多一些平台。

参考链接:
SteamVR脚本解析
Camera 组件介绍
手柄事件
SteamVR_Control 详解(大概的一个工作流程和会用到的组件)
手柄射线拾取
抓取物体、投掷 (父物体为手柄的方法,还有很多错误的解决方法)
手柄抓取物体(最常见的一篇文章,感觉上面一篇文章更好些)
抓取和投掷(父物体方法)
Unity中Tracker问题
SteamVR(HTC Vive) Unity插件深度分析
VRTK Documentation
SteamVR Unity工具包(三):控制器交互
VRTK 3.2.0版本Demo详解
SteamVR(HTC Vive) Unity插件深度分析(四)
开发HTC Vive应用的重要资源

DoTween 序列和路径

发表于 2017-08-13 | 阅读次数:

参考来自:http://blog.csdn.net/lyh916/article/details/45888117

创建Sequence:
Sequence可以包含Sequence,当执行一个Sequence时会顺序执行Tweener,可以使用Insert方法实现同时执行。
Sequence的方法:

1
2
3
4
5
6
7
8
9
10
11
static DOTween.Sequence()
Append(Tween tween)
AppendCallback(TweenCallback callback)
AppendInterval(float interval)
Insert(float atPosition, Tween tween)
InsertCallback(float atPosition, TweenCallback callback)
Join(Tween tween)
Prepend(Tween tween)
PrependCallback(TweenCallback callback)
PrependInterval(float interval)

例子:

1
2
3
4
5
6
7
8
9
10
// Grab a free Sequence to use
Sequence mySequence = DOTween.Sequence();
// Add a movement tween at the beginning
mySequence.Append(transform.DOMoveX(2, 1));
// Add a rotation tween as soon as the previous one is finished
mySequence.Append(transform.DORotate(new Vector3(0, 180, 0), 1));
// Delay the whole Sequence by 1 second
mySequence.PrependInterval(1);
// Insert a scale tween for the whole duration of the Sequence
mySequence.Insert(0, transform.DOScale(new Vector3(2, 2, 2), mySequence.Duration()));

等同于:

1
2
3
4
5
Sequence mySequence = DOTween.Sequence();
mySequence.Append(transform.DOMoveX(2, 1)) //第一个运动
.Append(transform.DORotate(new Vector3(0, 180, 0), 1)) //第二个运动
.PrependInterval(1) //运动延迟
.Insert(0, transform.DOScale(new Vector3(2, 2, 2), mySequence.Duration()));//跟上两个运动同时进行的运动

参考网址:
http://blog.csdn.net/u014230923/article/details/51469848

1234
Lynn

Lynn

35 日志
2 分类
17 标签
GitHub 微博 Instagram
© 2021 Lynn
由 Hexo 强力驱动
|
主题 — NexT.Gemini v5.1.3