视频路书编辑器完善

This commit is contained in:
lishuo committed 2022-05-30 15:17:55 +08:00
1 parent 17c2a44e40
commit 9f0f42981e
12 files changed
+5980 -175

No files matched your search

@@ -71,12 +71,51 @@ namespace Assets.Scripts.Scenes.VideoRide
bone_bottle_2 = transform.Find("bone_cable_20");
}
//人物状态
public const int HERO_UP = 0;
public const int HERO_RIGHT = 1;
public const int HERO_DOWN = 2;
public const int HERO_LEFT = 3;
//人物当前行走的方向状态
public int state = 0;
//人物移动速度
public int moveSpeed = 2;
void setHeroState(int newState)
{
//根据当前人物方向与上一次备份的方向计算出模型旋转的角度
Vector3 transformValue = new Vector3();
//模型移动的位置数值
switch (newState)
{
case HERO_UP:
transformValue = Vector3.forward * Time.deltaTime;
break;
case HERO_DOWN:
transformValue = (-Vector3.forward) * Time.deltaTime;
break;
case HERO_LEFT:
transformValue = Vector3.left * Time.deltaTime;
break;
case HERO_RIGHT:
transformValue = (-Vector3.left) * Time.deltaTime;
break;
}
//移动人物
transform.Translate(transformValue * moveSpeed, Space.World);
state = newState;
}
protected virtual void Update()
{
#if UNITY_EDITOR
#endif
timer -= Time.deltaTime;
CreateHeadImage();
CharacterControl();
Turn();
while (timer <= 0)
{
try
@@ -90,7 +129,6 @@ namespace Assets.Scripts.Scenes.VideoRide
ComputeRecord();
ComputeVideo();
RayCastHit();
Turn();
}
ComputeAnimator();//控制动画
timer += 1f;
@@ -104,6 +142,52 @@ namespace Assets.Scripts.Scenes.VideoRide
}
}
private Vector3 rotation = Vector3.zero;
private void CharacterControl()
{
float KeyVertical = Input.GetAxis("Vertical");
float KeyHorizontal = Input.GetAxis("Horizontal");
var delta = 0.2f;
var zdelta = 0.1f;
//控制人物左右倾斜
if (Input.GetKey(KeyCode.Q))
{
rotation.y -= delta;
rotation.z += zdelta;
transform.DORotate(rotation, 0);
}
if (Input.GetKey(KeyCode.E))
{
rotation.y += delta;
rotation.z -= zdelta;
transform.DORotate(rotation, 0);
}
//空格键记录当前人物数据
if (Input.GetKey(KeyCode.Space))
{
Debug.Log($"{manager.GetCurrentFrame()}:{transform.rotation.y},{transform.rotation.z},{transform.position.x}");
}
//人物前后左右
if (KeyVertical == -1)
{
setHeroState(HERO_DOWN); //下
}
else if (KeyVertical == 1)
{
setHeroState(HERO_UP); //上
}
if (KeyHorizontal == 1)
{
setHeroState(HERO_RIGHT); //右
}
else if (KeyHorizontal == -1)
{
setHeroState(HERO_LEFT); //左
}
}
//人物碰撞
void OnCollisionEnter(Collision collision)
@@ -111,7 +195,7 @@ namespace Assets.Scripts.Scenes.VideoRide
}
void RayCastHit()
void RayCastHit()
{
Vector3 pos = transform.position;
Ray ray = new Ray(pos, new Vector3(0, 0, 1));
@@ -132,104 +216,56 @@ namespace Assets.Scripts.Scenes.VideoRide
animator.SetFloat("speed", (float)speed);
animator.SetFloat("grade", (float)currentSlope);
animator.SetFloat("power", (float)power);
animator.SetFloat("bearing", bearing);
//播放喝水和回头的动画
var headBack = ticks % 60 == 0 && speed > 0;
var drink = ticks % 125 == 0 && speed > 0;
animator.SetBool("headBack", headBack);
animator.SetBool("drinking", drink);
}
}
protected virtual int GetCurrentFrame()
{
protected virtual int GetCurrentFrame()
{
return manager.GetCurrentFrame();
}
private bool animated = false;
private float offset = 0;
private Vector3 rotation = Vector3.zero;
protected CustomRange currentRange { get; set; }
//控制角色进行向左或向右
private CustomRange pre;
private CustomRange next;
protected virtual void Turn()
{
//控制人物的转向
var currentFrame = GetCurrentFrame();
currentRange = manager.mockDirection.Where(c => c.Start < currentFrame && c.End > currentFrame).FirstOrDefault();
if (currentRange != null)
{
bearing = currentRange.RotationY;
rotation.y = currentRange.RotationY;
rotation.z = currentRange.RotationZ;
}
else
{
rotation.y = 0;
rotation.z = 0;
bearing = 0;
}
var headBack = ticks % 60 == 0 && speed > 0 && bearing == 0;
var drink = ticks % 125 == 0 && speed > 0 && bearing == 0;
var config = manager.mockDirection;
animator.SetFloat("bearing", bearing);
animator.SetBool("headBack", headBack);
animator.SetBool("drinking", drink);
pre = config[0];
next = config[0];
var waiting = ratio == 0 ? 1 : 1 / ratio;
//直角拐弯
if (Math.Abs(bearing) > 30)
for (int i = 0; i < config.Count; i++)
{
if (!animated)
if (config[i].KeyFrame >= currentFrame)
{
animated = true;
var tween = transform.DORotate(new Vector3(0, bearing, -bearing/5), waiting);
tween.onComplete += () =>
{
var zoffset = bearing / 10.5f;
var doMoveX = transform.DOMoveX(transform.position.x + zoffset, waiting);
doMoveX.onComplete += () =>
{
offset = -zoffset;
};
};
tween.SetEase(Ease.InOutSine).SetLoops(2, LoopType.Incremental);
pre = i > 0 ? config[i - 1] : config[i];
next = config[i];
break;
}
}
else
{
//直角拐弯回正
if (offset != 0)
{
var cpoffset = offset;
transform.DORotate(new Vector3(0, bearing, 0), 1.2f * waiting).onComplete += () =>
{
transform.DOMoveX(transform.position.x + cpoffset, 1.2f * waiting).onComplete += () =>
{
animated = false;
};
};
offset = 0;
}
//正常拐弯
else
{
transform.DORotate(rotation, 0.6f);
}
}
}
Vector3 current;
Vector3 forward;
//0-90 右转弯 -90-0左转弯
protected virtual void TurnAround()
{
StartCoroutine(MoveTo());
var p = new Vector3(0, pre.RotationY, pre.RotationZ);
var q = new Vector3(0, next.RotationY, next.RotationZ);
var t = (float)(currentFrame - pre.KeyFrame) / (float)(next.KeyFrame - pre.KeyFrame);
var rt = Vector3.Slerp(p, q, t);
transform.DORotate(rt, 0, RotateMode.Fast);
//控制人物的前后左右
var l = new Vector3(pre.PositionX, pre.PositionY, pre.PositionZ);
var s = new Vector3(next.PositionX, next.PositionY, next.PositionZ);
var pos = Vector3.Slerp(l,s, t);
transform.DOMove(pos,0);
//TODO:控制光线
}
protected virtual IEnumerator MoveTo()
{
float t = 0;
while (t < 1)
{
t += Time.deltaTime;
Vector3 v = Vector3.Lerp(current, forward, t);
current = v;
transform.DORotate(v, 0);
yield return new WaitForEndOfFrame();
}
}
//计算人物当前属性
protected virtual void ComputePlayer()
{
@@ -252,7 +288,9 @@ namespace Assets.Scripts.Scenes.VideoRide
}
}
}
Vector3 current { get; set; }
Vector3 forward { get; set; }
//计算当前人物的经纬度
protected virtual void Forward()
{
try
@@ -260,30 +298,13 @@ namespace Assets.Scripts.Scenes.VideoRide
if (mapData == null)
mapData = manager.GetMapData();
currentlatLon = manager.Along(totalDistance % mapData.TotalDistance);
////根据人物速度设置人物距离摄像头远近
//if (speed > 20 && speed < 30)
//{
// transform.DOMoveZ(3, 1f);
//}
//else if (speed > 30 && speed < 40)
//{
// transform.DOMoveZ(3.5f, 1f);
//}
//else if (speed > 40)
//{
// transform.DOMoveZ(4, 1f);
//}
//else
//{
// transform.DOMoveZ(3, 1f);
//}
}
catch (Exception e)
{
Debug.LogError(e);
}
}
protected float ratio = 1;
protected float ratio = 1;//视频播放速率
protected virtual void ComputeVideo()
{
@@ -369,7 +390,7 @@ namespace Assets.Scripts.Scenes.VideoRide
}
}
}
//显示人物海拔图的头像
public void CreateHeadImage()
{
if (head == null)
@@ -24,28 +24,38 @@ namespace Assets.Scripts.Scenes.VideoRide
{
public class CustomRange
{
public int KeyFrame { get; set; }//帧数
public int Start { get; set; }//起始帧
public int End { get; set; }//结束帧
public int PositionX { get; set; }
public int PositionY { get; set; }
public int PositionZ { get; set; }
public int RotationY { get; set; }
public int RotationZ { get; set; }
public int ShadowDirection { get; set; }
public float PositionX { get; set; }
public float PositionY { get; set; }
public float PositionZ { get; set; }
public float RotationY { get; set; }
public float RotationZ { get; set; }
public float LightY { get; set; }
private const float defaultRotationY = 0;
private const float defaultRotationZ = 0;
private const float defaultPositionX = 0;
private const float defaultPositionY = -1;
private const float defaultPositionZ = 3;
private const float defaultLightY = 0;
public static CustomRange Read(string s)
{
//243~573:-15,13,12
// - 代表默认值
//KeyFrame:RotationY,RotationZ,PositionX,PositionY,PositionZ,LightY
var result = s.Split(':');
var range = result[0].Split('~');
var v = result[1].Split(',');
CustomRange r = new CustomRange()
{
Start = Convert.ToInt32(range[0]),
End = Convert.ToInt32(range[1]),
RotationY = Convert.ToInt32(v[0]),
RotationZ = Convert.ToInt32(v[1]),
PositionX = Convert.ToInt32(v[2]),
KeyFrame = Convert.ToInt32(result[0]),
RotationY = v[0].Equals("-") ? defaultRotationY : (float)Convert.ToDouble(v[0]),
RotationZ = v[1].Equals("-") ? defaultRotationZ : (float)Convert.ToDouble(v[1]),
PositionX = v[2].Equals("-") ? defaultPositionX : (float)Convert.ToDouble(v[2]),
PositionY = v[3].Equals("-") ? defaultPositionY : (float)Convert.ToDouble(v[3]),
PositionZ = v[4].Equals("-") ? defaultPositionZ : (float)Convert.ToDouble(v[4]),
LightY = v[5].Equals("-") ? defaultLightY : (float)Convert.ToDouble(v[5]),
};
return r;
}
@@ -48,14 +48,6 @@ namespace Assets.Scripts.Scenes.VideoRide
protected override void Turn()
{
base.Turn();
if (currentRange != null)
{
transform.DOMoveX(currentRange.PositionX, 0.8f);
}
else
{
transform.DOMoveX(1, 0.8f);
}
}
protected override void ComputePlayer()
{
+2 -2
View File
@@ -19,9 +19,9 @@ public class MultiTips:PFUIText
if (result.result)
{
tips = result.data.ToArray();
random = new System.Random();
currentIndex = random.Next(0, tips.Length);
}
random = new System.Random();
currentIndex = random.Next(0, tips.Length);
SetText();
}
// Start is called before the first frame update