一些小修改

This commit is contained in:
liuliang 2024-12-26 22:26:18 +08:00
parent 0ece047d64
commit 0416eb8c6b
11 changed files with 616 additions and 13316 deletions

View File

@ -160,7 +160,7 @@ MonoBehaviour:
m_FallbackScreenDPI: 96
m_DefaultSpriteDPI: 96
m_DynamicPixelsPerUnit: 1
m_PresetInfoIsWorld: 1
m_PresetInfoIsWorld: 0
--- !u!114 &4718796657024693748
MonoBehaviour:
m_ObjectHideFlags: 0

View File

@ -67,6 +67,7 @@ public class Drill : MonoBehaviour
// 演练计划按钮点击事件
void OnClickScheduleBtn()
{
SceneManager.LoadScene(2);
Debug.Log("点击了演练计划按钮!");
// 这里可以添加具体逻辑
}

View File

@ -40,14 +40,22 @@ public class Panel2 : MonoBehaviour
peopleposition = GameObject.Find("peopleposition").gameObject;
//获取所有子物体中的 Button 组件
nameImage = new List<GameObject>();
// 遍历 peopleposition 的子物体
foreach (Transform child in peopleposition.transform)
{
// 查找每个子物体中的"bg"子物体
Transform bgTransform = child.Find("nameImage");
if (bgTransform != null)
// 遍历子物体的子物体
foreach (Transform secondLevelChild in child)
{
nameImage.Add(bgTransform.gameObject);
// 遍历子物体的子物体的子物体
foreach (Transform thirdLevelChild in secondLevelChild)
{
// 获取 Image 组件
Image imageComponent = thirdLevelChild.GetComponent<Image>();
if (imageComponent != null)
{
nameImage.Add(imageComponent.gameObject); // 添加到列表
}
}
}
}
// 获取所有标签为 "Player" 的物体

View File

@ -32,25 +32,40 @@ public class ReadRoom : MonoBehaviour
//将当前日期格式化为 "yyyy/MM/dd" 形式
string formattedDate = currentDate.ToString("yyyy/MM/dd");
// 调用方法,动态生成房间元素
foreach (var room in roomDataList)
{
for (int i = 0; i < room.PlayerList.Count; i++)
if (room.Status == "进行中")
{
if ((GlobalData.ServerData.data.userId == room.PlayerList[i].UserId) && ("2024/12/20" == room.ReserveDate))
bool found = false; // 标记是否找到匹配的用户 ID
for (int i = 0; i < room.PlayerList.Count; i++)
{
Debug.Log("可以直接进入房间");
SceneManager.LoadScene("Tmap 1");
isenter = true;
if ((GlobalData.ServerData.data.userId == room.PlayerList[i].UserId) && ("2024/12/20" == room.ReserveDate))
{
Debug.Log("可以直接进入房间");
SceneManager.LoadScene("Tmap 1");
isenter = true;
found = true; // 找到匹配用户 ID
break; // 直接跳出循环
}
}
//else
//{
// Debug.Log("不可以直接进入房间");
// SceneManager.LoadScene(1);
//}
// 如果没有找到匹配的用户 ID跳转到 "yhj" 场景
if (!found)
{
Debug.Log("未找到匹配用户 ID跳转到场景 'yhj'");
SceneManager.LoadScene("yhj");
}
}
else
{
Debug.Log("状态不是 '进行中',跳转到场景 'yhj'");
SceneManager.LoadScene("yhj");
}
}
}
else

View File

@ -3,6 +3,8 @@ using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using static UnityEditor.Experimental.GraphView.GraphView;
using static UnityEngine.GraphicsBuffer;
public class UseObjects : MonoBehaviour
{
@ -62,6 +64,13 @@ public class UseObjects : MonoBehaviour
// 绑定点击事件
childButton.onClick.AddListener(() => OnChildClicked(child.gameObject));
}
// 获取所有标签为 "People" 的物体
GameObject[] playNPC = GameObject.FindGameObjectsWithTag("People");
// 遍历每个人,将其存入一个链表
foreach (GameObject player in playNPC)
{
potentialTargets.Add(player.gameObject);
}
UseCautionaryitems(player.transform.position, polePrefab);
}
private void Update()

View File

@ -0,0 +1,151 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class xiaozhigou : MonoBehaviour
{
public Camera mainCamera; // 玩家摄像机
public RectTransform uiCanvas; // UI Canvas 的 RectTransform
public GameObject targetIconPrefab; // UI 图标的预制体
private LinkedList<GameObject> playerList = new LinkedList<GameObject>(); // 存储标签为 "Player" 的对象
private GameObject peopleposition;//位置的信息
private Dictionary<GameObject, RectTransform> playerUIMap = new Dictionary<GameObject, RectTransform>(); // 存储角色与对应的 UI 标记
private void Start()
{
peopleposition = GameObject.Find("peopleposition");
if (peopleposition == null)
{
Debug.LogError("请确保场景中有一个名为 'peopleposition' 的 GameObject 作为 UI 的父物体。");
return;
}
// 初始化获取当前场景中所有的 "Player" 标签对象并创建 UI 标记
UpdatePlayerList();
CreateUIForPlayers();
}
void Update()
{
// 实时更新 Player 列表和对应的 UI
UpdatePlayerList();
UpdateUIForPlayers();
}
// 更新链表中的 "Player" 对象
private void UpdatePlayerList()
{
// 获取所有带有 "Player" 标签的对象
GameObject[] players = GameObject.FindGameObjectsWithTag("Player");
// 检查新增的 Player
foreach (GameObject player in players)
{
if (!playerList.Contains(player)) // 新增的角色
{
playerList.AddLast(player);
// 为新增角色创建 UI 标记
if (!playerUIMap.ContainsKey(player))
{
CreateUIForPlayer(player);
}
}
}
// 检查已移除的 Player
var node = playerList.First;
while (node != null)
{
var nextNode = node.Next;
if (!System.Array.Exists(players, p => p == node.Value))
{
// 如果角色已被移除,删除对应的 UI 标记
if (playerUIMap.ContainsKey(node.Value))
{
Destroy(playerUIMap[node.Value].gameObject);
playerUIMap.Remove(node.Value);
}
playerList.Remove(node);
}
node = nextNode;
}
}
// 为所有玩家创建 UI 标记
private void CreateUIForPlayers()
{
foreach (var player in playerList)
{
if (!playerUIMap.ContainsKey(player))
{
CreateUIForPlayer(player);
}
}
}
// 为单个玩家创建 UI 标记
private void CreateUIForPlayer(GameObject player)
{
if (targetIconPrefab == null || uiCanvas == null)
{
Debug.LogError("请确保已设置 TargetIconPrefab 和 uiCanvas。");
return;
}
// 实例化 UI 图标
GameObject iconInstance = Instantiate(targetIconPrefab, peopleposition.transform);
// 获取 RectTransform 用于设置位置
RectTransform iconRectTransform = iconInstance.GetComponent<RectTransform>();
// 设置初始内容
Text nameText = iconInstance.GetComponentInChildren<Text>();
if (nameText != null)
{
nameText.text = player.name; // 显示角色名称
}
// 将 UI 图标与玩家对应
playerUIMap[player] = iconRectTransform;
}
// 实时更新所有玩家的 UI
private void UpdateUIForPlayers()
{
foreach (var player in playerList)
{
if (!playerUIMap.ContainsKey(player)) continue;
RectTransform targetIcon = playerUIMap[player];
// 获取玩家的屏幕坐标
Vector3 screenPoint = mainCamera.WorldToScreenPoint(player.transform.position);
// 检查玩家是否在屏幕内
if (screenPoint.z > 0 && screenPoint.x > 0 && screenPoint.x < Screen.width && screenPoint.y > 0 && screenPoint.y < Screen.height)
{
// 玩家在屏幕内,显示图标
targetIcon.gameObject.SetActive(true);
targetIcon.position = screenPoint;
//// 更新图标内容
//Text nameText = targetIcon.GetComponentInChildren<Text>();
//if (nameText != null)
//{
// float distance = Vector3.Distance(mainCamera.transform.position, player.transform.position);
// nameText.text = $"{player.name}\n距离: {distance:F1} 米";
//}
}
else
{
// 玩家不在屏幕内,隐藏图标
targetIcon.gameObject.SetActive(false);
}
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 596a3807554d7de459064cbc2d74e1fe
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,318 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1 &8713418930467998688
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 8713418930467998691}
- component: {fileID: 8713418930467998701}
- component: {fileID: 8713418930467998690}
m_Layer: 5
m_Name: nameImage
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!224 &8713418930467998691
RectTransform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 8713418930467998688}
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:
- {fileID: 8713418932117249394}
m_Father: {fileID: 8713418931296873048}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0.5, y: 0.5}
m_AnchorMax: {x: 0.5, y: 0.5}
m_AnchoredPosition: {x: 100, y: 0}
m_SizeDelta: {x: 150, y: 50}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!222 &8713418930467998701
CanvasRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 8713418930467998688}
m_CullTransparentMesh: 1
--- !u!114 &8713418930467998690
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 8713418930467998688}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: fe87c0e1cc204ed48ad3b37840f39efc, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_RaycastTarget: 1
m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0}
m_Maskable: 1
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_Sprite: {fileID: 21300000, guid: e5ea0e959c8e28d469779ca5e43bd043, type: 3}
m_Type: 0
m_PreserveAspect: 0
m_FillCenter: 1
m_FillMethod: 4
m_FillAmount: 1
m_FillClockwise: 1
m_FillOrigin: 0
m_UseSpriteMesh: 0
m_PixelsPerUnitMultiplier: 1
--- !u!1 &8713418931296873049
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 8713418931296873048}
- component: {fileID: 8713418931296873050}
- component: {fileID: 8713418931296873051}
m_Layer: 5
m_Name: Image
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!224 &8713418931296873048
RectTransform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 8713418931296873049}
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:
- {fileID: 8713418930467998691}
m_Father: {fileID: 8713418931512314567}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0.5, y: 0.5}
m_AnchorMax: {x: 0.5, y: 0.5}
m_AnchoredPosition: {x: -4.5, y: 0}
m_SizeDelta: {x: 50, y: 50}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!222 &8713418931296873050
CanvasRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 8713418931296873049}
m_CullTransparentMesh: 1
--- !u!114 &8713418931296873051
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 8713418931296873049}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: fe87c0e1cc204ed48ad3b37840f39efc, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_RaycastTarget: 1
m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0}
m_Maskable: 1
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_Sprite: {fileID: 21300000, guid: 09483f22e5b7958429cfb80ab82a9f80, type: 3}
m_Type: 0
m_PreserveAspect: 0
m_FillCenter: 1
m_FillMethod: 4
m_FillAmount: 1
m_FillClockwise: 1
m_FillOrigin: 0
m_UseSpriteMesh: 0
m_PixelsPerUnitMultiplier: 1
--- !u!1 &8713418931512314564
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 8713418931512314567}
- component: {fileID: 8713418931512314566}
m_Layer: 5
m_Name: item
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!224 &8713418931512314567
RectTransform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 8713418931512314564}
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:
- {fileID: 8713418931296873048}
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0.5, y: 0.5}
m_AnchorMax: {x: 0.5, y: 0.5}
m_AnchoredPosition: {x: -355, y: -124}
m_SizeDelta: {x: 200, y: 50}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &8713418931512314566
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 8713418931512314564}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 4e29b1a8efbd4b44bb3f3716e73f07ff, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Navigation:
m_Mode: 3
m_WrapAround: 0
m_SelectOnUp: {fileID: 0}
m_SelectOnDown: {fileID: 0}
m_SelectOnLeft: {fileID: 0}
m_SelectOnRight: {fileID: 0}
m_Transition: 1
m_Colors:
m_NormalColor: {r: 1, g: 1, b: 1, a: 1}
m_HighlightedColor: {r: 0.9607843, g: 0.9607843, b: 0.9607843, a: 1}
m_PressedColor: {r: 0.78431374, g: 0.78431374, b: 0.78431374, a: 1}
m_SelectedColor: {r: 0.9607843, g: 0.9607843, b: 0.9607843, a: 1}
m_DisabledColor: {r: 0.78431374, g: 0.78431374, b: 0.78431374, a: 0.5019608}
m_ColorMultiplier: 1
m_FadeDuration: 0.1
m_SpriteState:
m_HighlightedSprite: {fileID: 0}
m_PressedSprite: {fileID: 0}
m_SelectedSprite: {fileID: 0}
m_DisabledSprite: {fileID: 0}
m_AnimationTriggers:
m_NormalTrigger: Normal
m_HighlightedTrigger: Highlighted
m_PressedTrigger: Pressed
m_SelectedTrigger: Selected
m_DisabledTrigger: Disabled
m_Interactable: 1
m_TargetGraphic: {fileID: 0}
m_OnClick:
m_PersistentCalls:
m_Calls: []
--- !u!1 &8713418932117249395
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 8713418932117249394}
- component: {fileID: 8713418932117249404}
- component: {fileID: 8713418932117249405}
m_Layer: 5
m_Name: name
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!224 &8713418932117249394
RectTransform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 8713418932117249395}
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: 8713418930467998691}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0.5, y: 0.5}
m_AnchorMax: {x: 0.5, y: 0.5}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 150, y: 50}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!222 &8713418932117249404
CanvasRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 8713418932117249395}
m_CullTransparentMesh: 1
--- !u!114 &8713418932117249405
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 8713418932117249395}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 5f7201a12d95ffc409449d95f23cf332, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 0.19607843, g: 0.19607843, b: 0.19607843, a: 1}
m_RaycastTarget: 1
m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0}
m_Maskable: 1
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_FontData:
m_Font: {fileID: 10102, guid: 0000000000000000e000000000000000, type: 0}
m_FontSize: 40
m_FontStyle: 0
m_BestFit: 0
m_MinSize: 4
m_MaxSize: 40
m_Alignment: 4
m_AlignByGeometry: 0
m_RichText: 1
m_HorizontalOverflow: 0
m_VerticalOverflow: 0
m_LineSpacing: 1
m_Text: "\u89D2\u82722"

View File

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 00c7bf087b3a01e4bb5cc113b5d6d5fc
PrefabImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff