Skip to content
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

Merged
merged 12 commits into from
Dec 25, 2024
Merged

Zhwa #27

merged 12 commits into from
Dec 25, 2024

Conversation

z-hwa
Copy link
Collaborator

@z-hwa z-hwa commented Dec 17, 2024

為修改以及新增的腳本添加註解
整理commit

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
@z-hwa z-hwa changed the base branch from main to develop December 17, 2024 11:19
change encode from big5 to utf8
which can show chinese on github
@Aka2210 Aka2210 self-requested a review December 19, 2024 03:32
Aka2210

This comment was marked as duplicate.

Aka2210

This comment was marked as duplicate.

Copy link
Collaborator

@Aka2210 Aka2210 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

掉落物和道具上層沒問題,但下層觸發的方式可以改用更方便的插件

Comment on lines 61 to 71
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);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

可能會導致移動效果不怪異,待討論

Comment on lines 94 to 150
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;

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

事件觸發方式重構後要回來改

Comment on lines +20 to +21
EventManager.TriggerEvent<float>(NameOfEvent.TimeControl, slowdownFactor);
EventManager.TriggerEvent<bool>(NameOfEvent.ChangeMoveMode, false);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

若已經打算使用UniRx插件,那訂閱事件也建議改成使用較方便的UniRx設置

Comment on lines +37 to +38
EventManager.TriggerEvent(NameOfEvent.TimeResume);
EventManager.TriggerEvent<bool>(NameOfEvent.ChangeMoveMode, true);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

重構事件觸發方式後要記得回來改

Comment on lines 1 to 137
// 註冊事件,這裡支持泛型
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

}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

需要被重構,使用UniRx可以簡化很多東西,這邊的多型我看到快裂開ㄌ

Comment on lines 43 to 63
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);
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

事件重構後要回來改

@z-hwa
Copy link
Collaborator Author

z-hwa commented Dec 19, 2024

Player Move方式的改變尚有疑慮,playerRigibody.MovePosition可能導致移動效果不佳,待討論、測試

這裡是因為如果不改成用MovePosition
用原本的運動方式 更換time.deltatime以及time.unscaledDeltaTime的話
在時間流速等於1的情況下 移動速度會不同

比如說使用減速器後玩家的移動速度在理想設計中應該保持一致
但如果使用原本的移動方式 會變慢一些
不知道甚麼原因

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的移動方式
	但是添加了手動摩擦力計算 現在的移動跟以前一樣舒適(不
	應該說更強大
@z-hwa
Copy link
Collaborator Author

z-hwa commented Dec 19, 2024

重構了事件系統
為玩家移動添加摩擦力
把一些中文亂碼的地方改回正確的中文

Copy link
Collaborator

@Aka2210 Aka2210 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

剩變數重複問題~

Comment on lines +78 to +81
Vector3 moveDir = (playerRigibody.transform.forward * inputVector.y + playerRigibody.transform.right * inputVector.x).normalized;

// 根據輸入更新目標速度
Vector3 targetVelocity = moveDir * maxSpeed;
Copy link
Collaborator

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
@Aka2210 Aka2210 merged commit 1d67c46 into develop Dec 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants