拖动视角,可交互对象和任务添加

This commit is contained in:
huyulong 2024-12-19 15:04:19 +08:00
parent 910f3f28a6
commit a9b7d0022d
5 changed files with 162 additions and 88 deletions

View File

@ -30,29 +30,29 @@ public static partial class JoinReflection {
"ZXNwb25zZRgLIAEoCzIRLlRhc2tJbmZvUmVzcG9uc2USKwoOb2JqZWN0UmVz",
"cG9uc2UYDCABKAsyEy5PYmplY3RJbmZvUmVzcG9uc2UiNwoQUm9vbVVzZXJS",
"ZXNwb25zZRIjCgh1c2VyTGlzdBgBIAMoCzIRLlVzZXJKb2luUmVzcG9uc2Ui",
"ogIKEFRhc2tJbmZvUmVzcG9uc2USDgoGVGFza0lkGAEgASgJEg4KBlN0YXR1",
"tgIKEFRhc2tJbmZvUmVzcG9uc2USDgoGVGFza0lkGAEgASgJEg4KBlN0YXR1",
"cxgCIAEoCRIOCgZSb29tSWQYAyABKAkSCQoBWBgEIAEoAhIJCgFZGAUgASgC",
"EgkKAVoYBiABKAISDAoEVHlwZRgHIAEoCRIRCglUaW1lTGltaXQYCCABKAMS",
"DAoERGVzYxgJIAEoCRIPCgdUcmlnZ2VyGAogASgJEhEKCU5leHRUYXNrcxgL",
"IAEoCRISCgpUYXJnZXRUeXBlGAwgASgJEg4KBlJld2FyZBgNIAEoCRIMCgRO",
"b3RlGA4gASgJEhIKCkNyZWF0ZVRpbWUYDyABKAkSEgoKVXBkYXRlVGltZRgQ",
"IAEoCRIQCghUb1VzZXJJZBgRIAEoCSKvAwoST2JqZWN0SW5mb1Jlc3BvbnNl",
"Eg4KBlJvb21JZBgBIAEoCRIKCgJJZBgCIAEoCRIQCghPYmplY3RJZBgDIAEo",
"CRIMCgROb3RlGAQgASgJEgwKBFR5cGUYBSABKAkSDAoETmFtZRgGIAEoCRIW",
"Cg5OYW1lU2hvd09mZnNldBgHIAEoAxISCgpTaG93UmFkaXVzGAggASgDEgwK",
"BEljb24YCSABKAkSDAoEUm9sZRgKIAEoCRISCgpJdGVtRGVwZW5kGAsgASgJ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Code(descriptorData,
new pbr::FileDescriptor[] { },
new pbr::GeneratedClrTypeInfo(null, null, new pbr::GeneratedClrTypeInfo[] {
new pbr::GeneratedClrTypeInfo(typeof(global::UserJoinResponse), global::UserJoinResponse.Parser, new[]{ "UserId", "NickName", "RoleName", "RoomId", "Online", "MessageType", "Cmd", "IncidentPosition", "FireRadius", "FireValue", "TaskResponse", "ObjectResponse" }, null, null, null, null),
new pbr::GeneratedClrTypeInfo(typeof(global::RoomUserResponse), global::RoomUserResponse.Parser, new[]{ "UserList" }, null, null, null, null),
new pbr::GeneratedClrTypeInfo(typeof(global::TaskInfoResponse), global::TaskInfoResponse.Parser, new[]{ "TaskId", "Status", "RoomId", "X", "Y", "Z", "Type", "TimeLimit", "Desc", "Trigger", "NextTasks", "TargetType", "Reward", "Note", "CreateTime", "UpdateTime", "ToUserId" }, null, null, null, null),
new pbr::GeneratedClrTypeInfo(typeof(global::TaskInfoResponse), global::TaskInfoResponse.Parser, new[]{ "TaskId", "Status", "RoomId", "X", "Y", "Z", "Type", "TimeLimit", "Desc", "Trigger", "NextTasks", "TargetType", "Reward", "Note", "CreateTime", "UpdateTime", "ToUserId", "BaseTaskId" }, null, null, null, null),
new pbr::GeneratedClrTypeInfo(typeof(global::ObjectInfoResponse), global::ObjectInfoResponse.Parser, new[]{ "RoomId", "Id", "ObjectId", "Note", "Type", "Name", "NameShowOffset", "ShowRadius", "Icon", "Role", "ItemDepend", "TakeTime", "NeedPlayers", "TaskStatus", "SelectList", "OnOff", "Status", "ResChange", "ParallelControl", "ExtraValue", "UserIds", "CreateTime", "UpdateTime" }, null, null, null, null)
}));
}
@ -961,6 +961,7 @@ public sealed partial class TaskInfoResponse : pb::IMessage<TaskInfoResponse>
createTime_ = other.createTime_;
updateTime_ = other.updateTime_;
toUserId_ = other.toUserId_;
baseTaskId_ = other.baseTaskId_;
_unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
}
@ -1225,6 +1226,21 @@ public sealed partial class TaskInfoResponse : pb::IMessage<TaskInfoResponse>
}
}
/// <summary>Field number for the "BaseTaskId" field.</summary>
public const int BaseTaskIdFieldNumber = 18;
private string baseTaskId_ = "";
/// <summary>
/// 基础任务id
/// </summary>
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public string BaseTaskId {
get { return baseTaskId_; }
set {
baseTaskId_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
}
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public override bool Equals(object other) {
@ -1257,6 +1273,7 @@ public sealed partial class TaskInfoResponse : pb::IMessage<TaskInfoResponse>
if (CreateTime != other.CreateTime) return false;
if (UpdateTime != other.UpdateTime) return false;
if (ToUserId != other.ToUserId) return false;
if (BaseTaskId != other.BaseTaskId) return false;
return Equals(_unknownFields, other._unknownFields);
}
@ -1281,6 +1298,7 @@ public sealed partial class TaskInfoResponse : pb::IMessage<TaskInfoResponse>
if (CreateTime.Length != 0) hash ^= CreateTime.GetHashCode();
if (UpdateTime.Length != 0) hash ^= UpdateTime.GetHashCode();
if (ToUserId.Length != 0) hash ^= ToUserId.GetHashCode();
if (BaseTaskId.Length != 0) hash ^= BaseTaskId.GetHashCode();
if (_unknownFields != null) {
hash ^= _unknownFields.GetHashCode();
}
@ -1367,6 +1385,10 @@ public sealed partial class TaskInfoResponse : pb::IMessage<TaskInfoResponse>
output.WriteRawTag(138, 1);
output.WriteString(ToUserId);
}
if (BaseTaskId.Length != 0) {
output.WriteRawTag(146, 1);
output.WriteString(BaseTaskId);
}
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
@ -1445,6 +1467,10 @@ public sealed partial class TaskInfoResponse : pb::IMessage<TaskInfoResponse>
output.WriteRawTag(138, 1);
output.WriteString(ToUserId);
}
if (BaseTaskId.Length != 0) {
output.WriteRawTag(146, 1);
output.WriteString(BaseTaskId);
}
if (_unknownFields != null) {
_unknownFields.WriteTo(ref output);
}
@ -1506,6 +1532,9 @@ public sealed partial class TaskInfoResponse : pb::IMessage<TaskInfoResponse>
if (ToUserId.Length != 0) {
size += 2 + pb::CodedOutputStream.ComputeStringSize(ToUserId);
}
if (BaseTaskId.Length != 0) {
size += 2 + pb::CodedOutputStream.ComputeStringSize(BaseTaskId);
}
if (_unknownFields != null) {
size += _unknownFields.CalculateSize();
}
@ -1569,6 +1598,9 @@ public sealed partial class TaskInfoResponse : pb::IMessage<TaskInfoResponse>
if (other.ToUserId.Length != 0) {
ToUserId = other.ToUserId;
}
if (other.BaseTaskId.Length != 0) {
BaseTaskId = other.BaseTaskId;
}
_unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields);
}
@ -1656,6 +1688,10 @@ public sealed partial class TaskInfoResponse : pb::IMessage<TaskInfoResponse>
ToUserId = input.ReadString();
break;
}
case 146: {
BaseTaskId = input.ReadString();
break;
}
}
}
#endif
@ -1743,6 +1779,10 @@ public sealed partial class TaskInfoResponse : pb::IMessage<TaskInfoResponse>
ToUserId = input.ReadString();
break;
}
case 146: {
BaseTaskId = input.ReadString();
break;
}
}
}
}

View File

@ -510,7 +510,7 @@ public class test : MonoBehaviour
TaskInfoResponse taskInfoResponse = userJoinResponse.TaskResponse;
if (long.Parse(taskInfoResponse.ToUserId) == userJoinResponse.UserId)//当这个任务是当前玩家的任务时显示任务
{
//TaskPanel.instance.SetInfo(int.Parse(taskInfoResponse.TaskId));
TaskPanel.instance.Taskad(int.Parse(taskInfoResponse.TaskId));
}
}

View File

@ -30,21 +30,30 @@ public class TaskPanel : Base
{
instance = this;
hideBtn.onClick.AddListener(OnClickHideButton);
InitList();
//InitList();
//InitTask(taskIDs);
}
//public void InitList()
//{
// foreach (Task_ task in JSONReader.TaskDictionary.Values)
// {
// if (int.TryParse(task.ID, out int taskId))
// {
// // 转换成功,添加到 taskIDs 列表
// taskIDs.Add(taskId);
// }
// }
//}
//添加任务
public void Taskad(int id)
{
taskIDs.Add(id);
InitTask(taskIDs);
}
public void InitList()
{
foreach (Task_ task in JSONReader.TaskDictionary.Values)
{
if (int.TryParse(task.ID, out int taskId))
{
// 转换成功,添加到 taskIDs 列表
taskIDs.Add(taskId);
}
}
}
// 将任务栏收起或显示
public void OnClickHideButton()
{
@ -72,13 +81,14 @@ public class TaskPanel : Base
}
}
// 添加新任务
// 将每条任务实例化
public void AddTask(int taskId)
{
GameObject go = Instantiate(taskPrefab, contentTrans);
TaskItem taskItem = go.GetComponent<TaskItem>();
taskItem.SetInfo(taskId, JSONReader);
taskItems.Add(taskItem);
}
// 更新任务UI

View File

@ -29044,52 +29044,6 @@ Transform:
m_Father: {fileID: 0}
m_RootOrder: 24
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &1909673636
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1909673638}
- component: {fileID: 1909673637}
m_Layer: 0
m_Name: BurstCollisionWorld
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!114 &1909673637
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1909673636}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: f1a161c4294214a4fbcb7e9e94800494, type: 3}
m_Name:
m_EditorClassIdentifier:
cellSpans:
m_AlignBytes: 16
--- !u!4 &1909673638
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1909673636}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 38
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1001 &1912789160
PrefabInstance:
m_ObjectHideFlags: 0
@ -29909,6 +29863,52 @@ MeshCollider:
m_Convex: 0
m_CookingOptions: 30
m_Mesh: {fileID: 3628990442929905983, guid: 00003e04dc9a2534eb207f108c7b0cd3, type: 3}
--- !u!1 &2006179374
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 2006179376}
- component: {fileID: 2006179375}
m_Layer: 0
m_Name: BurstCollisionWorld
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!114 &2006179375
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2006179374}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: f1a161c4294214a4fbcb7e9e94800494, type: 3}
m_Name:
m_EditorClassIdentifier:
cellSpans:
m_AlignBytes: 16
--- !u!4 &2006179376
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2006179374}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 38
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &2007442320
GameObject:
m_ObjectHideFlags: 0
@ -43967,10 +43967,15 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 4e3938570b1787843b6fe76c1c2b9651, type: 3}
m_Name:
m_EditorClassIdentifier:
joystickBackground: {fileID: 8163955216411254552}
isDrag: 0
joystickBackground: {fileID: 8163955216392696351}
joystick: {fileID: 8163955215854446702}
playerCamera: {fileID: 1068997306}
rotationSpeed: 10
rotationSpeed: 0.5
horizontalMinRotation: -75
horizontalMaxRotation: 75
verticalMinRotation: -75
verticalMaxRotation: 75
--- !u!224 &8163955216411254552
RectTransform:
m_ObjectHideFlags: 0

View File

@ -9,14 +9,30 @@ public class JoystickController : MonoBehaviour, IDragHandler, IEndDragHandler
public RectTransform joystickBackground; // 摇杆背景
public RectTransform joystick; // 摇杆
public Camera playerCamera; // 摄像机
public float rotationSpeed = 5f; // 摄像机旋转速度
public float rotationSpeed = 0.5f; // 摄像机旋转速度
// 旋转角度限制
public float horizontalMinRotation = -75f; // 水平旋转最小值
public float horizontalMaxRotation = 75f; // 水平旋转最大值
public float verticalMinRotation = -75f; // 垂直旋转最小值
public float verticalMaxRotation = 75f; // 垂直旋转最大值
private Vector2 joystickInput = Vector2.zero;
private float currentXRotation = 0f; // 当前的水平旋转角度
private float currentYRotation = 0f; // 当前的垂直旋转角度
private float targetXRotation = 0f; // 目标水平旋转角度
private float targetYRotation = 0f; // 目标垂直旋转角度
void Start()
{
// 初始化摇杆的位置
joystick.anchoredPosition = Vector2.zero;
// 初始化摄像机的旋转角度
targetXRotation = playerCamera.transform.eulerAngles.y;
targetYRotation = playerCamera.transform.eulerAngles.x;
}
// 每帧更新摇杆的输入
@ -25,28 +41,28 @@ public class JoystickController : MonoBehaviour, IDragHandler, IEndDragHandler
if (joystickInput.magnitude > 0)
{
// 根据摇杆的输入控制摄像机旋转
float horizontal = joystickInput.x;
float vertical = joystickInput.y;
targetXRotation += joystickInput.x * rotationSpeed * Time.deltaTime;
targetYRotation -= joystickInput.y * rotationSpeed * Time.deltaTime;
// 水平旋转
playerCamera.transform.Rotate(Vector3.up, horizontal * rotationSpeed * Time.deltaTime);
// 限制水平旋转范围,防止摄像机旋转过头
targetXRotation = Mathf.Clamp(targetXRotation, horizontalMinRotation, horizontalMaxRotation);
// 垂直旋转
playerCamera.transform.Rotate(Vector3.left, vertical * rotationSpeed * Time.deltaTime);
// 限制垂直旋转范围,防止摄像机翻转
targetYRotation = Mathf.Clamp(targetYRotation, verticalMinRotation, verticalMaxRotation);
// 使用 Quaternion 来平滑过渡到目标旋转角度
playerCamera.transform.localRotation = Quaternion.Euler(targetYRotation, targetXRotation, 0f);
}
}
// 摇杆拖动时更新摇杆位置和输入
public void OnDrag(PointerEventData eventData)
{
isDrag = true;
// 更新摇杆的位置
joystick.anchoredPosition = joystickInput;
Vector2 localPoint;
// 将触摸位置从屏幕坐标转换为UI本地坐标
RectTransformUtility.ScreenPointToLocalPointInRectangle(joystickBackground, eventData.position, eventData.pressEventCamera, out localPoint);
// 计算摇杆的输入方向
joystickInput = localPoint.normalized;
@ -56,13 +72,16 @@ public class JoystickController : MonoBehaviour, IDragHandler, IEndDragHandler
joystickInput = localPoint.normalized * (joystickBackground.sizeDelta.x / 2);
}
// 更新摇杆的位置
joystick.anchoredPosition = joystickInput;
}
// 摇杆松开时重置摇杆位置
public void OnEndDrag(PointerEventData eventData)
{
isDrag = false;
// 摇杆松开后重置位置
joystick.anchoredPosition = Vector2.zero;
joystickInput = Vector2.zero;
}