fix:调整水晶随机位置逻辑,改成雕像组内相互位置和旋转随机

This commit is contained in:
bzx
2026-03-25 11:58:57 +08:00
parent 6ff170894f
commit 53c5775e11
3 changed files with 37 additions and 14 deletions

View File

@@ -82312,7 +82312,7 @@ GameObject:
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
m_IsActive: 0
--- !u!4 &496282144
Transform:
m_ObjectHideFlags: 0
@@ -296319,7 +296319,7 @@ GameObject:
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 0
m_IsActive: 1
--- !u!4 &1597025902
Transform:
m_ObjectHideFlags: 0

View File

@@ -114,7 +114,7 @@ public class GameManager : MonoBehaviour
yield return new WaitForSeconds(1f);
// 开始第一个过场
StartCutscene(0);
StartCutscene(0);
}
public void StartCutscene(int id)

View File

@@ -311,28 +311,51 @@ public class CrystalStatueGroup : MonoBehaviour
#region
/// <summary>
/// 应用随机Y轴旋转
/// 将360度分成rotationDivisions份随机选择一个角度
/// 应用随机位置和旋转
/// 存储所有雕像的位置和旋转,相互赋值随机位置,确保每个位置都有雕像
/// </summary>
private void ApplyRandomRotation()
{
if (!enableRandomRotation)
return;
// 计算每份的角度
float anglePerDivision = 360f / rotationDivisions;
int statueCount = statues.Length;
if (statueCount == 0)
return;
// 随机选择一个份数0到rotationDivisions-1
int randomDivision = Random.Range(0, rotationDivisions);
// 1. 存储所有雕像的位置和旋转
Vector3[] positions = new Vector3[statueCount];
Quaternion[] rotations = new Quaternion[statueCount];
// 计算最终角度
float randomAngle = randomDivision * anglePerDivision;
for (int i = 0; i < statueCount; i++)
{
positions[i] = statues[i].transform.localPosition;
rotations[i] = statues[i].transform.localRotation;
}
// 应用Y轴旋转
transform.rotation = Quaternion.Euler(0f, randomAngle, 0f);
// 2. 创建索引数组并打乱Fisher-Yates洗牌算法
int[] indices = new int[statueCount];
for (int i = 0; i < statueCount; i++)
{
indices[i] = i;
}
for (int i = statueCount - 1; i > 0; i--)
{
int j = Random.Range(0, i + 1);
(indices[i], indices[j]) = (indices[j], indices[i]);
}
// 3. 相互赋值随机位置和旋转(每个位置都有雕像)
for (int i = 0; i < statueCount; i++)
{
int newIndex = indices[i];
statues[i].transform.localPosition = positions[newIndex];
statues[i].transform.localRotation = rotations[newIndex];
}
if (debugMode)
Debug.Log($"[CrystalStatueGroup] 随机旋转: {randomAngle}度 (第{randomDivision + 1}/{rotationDivisions}份)");
Debug.Log($"[CrystalStatueGroup] 已打乱 {statueCount} 个雕像的位置和旋转");
}
/// <summary>