-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Zhwa #27
Conversation
add craft manager, which used to control craft in whole game
add scriptable object of item and drops add scriptable object of recipe add scriptable object of recipe book
control item in whole game
add time manager to control time in the whole game add event manager, which can used to register, subscribe event
PlayerMove add boolean status to decide whether player move is effected by time add function to control the status, which trigger by event FlyingSickle time slowdown is now controled by event add boolean value to decide whether to show mouse in game
change encode from big5 to utf8 which can show chinese on github
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
掉落物和道具上層沒問題,但下層觸發的方式可以改用更方便的插件
playerRigibody.velocity = moveDirection.normalized * maxSpeed; | ||
//playerRigibody.velocity = moveDirection.normalized * maxSpeed; | ||
|
||
// 計算移動方向 | ||
Vector3 moveDir = (playerRigibody.transform.forward * inputVector.y + playerRigibody.transform.right * inputVector.x).normalized; | ||
Vector3 moveDistance = moveDir * maxSpeed; | ||
|
||
// 根據 Time.timeScale 是否縮放,選擇合適的時間間隔 | ||
float deltaTime = isScaledByTime ? Time.deltaTime : Time.unscaledDeltaTime; | ||
|
||
// 這樣可以手動更新位置,避免受 Time.timeScale 影響 | ||
playerRigibody.MovePosition(playerRigibody.position + moveDistance * deltaTime); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
可能會導致移動效果不怪異,待討論
private void OnEnable() | ||
{ | ||
// 註冊對 事件的訂閱 | ||
EventManager.StartListening<bool>(NameOfEvent.ChangeMoveMode, ChangeMoveMode); | ||
} | ||
|
||
private void OnDisable() | ||
{ | ||
// 取消註冊對 事件的訂閱 | ||
EventManager.StopListening<bool>(NameOfEvent.ChangeMoveMode, ChangeMoveMode); | ||
} | ||
|
||
private void ChangeMoveMode(bool _isScaledByTime) | ||
{ | ||
Debug.Log($"PlayMove: Move mode is changed (is scaled by time: {_isScaledByTime})"); | ||
isScaledByTime = _isScaledByTime; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
事件觸發方式重構後要回來改
EventManager.TriggerEvent<float>(NameOfEvent.TimeControl, slowdownFactor); | ||
EventManager.TriggerEvent<bool>(NameOfEvent.ChangeMoveMode, false); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
若已經打算使用UniRx插件,那訂閱事件也建議改成使用較方便的UniRx設置
EventManager.TriggerEvent(NameOfEvent.TimeResume); | ||
EventManager.TriggerEvent<bool>(NameOfEvent.ChangeMoveMode, true); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
重構事件觸發方式後要記得回來改
// 註冊事件,這裡支持泛型 | ||
public static void StartListening(NameOfEvent eventName, Action listener) | ||
{ | ||
if (eventDictionary.ContainsKey(eventName)) | ||
{ | ||
eventDictionary[eventName] = Delegate.Combine(eventDictionary[eventName], listener); | ||
} | ||
else | ||
{ | ||
eventDictionary.Add(eventName, listener); | ||
} | ||
} | ||
// 取消註冊事件 | ||
public static void StopListening(NameOfEvent eventName, Action listener) | ||
{ | ||
if (eventDictionary.ContainsKey(eventName)) | ||
{ | ||
eventDictionary[eventName] = Delegate.Remove(eventDictionary[eventName], listener); | ||
} | ||
} | ||
|
||
// 觸發事件,這裡支持傳遞不同類型的參數 | ||
public static void TriggerEvent(NameOfEvent eventName) | ||
{ | ||
if (eventDictionary.ContainsKey(eventName)) | ||
{ | ||
Action action = eventDictionary[eventName] as Action; | ||
action?.Invoke(); | ||
} | ||
} | ||
#endregion | ||
|
||
#region 帶一個參數 | ||
// 註冊事件,這裡支持泛型 | ||
public static void StartListening<T>(NameOfEvent eventName, Action<T> listener) | ||
{ | ||
if (eventDictionary.ContainsKey(eventName)) | ||
{ | ||
eventDictionary[eventName] = Delegate.Combine(eventDictionary[eventName], listener); | ||
} | ||
else | ||
{ | ||
eventDictionary.Add(eventName, listener); | ||
} | ||
} | ||
// 取消註冊事件 | ||
public static void StopListening<T>(NameOfEvent eventName, Action<T> listener) | ||
{ | ||
if (eventDictionary.ContainsKey(eventName)) | ||
{ | ||
eventDictionary[eventName] = Delegate.Remove(eventDictionary[eventName], listener); | ||
} | ||
} | ||
|
||
// 觸發事件,這裡支持傳遞不同類型的參數 | ||
public static void TriggerEvent<T>(NameOfEvent eventName, T parameter) | ||
{ | ||
if (eventDictionary.ContainsKey(eventName)) | ||
{ | ||
Action<T> action = eventDictionary[eventName] as Action<T>; | ||
action?.Invoke(parameter); | ||
} | ||
} | ||
#endregion | ||
|
||
#region 帶兩個參數 | ||
// 重載,支持多個參數的情況 | ||
// 註冊事件,這裡支持泛型 | ||
public static void StartListening<T1, T2>(NameOfEvent eventName, Action<T1, T2> listener) | ||
{ | ||
if (eventDictionary.ContainsKey(eventName)) | ||
{ | ||
eventDictionary[eventName] = Delegate.Combine(eventDictionary[eventName], listener); | ||
} | ||
else | ||
{ | ||
eventDictionary.Add(eventName, listener); | ||
} | ||
} | ||
// 取消註冊事件 | ||
public static void StopListening<T1, T2>(NameOfEvent eventName, Action<T1, T2> listener) | ||
{ | ||
if (eventDictionary.ContainsKey(eventName)) | ||
{ | ||
eventDictionary[eventName] = Delegate.Remove(eventDictionary[eventName], listener); | ||
} | ||
} | ||
|
||
// 觸發事件,這裡支持傳遞不同類型的參數 | ||
public static void TriggerEvent<T1, T2>(NameOfEvent eventName, T1 p1, T2 p2) | ||
{ | ||
if (eventDictionary.ContainsKey(eventName)) | ||
{ | ||
Action<T1, T2> action = eventDictionary[eventName] as Action<T1, T2>; | ||
action?.Invoke(p1, p2); | ||
} | ||
} | ||
#endregion | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
需要被重構,使用UniRx可以簡化很多東西,這邊的多型我看到快裂開ㄌ
private void OnEnable() | ||
{ | ||
// 註冊對 事件的訂閱 | ||
EventManager.StartListening<float>(NameOfEvent.TimeControl, TimeControl); | ||
EventManager.StartListening(NameOfEvent.TimeResume, TimeResume); | ||
} | ||
|
||
private void OnDisable() | ||
{ | ||
// 取消註冊對 事件的訂閱 | ||
EventManager.StopListening<float>(NameOfEvent.TimeControl, TimeControl); | ||
EventManager.StopListening(NameOfEvent.TimeResume, TimeResume); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
事件重構後要回來改
這裡是因為如果不改成用MovePosition 比如說使用減速器後玩家的移動速度在理想設計中應該保持一致 |
RecipeBook Change encode from big5 to utf 8
change Event manager design from C# event(delegate) to UniRx reduce unsibscribe frunction in EventManager but increase complexity of subscribe person
EventManager 詳細說明該東西的使用流程 以及參考範例 需要更多多型支援 請issue zhwa
isScaledByTime 將該狀態的狀態改變函數 更改為UniRx的訂閱方式 player move 保留move position的移動方式 但是添加了手動摩擦力計算 現在的移動跟以前一樣舒適(不 應該說更強大
重構了事件系統 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
剩變數重複問題~
Vector3 moveDir = (playerRigibody.transform.forward * inputVector.y + playerRigibody.transform.right * inputVector.x).normalized; | ||
|
||
// 根據輸入更新目標速度 | ||
Vector3 targetVelocity = moveDir * maxSpeed; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
簡化參數,上方有moveDirection,也可以這邊自己設moveDir,留一個就好
Move direction var. is duplicate fix this problem
為修改以及新增的腳本添加註解
整理commit