improve live

This commit is contained in:
左右看
2023-07-07 05:30:20 +08:00
parent f5573496ee
commit 6a89bba5e3
15 changed files with 443 additions and 117 deletions
+145
View File
@@ -0,0 +1,145 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;
/// <summary>
/// A simple free camera to be added to a Unity game object.
///
/// Keys:
/// wasd / arrows - movement
/// q/e - up/down (local space)
/// r/f - up/down (world space)
/// pageup/pagedown - up/down (world space)
/// hold shift - enable fast movement mode
/// right mouse - enable free look
/// mouse - free look / rotation
///
/// </summary>
public class FreeCam : MonoBehaviour
{
/// <summary>
/// Normal speed of camera movement.
/// </summary>
public float movementSpeed = 10f;
/// <summary>
/// Speed of camera movement when shift is held down,
/// </summary>
public float fastMovementSpeed = 100f;
/// <summary>
/// Sensitivity for free look.
/// </summary>
public float freeLookSensitivity = 3f;
/// <summary>
/// Amount to zoom the camera when using the mouse wheel.
/// </summary>
public float zoomSensitivity = 10f;
/// <summary>
/// Amount to zoom the camera when using the mouse wheel (fast mode).
/// </summary>
public float fastZoomSensitivity = 50f;
/// <summary>
/// Set to true when free looking (on right mouse button).
/// </summary>
private bool looking = false;
void Update()
{
var fastMode = Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift);
var movementSpeed = fastMode ? this.fastMovementSpeed : this.movementSpeed;
if (Input.GetKey(KeyCode.A) || Input.GetKey(KeyCode.LeftArrow))
{
transform.position = transform.position + (-transform.right * movementSpeed * Time.deltaTime);
}
if (Input.GetKey(KeyCode.D) || Input.GetKey(KeyCode.RightArrow))
{
transform.position = transform.position + (transform.right * movementSpeed * Time.deltaTime);
}
if (Input.GetKey(KeyCode.W) || Input.GetKey(KeyCode.UpArrow))
{
transform.position = transform.position + (transform.forward * movementSpeed * Time.deltaTime);
}
if (Input.GetKey(KeyCode.S) || Input.GetKey(KeyCode.DownArrow))
{
transform.position = transform.position + (-transform.forward * movementSpeed * Time.deltaTime);
}
if (Input.GetKey(KeyCode.Q))
{
transform.position = transform.position + (transform.up * movementSpeed * Time.deltaTime);
}
if (Input.GetKey(KeyCode.E))
{
transform.position = transform.position + (-transform.up * movementSpeed * Time.deltaTime);
}
if (Input.GetKey(KeyCode.R) || Input.GetKey(KeyCode.PageUp))
{
transform.position = transform.position + (Vector3.up * movementSpeed * Time.deltaTime);
}
if (Input.GetKey(KeyCode.F) || Input.GetKey(KeyCode.PageDown))
{
transform.position = transform.position + (-Vector3.up * movementSpeed * Time.deltaTime);
}
if (looking)
{
float newRotationX = transform.localEulerAngles.y + Input.GetAxis("Mouse X") * freeLookSensitivity;
float newRotationY = transform.localEulerAngles.x - Input.GetAxis("Mouse Y") * freeLookSensitivity;
transform.localEulerAngles = new Vector3(newRotationY, newRotationX, 0f);
}
float axis = Input.GetAxis("Mouse ScrollWheel");
if (axis != 0)
{
var zoomSensitivity = fastMode ? this.fastZoomSensitivity : this.zoomSensitivity;
transform.position = transform.position + transform.forward * axis * zoomSensitivity;
}
if (Input.GetKeyDown(KeyCode.Mouse1))
{
StartLooking();
}
else if (Input.GetKeyUp(KeyCode.Mouse1))
{
StopLooking();
}
}
void OnDisable()
{
StopLooking();
}
/// <summary>
/// Enable free looking.
/// </summary>
public void StartLooking()
{
looking = true;
Cursor.visible = false;
Cursor.lockState = CursorLockMode.Locked;
}
/// <summary>
/// Disable free looking.
/// </summary>
public void StopLooking()
{
looking = false;
Cursor.visible = true;
Cursor.lockState = CursorLockMode.None;
}
}
+11
View File
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: a45300b2c43d19444a0331fd08a640d2
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
+2 -3
View File
@@ -670,9 +670,8 @@ public class UmaViewerBuilder : MonoBehaviour
GameObject.Find("CriWare"),
GameObject.Find("CriWareLibraryInitializer"),
GameObject.Find("ViewerMain"),
GameObject.Find("Camera"),
GameObject.Find("Directional Light"),
GameObject.Find("AnimationCameraRoot"),
GameObject.Find("GlobalShaderController"),
GameObject.Find("AudioManager")
};
@@ -702,7 +701,7 @@ public class UmaViewerBuilder : MonoBehaviour
},
delegate ()
{
Gallop.Live.Director.instance.InitializeTimeline();
Gallop.Live.Director.instance.InitializeTimeline(characters.Count);
Gallop.Live.Director.instance.Play(live.MusicId, characters);
}
);
+1 -1
View File
@@ -128,7 +128,7 @@ public class UmaViewerGlobalShader : MonoBehaviour
{
//Used to calculate the correct outline
//Outline need more adjust in live
if (!UmaViewerUI.Instance.LiveTime)
if (UmaViewerBuilder.Instance.AnimationCamera != null)
{
if (UmaViewerBuilder.Instance.CurrentUMAContainer)
{
@@ -816,8 +816,6 @@ namespace Gallop
{
_prevLipKeyData = null;
_lastLipKeyData = null;
MouthMorphs.ForEach(morph => morph.weight = 0);
ChangeMorphMouth();
return;
}
@@ -826,42 +824,6 @@ namespace Gallop
_prevLipKeyData = _lastLipKeyData;
}
/*
float keyTime = (float)keyData_.frame / 60;
float easeTime = (float)keyData_.time/ 60;
float passTime = liveTime_ - keyTime;
float weightRatio = 0;
if (passTime >= easeTime)
{
weightRatio = 1;
}
else
{
float ratio = passTime / easeTime;
switch (keyData_.interpolateType)
{
case InterpolateType.Linear:
weightRatio = ratio;
break;
case InterpolateType.EaseIn:
weightRatio = Easing.EaseIn(ratio);
break;
case InterpolateType.EaseOut:
weightRatio = Easing.EaseOut(ratio);
break;
case InterpolateType.EaseInOut:
weightRatio = Easing.EaseInOut(ratio);
break;
default:
weightRatio = ratio;
break;
}
}
*/
float weightRatio = CalcMorphWeight(liveTime_, keyData_.time, keyData_.interpolateType, keyData_, null);
MouthMorphs.ForEach(morph => morph.weight = 0);
@@ -897,6 +859,9 @@ namespace Gallop
_lastLipKeyData = keyData_;
}
private LiveTimelineKeyFacialMouthData _prevMouthKeyData;
private LiveTimelineKeyFacialMouthData _lastMouthKeyData;
private LiveTimelineKeyFacialEyeData _prevEyesKeyData;
private LiveTimelineKeyFacialEyeData _lastEyesKeyData;
@@ -908,7 +873,48 @@ namespace Gallop
public void AlterUpdateFacialNew(ref FacialDataUpdateInfo updateInfo_, float liveTime_)
{
if(updateInfo_.eyeCur != null)
if (updateInfo_.mouthCur != null)
{
if (_lastMouthKeyData != updateInfo_.mouthCur)
{
_prevMouthKeyData = _lastMouthKeyData;
}
float weightRatio = CalcMorphWeight(liveTime_, updateInfo_.mouthCur.time, updateInfo_.mouthCur.interpolateType, updateInfo_.mouthCur, updateInfo_.mouthNext);
MouthMorphs.ForEach(morph => morph.weight = 0);
if (_prevMouthKeyData != null)
{
if (weightRatio != 1)
{
foreach (var part in _prevMouthKeyData.facialPartsDataArray)
{
if (part.FacialPartsId == 0) { continue; }
MouthMorphs[part.FacialPartsId - 1].weight = ((float)part.WeightPer / 100 * (1 - weightRatio)) * ((float)_prevMouthKeyData.weight / 100);
}
}
else
{
foreach (var part in _prevMouthKeyData.facialPartsDataArray)
{
if (part.FacialPartsId == 0) { continue; }
MouthMorphs[part.FacialPartsId - 1].weight = 0;
}
}
}
foreach (var part in updateInfo_.mouthCur.facialPartsDataArray)
{
if (part.FacialPartsId == 0) { continue; }
MouthMorphs[part.FacialPartsId - 1].weight += ((float)part.WeightPer / 100 * weightRatio) * ((float)updateInfo_.mouthCur.weight / 100);
}
ChangeMorphMouth();
_lastMouthKeyData = updateInfo_.mouthCur;
}
if (updateInfo_.eyeCur != null)
{
if (_lastEyesKeyData != updateInfo_.eyeCur)
{
@@ -9,7 +9,8 @@ namespace Gallop.Live.Cutt
// Fields
public LiveTimelineKeyFacialFaceData faceCur; // 0x0
public LiveTimelineKeyFacialFaceData faceNext; // 0x8
public LiveTimelineKeyFacialMouthData mouth; // 0x10
public LiveTimelineKeyFacialMouthData mouthCur; // 0x10
public LiveTimelineKeyFacialMouthData mouthNext; // 0x10
public LiveTimelineKeyFacialEyeData eyeCur; // 0x18
public LiveTimelineKeyFacialEyeData eyeNext; // 0x20
public LiveTimelineKeyFacialEyebrowData eyebrowCur; // 0x28
@@ -27,7 +27,7 @@ namespace Gallop.Live.Cutt
public event Action<LiveTimelineKeyLipSyncData, float> OnUpdateLipSync;
public event Action<FacialDataUpdateInfo, float> OnUpdateFacial;
public event Action<FacialDataUpdateInfo, float, int> OnUpdateFacial;
public void CopyValues<T>(T from, T to)
{
@@ -55,7 +55,7 @@ namespace Gallop.Live.Cutt
//}
}
public void InitCharaMotionSequence()
public void InitCharaMotionSequence(int[] motionSequence)
{
//Create Animation
foreach (var obj in Director.instance.charaObjs)
@@ -77,16 +77,17 @@ namespace Gallop.Live.Cutt
{
_keyArray[i] = data.worksheetList[0].charaMotSeqList[i].keys;
}
//Set Motion
int CharaPositionMax = characterStandPosLocators.Length;
int CharaPositionMax = Director.instance.allowCount;
_motionSequenceArray = new LiveTimelineMotionSequence[CharaPositionMax];
for (int i = 0; i < CharaPositionMax; i++)
{
_motionSequenceArray[i] = new LiveTimelineMotionSequence();
_motionSequenceArray[i].Initialize(Director.instance.charaObjs[i], i, i, this);
_motionSequenceArray[i].Initialize(Director.instance.charaObjs[i], i, motionSequence[i], this);
}
}
@@ -94,8 +95,8 @@ namespace Gallop.Live.Cutt
public void AlterUpdate(float liveTime)
{
AlterUpdate_CharaMotionSequence(liveTime);
AlterUpdate_LipSync(liveTime);
AlterUpdate_FacialData(liveTime);
AlterUpdate_LipSync(liveTime);
}
public void AlterUpdate_CharaMotionSequence(float liveTime)
@@ -112,10 +113,37 @@ namespace Gallop.Live.Cutt
FacialDataUpdateInfo updateInfo = default(FacialDataUpdateInfo);
if (facialDataList != null)
{
SetupFacialUpdateInfo_Mouth(ref updateInfo, facialDataList.mouthKeys, liveTime);
SetupFacialUpdateInfo_Eye(ref updateInfo, facialDataList.eyeKeys, liveTime);
SetupFacialUpdateInfo_Eyebrow(ref updateInfo, facialDataList.eyebrowKeys, liveTime);
SetupFacialUpdateInfo_Ear(ref updateInfo, facialDataList.earKeys, liveTime);
this.OnUpdateFacial(updateInfo, liveTime);
this.OnUpdateFacial(updateInfo, liveTime, 0);
}
var otherFacialDataList = data.worksheetList[0].other4FacialArray;
for(int i = 0; i < otherFacialDataList.Length && i < Director.instance.characterCount - 1; i++)
{
SetupFacialUpdateInfo_Mouth(ref updateInfo, otherFacialDataList[i].mouthKeys, liveTime);
SetupFacialUpdateInfo_Eye(ref updateInfo, otherFacialDataList[i].eyeKeys, liveTime);
SetupFacialUpdateInfo_Eyebrow(ref updateInfo, otherFacialDataList[i].eyebrowKeys, liveTime);
SetupFacialUpdateInfo_Ear(ref updateInfo, otherFacialDataList[i].earKeys, liveTime);
this.OnUpdateFacial(updateInfo, liveTime, i+1);
}
}
private void SetupFacialUpdateInfo_Mouth(ref FacialDataUpdateInfo updateInfo, LiveTimelineKeyFacialMouthDataList keys, float time)
{
LiveTimelineKey liveTimelineKey = null;
LiveTimelineKey liveTimelineKey2 = null;
LiveTimelineKeyIndex curKey = AlterUpdate_Key(keys, time);
if (curKey != null)
{
liveTimelineKey = curKey.key;
liveTimelineKey2 = curKey.nextKey;
updateInfo.mouthCur = liveTimelineKey as LiveTimelineKeyFacialMouthData;
updateInfo.mouthNext = liveTimelineKey2 as LiveTimelineKeyFacialMouthData;
updateInfo.mouthKeyIndex = curKey.index;
}
}
@@ -125,11 +153,14 @@ namespace Gallop.Live.Cutt
LiveTimelineKey liveTimelineKey2 = null;
LiveTimelineKeyIndex curKey = AlterUpdate_Key(keys, time);
liveTimelineKey = curKey.key;
liveTimelineKey2 = curKey.nextKey;
updateInfo.eyeCur = liveTimelineKey as LiveTimelineKeyFacialEyeData;
updateInfo.eyeNext = liveTimelineKey2 as LiveTimelineKeyFacialEyeData;
updateInfo.eyeKeyIndex = curKey.index;
if (curKey != null)
{
liveTimelineKey = curKey.key;
liveTimelineKey2 = curKey.nextKey;
updateInfo.eyeCur = liveTimelineKey as LiveTimelineKeyFacialEyeData;
updateInfo.eyeNext = liveTimelineKey2 as LiveTimelineKeyFacialEyeData;
updateInfo.eyeKeyIndex = curKey.index;
}
}
private void SetupFacialUpdateInfo_Eyebrow(ref FacialDataUpdateInfo updateInfo, LiveTimelineKeyFacialEyebrowDataList keys, float time)
@@ -138,11 +169,14 @@ namespace Gallop.Live.Cutt
LiveTimelineKey liveTimelineKey2 = null;
LiveTimelineKeyIndex curKey = AlterUpdate_Key(keys, time);
liveTimelineKey = curKey.key;
liveTimelineKey2 = curKey.nextKey;
updateInfo.eyebrowCur = liveTimelineKey as LiveTimelineKeyFacialEyebrowData;
updateInfo.eyebrowNext = liveTimelineKey2 as LiveTimelineKeyFacialEyebrowData;
updateInfo.eyebrowKeyIndex = curKey.index;
if (curKey != null)
{
liveTimelineKey = curKey.key;
liveTimelineKey2 = curKey.nextKey;
updateInfo.eyebrowCur = liveTimelineKey as LiveTimelineKeyFacialEyebrowData;
updateInfo.eyebrowNext = liveTimelineKey2 as LiveTimelineKeyFacialEyebrowData;
updateInfo.eyebrowKeyIndex = curKey.index;
}
}
private void SetupFacialUpdateInfo_Ear(ref FacialDataUpdateInfo updateInfo, LiveTimelineKeyFacialEarDataList keys, float time)
@@ -151,11 +185,14 @@ namespace Gallop.Live.Cutt
LiveTimelineKey liveTimelineKey2 = null;
LiveTimelineKeyIndex curKey = AlterUpdate_Key(keys, time);
liveTimelineKey = curKey.key;
liveTimelineKey2 = curKey.nextKey;
updateInfo.earCur = liveTimelineKey as LiveTimelineKeyFacialEarData;
updateInfo.earNext = liveTimelineKey2 as LiveTimelineKeyFacialEarData;
updateInfo.earKeyIndex = curKey.index;
if (curKey != null)
{
liveTimelineKey = curKey.key;
liveTimelineKey2 = curKey.nextKey;
updateInfo.earCur = liveTimelineKey as LiveTimelineKeyFacialEarData;
updateInfo.earNext = liveTimelineKey2 as LiveTimelineKeyFacialEarData;
updateInfo.earKeyIndex = curKey.index;
}
}
public void AlterUpdate_LipSync(float liveTime)
@@ -164,7 +201,7 @@ namespace Gallop.Live.Cutt
LiveTimelineKeyIndex curKey = AlterUpdate_Key(lipDataList, liveTime);
if (curKey != null && curKey.index != -1)
if (curKey != null && curKey.index != -1 && curKey.nextKey != null)
{
LiveTimelineKeyLipSyncData arg = curKey.key as LiveTimelineKeyLipSyncData;
this.OnUpdateLipSync(arg, liveTime);
@@ -339,6 +339,9 @@ namespace Gallop.Live
public bool _syncTime = false;
public bool _soloMode = false;
public int characterCount = 0;
public int allowCount = 0;
private void Awake()
{
if (live != null)
@@ -376,9 +379,11 @@ namespace Gallop.Live
}
}
public void InitializeTimeline()
public void InitializeTimeline(int count)
{
_liveTimelineControl.InitCharaMotionSequence();
allowCount = count;
_liveTimelineControl.InitCharaMotionSequence(_liveTimelineControl.data.characterSettings.motionSequenceIndices);
_liveTimelineControl.OnUpdateLipSync += delegate (LiveTimelineKeyLipSyncData keyData_, float liveTime_)
{
@@ -391,10 +396,13 @@ namespace Gallop.Live
}
}
};
_liveTimelineControl.OnUpdateFacial += delegate (FacialDataUpdateInfo updateInfo_, float liveTime_)
_liveTimelineControl.OnUpdateFacial += delegate (FacialDataUpdateInfo updateInfo_, float liveTime_, int position)
{
var container = charaObjs[0].GetComponentInChildren<UmaContainer>();
container.FaceDrivenKeyTarget.AlterUpdateFacialNew(ref updateInfo_, liveTime_);
if( position < charaObjs.Count)
{
var container = charaObjs[position].GetComponentInChildren<UmaContainer>();
container.FaceDrivenKeyTarget.AlterUpdateFacialNew(ref updateInfo_, liveTime_);
}
};
}
@@ -402,15 +410,14 @@ namespace Gallop.Live
{
Debug.Log(songid);
var charaCount = 0;
for (int i = 0; i < characters.Count; i++)
{
if (characters[i].CharaEntry.Name != "")
{
charaCount += 1;
characterCount += 1;
}
}
if(charaCount == 1)
if(characterCount == 1)
{
_soloMode = true;
}