2024-12-23 14:46:56 +08:00
using System ;
using System.Collections ;
using System.Collections.Generic ;
using UnityEngine ;
using UnityEngine.UI ;
2024-12-26 22:26:18 +08:00
using static UnityEditor . Experimental . GraphView . GraphView ;
using static UnityEngine . GraphicsBuffer ;
2024-12-23 14:46:56 +08:00
public class UseObjects : MonoBehaviour
{
private Transform parentObject ; // <20> <> <EFBFBD> <EFBFBD> <EFBFBD> 壨<EFBFBD> <E5A3A8> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> 壩
private GameObject player ; //<2F> <> <EFBFBD> <EFBFBD>
public JSONReader js ;
2024-12-27 16:29:07 +08:00
public List < MatialData > retrievedDataList = new List < MatialData > ( ) ; // <20> 洢<EFBFBD> <E6B4A2> <EFBFBD> <EFBFBD> ID <20> <> ѯ<EFBFBD> <D1AF> <EFBFBD> <EFBFBD> MatialData <20> <> <EFBFBD> <EFBFBD>
2024-12-23 14:46:56 +08:00
//<2F> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> Ʒ ʹ <C6B7> <CAB9>
public GameObject warningPrefab ; // <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <D7B6> <EFBFBD> <EFBFBD> ģ<EFBFBD> <C4A3>
public GameObject polePrefab ; // <20> <> <EFBFBD> <EFBFBD> <EFBFBD> ˵<EFBFBD> <CBB5> <EFBFBD> ģ<EFBFBD> <C4A3>
public GameObject tapePrefab ; // <20> <> <EFBFBD> 뾯ʾ <EBBEAF> <CABE> ģ<EFBFBD> <C4A3>
public float maxDistance = 10f ; // <20> <> <EFBFBD> <EFBFBD> ֱ<EFBFBD> Ӿ<EFBFBD> <D3BE> <EFBFBD> 10<31> <30>
public bool hasTape = false ; // <20> Ƿ<EFBFBD> Я<EFBFBD> <D0AF> <EFBFBD> <EFBFBD> <EFBFBD> 뾯ʾ <EBBEAF> <CABE>
private List < GameObject > warningObjects = new List < GameObject > ( ) ; // <20> 洢<EFBFBD> <E6B4A2> <EFBFBD> о <EFBFBD> <D0BE> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
//<2F> <> Ʒ <EFBFBD> <C6B7> <EFBFBD> <EFBFBD>
public List < GameObject > potentialTargets ; // <20> <> <EFBFBD> п<EFBFBD> <D0BF> ܳ<EFBFBD> Ϊ<EFBFBD> <CEAA> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> Ŀ<EFBFBD> <C4BF> <EFBFBD> б <EFBFBD>
2024-12-27 16:29:07 +08:00
public Transform deliverButton ; // <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ť
2024-12-23 14:46:56 +08:00
public float deliveryRange = 1f ; // <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> Χ <EFBFBD> 뾶
private GameObject currentTarget ; // <20> <> ǰ<EFBFBD> <C7B0> <EFBFBD> <EFBFBD> <EFBFBD> Ľ<EFBFBD> <C4BD> <EFBFBD> Ŀ<EFBFBD> <C4BF>
private bool islogistics ; //<2F> <> ɫ<EFBFBD> Ƿ<EFBFBD> Ϊ<EFBFBD> <CEAA> <EFBFBD> ڱ<EFBFBD> <DAB1> <EFBFBD> <EFBFBD> <EFBFBD> ;
private bool isdelivery ; //<2F> Ƿ<EFBFBD> <C7B7> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
2024-12-27 20:33:32 +08:00
//[System.Serializable]
//public class EmergencyItem
//{
// public string itemName; // <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
// public bool isConsumable; // <20> Ƿ<EFBFBD> <C7B7> <EFBFBD> <EFBFBD> <EFBFBD> Ʒ (1=<3D> ǣ<EFBFBD> 0=<3D> <> )
// public int validTime; // <20> <> Чʱ<D0A7> 䣺-1<> <31> <EFBFBD> <EFBFBD> <EFBFBD> ޣ<EFBFBD> <DEA3> <EFBFBD> 0 <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ʱ<EFBFBD> 䣩
//}
//// ģ<> <C4A3> <EFBFBD> <EFBFBD> Ʒ <EFBFBD> <C6B7> <EFBFBD> ֶ<EFBFBD> <D6B6> <EFBFBD> <EFBFBD> <EFBFBD>
//public Dictionary<string, EmergencyItem> itemConfigs = new Dictionary<string, EmergencyItem>();
public Dictionary < int , MatialData > itemConfigs = new Dictionary < int , MatialData > ( ) ; // <20> <> <EFBFBD> <EFBFBD> ID<49> 洢<EFBFBD> <E6B4A2> Ʒ <EFBFBD> <C6B7> Ϣ
2024-12-23 14:46:56 +08:00
void Start ( )
{
2024-12-27 16:29:07 +08:00
parentObject = transform . Find ( "fireEquip" ) ;
2024-12-23 14:46:56 +08:00
player = GameObject . FindGameObjectWithTag ( "Player" ) ;
// <20> <> ʼ <EFBFBD> <CABC> ģ<EFBFBD> <C4A3> <EFBFBD> <EFBFBD> Ʒ <EFBFBD> <C6B7> <EFBFBD> <EFBFBD>
2024-12-27 20:33:32 +08:00
InitializeItemConfigs ( 3001 , 3002 , 3003 , 3004 , 3005 , 3006 ) ;
2024-12-23 14:46:56 +08:00
// <20> <> <EFBFBD> ؽ<EFBFBD> <D8BD> <EFBFBD> <EFBFBD> <EFBFBD> ť
2024-12-27 16:29:07 +08:00
//deliverButton.gameObject.SetActive(false);
//deliverButton.onClick.AddListener(HandleDelivery);
2024-12-23 14:46:56 +08:00
// Ϊÿ<CEAA> <C3BF> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ӵ<EFBFBD> <D3B5> <EFBFBD> <EFBFBD> ¼<EFBFBD>
foreach ( Transform child in parentObject )
{
Button childButton = child . GetComponent < Button > ( ) ;
if ( childButton = = null )
{
Debug . LogWarning ( $"<22> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> {child.name} ȱ<> <C8B1> Button <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> " ) ;
continue ;
}
// <20> <> ʼ <EFBFBD> <CABC> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ״̬
Transform buttonPanel = child . Find ( "informationImage" ) ;
2024-12-27 16:29:07 +08:00
// <20> <> <EFBFBD> ؽ<EFBFBD> <D8BD> <EFBFBD> <EFBFBD> <EFBFBD> ť
deliverButton = child . Find ( "deliver" ) ;
deliverButton . gameObject . SetActive ( false ) ;
2024-12-23 14:46:56 +08:00
Transform highlight = child . Find ( "Image" ) ;
2024-12-27 16:29:07 +08:00
if ( buttonPanel ! = null )
{
buttonPanel . gameObject . SetActive ( false ) ;
}
2024-12-23 14:46:56 +08:00
if ( highlight ! = null ) highlight . gameObject . SetActive ( false ) ;
// <20> <EFBFBD> <F3B6A8B5> <EFBFBD> <EFBFBD> ¼<EFBFBD>
childButton . onClick . AddListener ( ( ) = > OnChildClicked ( child . gameObject ) ) ;
}
2024-12-26 22:26:18 +08:00
// <20> <> ȡ<EFBFBD> <C8A1> <EFBFBD> б <EFBFBD> ǩΪ "People" <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
GameObject [ ] playNPC = GameObject . FindGameObjectsWithTag ( "People" ) ;
// <20> <> <EFBFBD> <EFBFBD> ÿ<EFBFBD> <C3BF> <EFBFBD> <EFBFBD> ,<2C> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> һ <EFBFBD> <D2BB> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
foreach ( GameObject player in playNPC )
{
potentialTargets . Add ( player . gameObject ) ;
}
2024-12-27 20:33:32 +08:00
//UseCautionaryitems(player.transform.position, polePrefab);
2024-12-23 14:46:56 +08:00
}
private void Update ( )
{
// <20> ڷ<EFBFBD> Χ <EFBFBD> ڲ<EFBFBD> <DAB2> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> Ľ<EFBFBD> <C4BD> <EFBFBD> Ŀ<EFBFBD> <C4BF>
currentTarget = FindNearestTarget ( ) ;
if ( currentTarget ! = null )
{
// <20> <> ʾ <EFBFBD> <CABE> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ť<EFBFBD> <C5A5> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> Ŀ<EFBFBD> <C4BF>
HighlightTarget ( currentTarget , true ) ;
deliverButton . gameObject . SetActive ( true ) ;
}
else
{
// <20> <> <EFBFBD> ؽ<EFBFBD> <D8BD> <EFBFBD> <EFBFBD> <EFBFBD> ť<EFBFBD> <C5A5> ȡ<EFBFBD> <C8A1> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
if ( currentTarget ! = null )
{
HighlightTarget ( currentTarget , false ) ;
}
deliverButton . gameObject . SetActive ( false ) ;
}
}
// <20> <> ʼ <EFBFBD> <CABC> ģ<EFBFBD> <C4A3> <EFBFBD> <EFBFBD> Ʒ <EFBFBD> <C6B7> <EFBFBD> <EFBFBD>
2024-12-27 20:33:32 +08:00
void InitializeItemConfigs ( params int [ ] ids )
2024-12-23 14:46:56 +08:00
{
2024-12-27 20:33:32 +08:00
//itemConfigs.Add("1", new EmergencyItem { itemName = "1", isConsumable = true, validTime = -1 });
//itemConfigs.Add("2", new EmergencyItem { itemName = "2", isConsumable = true, validTime = 30 });
//itemConfigs.Add("3", new EmergencyItem { itemName = "3", isConsumable = false, validTime = 15 });
//itemConfigs.Add("4", new EmergencyItem { itemName = "4", isConsumable = true, validTime = -1 });
//itemConfigs.Add("5", new EmergencyItem { itemName = "5", isConsumable = true, validTime = 30 });
//itemConfigs.Add("6", new EmergencyItem { itemName = "6", isConsumable = false, validTime = 15 });
// <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ID <20> <> <EFBFBD> <EFBFBD>
foreach ( int id in ids )
2024-12-23 14:46:56 +08:00
{
2024-12-27 20:33:32 +08:00
// <20> <> <EFBFBD> Ӹ<EFBFBD> <D3B8> <EFBFBD> <EFBFBD> <EFBFBD> Ʒ <EFBFBD> <C6B7> <EFBFBD> <EFBFBD> ...
foreach ( var key in js . matialDictionary )
2024-12-23 14:46:56 +08:00
{
2024-12-27 20:33:32 +08:00
MatialData matialData = key . Value ;
if ( matialData . ID = = id )
{
//<2F> <> ȡ<EFBFBD> <C8A1> Ʒ <EFBFBD> <C6B7> <EFBFBD> <EFBFBD>
itemConfigs [ id ] = matialData ; // <20> <> ƥ<EFBFBD> <C6A5> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ӵ<EFBFBD> <D3B5> ֵ<EFBFBD> <D6B5> <EFBFBD>
Debug . Log ( $"<22> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ҵ<EFBFBD> : ID={matialData.ID}, Note={matialData.Note}, Type={matialData.Type}, Name={matialData.Name}" ) ;
}
}
// <20> <> <EFBFBD> <EFBFBD> δ<EFBFBD> ҵ<EFBFBD> <D2B5> <EFBFBD> <EFBFBD> <EFBFBD>
if ( retrievedDataList . Count = = 0 )
{
Debug . LogWarning ( "δ<> ҵ<EFBFBD> <D2B5> <EFBFBD> Ӧ ID <20> <> <EFBFBD> <EFBFBD> <EFBFBD> ݣ<EFBFBD> " ) ;
}
2024-12-23 14:46:56 +08:00
}
}
// <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> 屻<EFBFBD> <E5B1BB> <EFBFBD> <EFBFBD> ʱ
void OnChildClicked ( GameObject clickedChild )
{
// <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> İ<EFBFBD> ť<EFBFBD> <C5A5> <EFBFBD> ߹<CDB8> <DFB9> <EFBFBD>
foreach ( Transform child in parentObject )
{
Transform buttonPanel = child . Find ( "informationImage" ) ;
Transform highlight = child . Find ( "Image" ) ;
if ( buttonPanel ! = null ) buttonPanel . gameObject . SetActive ( false ) ;
if ( highlight ! = null ) highlight . gameObject . SetActive ( false ) ;
}
2024-12-27 20:33:32 +08:00
// <20> <> ȡ<EFBFBD> <C8A1> ǰ<EFBFBD> <C7B0> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> Ʋ<EFBFBD> <C6B2> <EFBFBD> <EFBFBD> <EFBFBD> ת<EFBFBD> <D7AA> Ϊ ID
if ( int . TryParse ( clickedChild . name , out int itemId ) & & itemConfigs . TryGetValue ( itemId , out MatialData itemData ) )
2024-12-23 14:46:56 +08:00
{
2024-12-27 20:33:32 +08:00
Debug . Log ( $"<22> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> Ʒ ID: {itemId}" ) ;
2024-12-23 14:46:56 +08:00
2024-12-27 20:33:32 +08:00
// <20> <> ȡ<EFBFBD> <C8A1> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> е İ<D0B5> ť<EFBFBD> <C5A5> <EFBFBD> <EFBFBD> <EFBFBD> ߹<CDB8> <DFB9> <EFBFBD>
Transform clickedButtonPanel = clickedChild . transform . Find ( "informationImage" ) ;
Transform clickedHighlight = clickedChild . transform . Find ( "Image" ) ;
2024-12-23 14:46:56 +08:00
2024-12-27 20:33:32 +08:00
// <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> Ʒ <EFBFBD> <C6B7> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ʾ <EFBFBD> <CABE> ť<EFBFBD> <C5A5> <EFBFBD> <EFBFBD> <EFBFBD> Ͱ<EFBFBD> ť
if ( clickedButtonPanel ! = null )
{
UpdateButtonPanel ( clickedButtonPanel , itemData ) ;
}
2024-12-23 14:46:56 +08:00
2024-12-27 20:33:32 +08:00
// <20> <> ʾ <EFBFBD> <CABE> ǰ<EFBFBD> <C7B0> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ĸ߹<C4B8> <DFB9> <EFBFBD>
if ( clickedHighlight ! = null )
{
clickedHighlight . gameObject . SetActive ( true ) ;
}
}
else
2024-12-23 14:46:56 +08:00
{
2024-12-27 20:33:32 +08:00
Debug . LogWarning ( $"δ<> ҵ<EFBFBD> <D2B5> <EFBFBD> Ʒ <EFBFBD> <C6B7> <EFBFBD> ã<EFBFBD> <C3A3> <EFBFBD> Ʒ <EFBFBD> <C6B7> <EFBFBD> <EFBFBD> : {clickedChild.name}" ) ;
2024-12-23 14:46:56 +08:00
}
}
// <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> Ʒ <EFBFBD> <C6B7> <EFBFBD> ø<EFBFBD> <C3B8> °<EFBFBD> ť<EFBFBD> <C5A5> <EFBFBD> <EFBFBD>
2024-12-27 20:33:32 +08:00
void UpdateButtonPanel ( Transform buttonPanel , MatialData itemData )
2024-12-23 14:46:56 +08:00
{
// <20> <> ȡ<EFBFBD> <C8A1> ť
Button viewButton = buttonPanel . Find ( "LookButton" ) . GetComponent < Button > ( ) ;
Button useButton = buttonPanel . Find ( "UseButton" ) . GetComponent < Button > ( ) ;
Button discardButton = buttonPanel . Find ( "ThrowButton" ) . GetComponent < Button > ( ) ;
2024-12-27 20:33:32 +08:00
// <20> <> <EFBFBD> <EFBFBD> ֮ǰ<D6AE> <EFBFBD> <F3B6A8B5> ¼<EFBFBD> <C2BC> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ظ<EFBFBD> <D8B8> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ¼<EFBFBD>
viewButton . onClick . RemoveAllListeners ( ) ;
useButton . onClick . RemoveAllListeners ( ) ;
discardButton . onClick . RemoveAllListeners ( ) ;
2024-12-23 14:46:56 +08:00
// <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ʾ <EFBFBD> <CABE> <EFBFBD> <EFBFBD> <EFBFBD> ذ<EFBFBD> ť
2024-12-27 20:33:32 +08:00
bool isConsumable = itemData . ConsumableType = = 1 ; // <20> Ƿ<EFBFBD> <C7B7> <EFBFBD> <EFBFBD> <EFBFBD> Ʒ
int validTime = itemData . Durations ; // <20> <> Чʱ<D0A7> <CAB1>
if ( isConsumable & & validTime = = - 1 )
2024-12-23 14:46:56 +08:00
{
// <20> <> <EFBFBD> <EFBFBD> 1<EFBFBD> <31> ֱ<EFBFBD> <D6B1> ʹ <EFBFBD> ã<EFBFBD> <C3A3> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ť
buttonPanel . gameObject . SetActive ( false ) ;
2024-12-27 20:33:32 +08:00
UseItem ( itemData ) ;
2024-12-23 14:46:56 +08:00
}
2024-12-27 20:33:32 +08:00
else if ( isConsumable & & validTime > = 0 )
2024-12-23 14:46:56 +08:00
{
buttonPanel . gameObject . SetActive ( true ) ;
// <20> <> <EFBFBD> <EFBFBD> 2<EFBFBD> <32> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> 鿴<EFBFBD> <E9BFB4> <EFBFBD> <EFBFBD> ʹ <EFBFBD> á<EFBFBD> <C3A1> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
viewButton . gameObject . SetActive ( true ) ;
useButton . gameObject . SetActive ( true ) ;
discardButton . gameObject . SetActive ( true ) ;
// <20> <> <EFBFBD> <EFBFBD> <EFBFBD> ¼<EFBFBD>
2024-12-27 20:33:32 +08:00
viewButton . onClick . AddListener ( ( ) = > ViewItem ( itemData ) ) ;
useButton . onClick . AddListener ( ( ) = > UseItem ( itemData ) ) ;
discardButton . onClick . AddListener ( ( ) = > DiscardItem ( itemData ) ) ;
2024-12-23 14:46:56 +08:00
}
2024-12-27 20:33:32 +08:00
else if ( ! isConsumable & & validTime > = 0 )
2024-12-23 14:46:56 +08:00
{
buttonPanel . gameObject . SetActive ( true ) ;
// <20> <> <EFBFBD> <EFBFBD> 3<EFBFBD> <33> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> 鿴<EFBFBD> <E9BFB4> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
viewButton . gameObject . SetActive ( true ) ;
useButton . gameObject . SetActive ( false ) ;
discardButton . gameObject . SetActive ( true ) ;
// <20> <> <EFBFBD> <EFBFBD> <EFBFBD> ¼<EFBFBD>
2024-12-27 20:33:32 +08:00
viewButton . onClick . AddListener ( ( ) = > ViewItem ( itemData ) ) ;
discardButton . onClick . AddListener ( ( ) = > DiscardItem ( itemData ) ) ;
2024-12-23 14:46:56 +08:00
}
}
// <20> 鿴<EFBFBD> <E9BFB4> Ʒ <EFBFBD> <EFBFBD>
2024-12-27 20:33:32 +08:00
void ViewItem ( MatialData item )
2024-12-23 14:46:56 +08:00
{
2024-12-27 20:33:32 +08:00
Debug . Log ( $"<22> 鿴<EFBFBD> <E9BFB4> Ʒ <EFBFBD> <C6B7> {item.Name}" ) ;
2024-12-23 14:46:56 +08:00
}
// ʹ <> <CAB9> <EFBFBD> <EFBFBD> Ʒ <EFBFBD> <EFBFBD>
2024-12-27 20:33:32 +08:00
void UseItem ( MatialData item )
2024-12-23 14:46:56 +08:00
{
2024-12-27 20:33:32 +08:00
Debug . Log ( $"ʹ <> <CAB9> <EFBFBD> <EFBFBD> Ʒ <EFBFBD> <C6B7> {item.Name}" ) ;
2024-12-23 14:46:56 +08:00
}
// <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> Ʒ <EFBFBD> <EFBFBD>
2024-12-27 20:33:32 +08:00
void DiscardItem ( MatialData item )
2024-12-23 14:46:56 +08:00
{
2024-12-27 20:33:32 +08:00
Debug . Log ( $"<22> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> Ʒ <EFBFBD> <C6B7> {item.Name}" ) ;
2024-12-23 14:46:56 +08:00
}
//ʹ <> þ<EFBFBD> <C3BE> <EFBFBD> <EFBFBD> <EFBFBD> Ʒ
void UseCautionaryitems ( Vector3 playerPosition , GameObject gameObject )
{
// <20> <> <EFBFBD> ɾ<EFBFBD> <C9BE> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> (<28> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ,<2C> <> <EFBFBD> <EFBFBD> )
GameObject newWarning = Instantiate ( gameObject , playerPosition , Quaternion . identity ) ;
warningObjects . Add ( newWarning ) ;
// <20> жϵ<D0B6> ǰλ<C7B0> <CEBB> <EFBFBD> Ƿ<EFBFBD> <C7B7> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> 10<31> <30> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
GameObject nearestWarning = FindNearestWarning ( newWarning ) ;
if ( nearestWarning ! = null )
{
if ( hasTape )
{
// <20> <> <EFBFBD> <EFBFBD> Я<EFBFBD> <D0AF> <EFBFBD> <EFBFBD> <EFBFBD> 뾯ʾ <EBBEAF> <CABE> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ӵ<EFBFBD> <D3B5> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ľ<EFBFBD> <C4BE> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
CreateTape ( newWarning , nearestWarning ) ;
}
else
{
// <20> <> Я<EFBFBD> <D0AF> <EFBFBD> <EFBFBD> <EFBFBD> 뾯ʾ <EBBEAF> <CABE> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ʾ <EFBFBD> <CABE> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> Ч<EFBFBD> Լ<EFBFBD> ¼
Debug . Log ( "δЯ<CEB4> <D0AF> <EFBFBD> <EFBFBD> <EFBFBD> 뾯ʾ <EBBEAF> <CABE> <EFBFBD> <EFBFBD> δ<EFBFBD> <CEB4> <EFBFBD> Ӿ<EFBFBD> <D3BE> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ߣ<EFBFBD> " ) ;
}
}
else
{
Debug . Log ( "<22> <> ǰλ<C7B0> <CEBB> <EFBFBD> <EFBFBD> Χ 10<31> <EFBFBD> Χ <EFBFBD> <CEA7> û<EFBFBD> <C3BB> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ߣ<EFBFBD> " ) ;
}
}
// <20> ҵ<EFBFBD> <D2B5> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ľ<EFBFBD> <C4BE> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
private GameObject FindNearestWarning ( GameObject currentWarning )
{
GameObject nearest = null ;
float minDistance = maxDistance ;
foreach ( GameObject warning in warningObjects )
{
if ( warning = = currentWarning ) continue ; // <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ǰ<EFBFBD> <C7B0> <EFBFBD> <EFBFBD>
float distance = Vector3 . Distance ( currentWarning . transform . position , warning . transform . position ) ;
if ( distance < minDistance )
{
minDistance = distance ;
nearest = warning ;
}
}
return nearest ;
}
// <20> <> <EFBFBD> ɸ<EFBFBD> <C9B8> 뾯ʾ <EBBEAF> <CABE>
private void CreateTape ( GameObject start , GameObject end )
{
// <20> <> <EFBFBD> ɸ<EFBFBD> <C9B8> 뾯ʾ <EBBEAF> <CABE>
GameObject tape = Instantiate ( tapePrefab ) ;
// <20> <> <EFBFBD> ø<EFBFBD> <C3B8> 뾯ʾ <EBBEAF> <CABE> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> յ<EFBFBD>
LineRenderer lineRenderer = tape . GetComponent < LineRenderer > ( ) ;
if ( lineRenderer ! = null )
{
lineRenderer . positionCount = 2 ;
lineRenderer . SetPosition ( 0 , start . transform . position ) ;
lineRenderer . SetPosition ( 1 , end . transform . position ) ;
}
Debug . Log ( $"<22> <> <EFBFBD> <EFBFBD> <EFBFBD> Ӿ<EFBFBD> <D3BE> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ߣ<EFBFBD> {start.name} -> {end.name}" ) ;
}
// <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <DFBC> в<EFBFBD> <D0B2> ҷ<EFBFBD> Χ <EFBFBD> <CEA7> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> Ŀ<EFBFBD> <C4BF>
GameObject FindNearestTarget ( )
{
GameObject nearestTarget = null ;
float nearestDistance = deliveryRange ;
foreach ( var target in potentialTargets )
{
float distance = Vector3 . Distance ( player . transform . position , target . transform . position ) ;
if ( distance < = deliveryRange & & IsInFront ( target ) )
{
nearestTarget = target ;
nearestDistance = distance ;
}
}
return nearestTarget ;
}
// <20> ж<EFBFBD> Ŀ<EFBFBD> <C4BF> <EFBFBD> Ƿ<EFBFBD> <C7B7> ڽ<EFBFBD> ɫ<EFBFBD> <C9AB> <EFBFBD> <EFBFBD> 180 <20> <> <EFBFBD> <EFBFBD>
bool IsInFront ( GameObject target )
{
Vector3 directionToTarget = ( target . transform . position - player . transform . position ) . normalized ;
float dotProduct = Vector3 . Dot ( player . transform . forward , directionToTarget ) ;
return dotProduct > 0 ; // <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> 180 <20> <> <EFBFBD> <EFBFBD>
}
// <20> <> <EFBFBD> <EFBFBD> Ŀ<EFBFBD> ꣨<EFBFBD> <EAA3A8> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ʾ <EFBFBD> <CABE> Ե<EFBFBD> <D4B5> <EFBFBD> <EFBFBD> Ч<EFBFBD> <D0A7> <EFBFBD> <EFBFBD>
void HighlightTarget ( GameObject target , bool highlight )
{
Renderer renderer = target . GetComponent < Renderer > ( ) ;
if ( renderer ! = null )
{
// <20> <> <EFBFBD> ø<EFBFBD> <C3B8> <EFBFBD> Ч<EFBFBD> <D0A7> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> IJ<EFBFBD> <C4B2> ʻ <EFBFBD> <CABB> <EFBFBD> ɫ
renderer . material . SetColor ( "_EmissionColor" , highlight ? Color . green : Color . black ) ;
}
}
// <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
void HandleDelivery ( )
{
if ( currentTarget = = null )
{
Debug . LogWarning ( "û<> пɽ<D0BF> <C9BD> <EFBFBD> <EFBFBD> <EFBFBD> Ŀ<EFBFBD> ꣡" ) ;
return ;
}
// <20> <> <EFBFBD> <EFBFBD> Ŀ<EFBFBD> <C4BF> ְҵ<D6B0> Ƿ<EFBFBD> <C7B7> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
TargetData targetData = currentTarget . GetComponent < TargetData > ( ) ;
if ( targetData = = null | | targetData . weightCapacity = = - 1 )
{
Debug . LogWarning ( "Ŀ<> 겻<EFBFBD> <EAB2BB> <EFBFBD> 㽻<EFBFBD> <E3BDBB> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> " ) ;
return ;
}
// ִ<> н<EFBFBD> <D0BD> <EFBFBD> <EFBFBD> <EFBFBD> <DFBC> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ҵ<EFBFBD> <D2B5> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> Ŀ<EFBFBD> <C4BF> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
PlayerInventory playerInventory = player . GetComponent < PlayerInventory > ( ) ;
if ( playerInventory ! = null & & playerInventory . UseItem ( "SelectedItem" ) )
{
targetData . ReceiveItem ( "SelectedItem" ) ;
Debug . Log ( $"<22> ɹ<EFBFBD> <C9B9> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ߸<EFBFBD> Ŀ<EFBFBD> ꣺{currentTarget.name}" ) ;
}
else
{
Debug . LogWarning ( "<22> <> <EFBFBD> ҵ<EFBFBD> <D2B5> ߲<EFBFBD> <DFB2> 㣬<EFBFBD> <EFBFBD> <DEB7> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> " ) ;
}
}
}
// Ŀ<> <C4BF> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
public class TargetData : MonoBehaviour
{
public int weightCapacity = 10 ; // <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ֵ
private Dictionary < string , int > receivedItems = new Dictionary < string , int > ( ) ;
public void ReceiveItem ( string itemName )
{
if ( receivedItems . ContainsKey ( itemName ) )
{
receivedItems [ itemName ] + + ;
}
else
{
receivedItems [ itemName ] = 1 ;
}
Debug . Log ( $"{itemName} <20> <> <EFBFBD> ճɹ<D5B3> <C9B9> <EFBFBD> <EFBFBD> <EFBFBD> ǰ<EFBFBD> <C7B0> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> {receivedItems[itemName]}" ) ;
}
}
// <20> <> <EFBFBD> ҵ<EFBFBD> <D2B5> ߹<EFBFBD> <DFB9> <EFBFBD> <EFBFBD> <EFBFBD>
public class PlayerInventory : MonoBehaviour
{
private Dictionary < string , int > items = new Dictionary < string , int >
{
{ "SelectedItem" , 5 } // ģ<> <C4A3> <EFBFBD> <EFBFBD> <EFBFBD> ҵĵ<D2B5> <C4B5> ߿<EFBFBD> <DFBF> <EFBFBD>
} ;
public bool UseItem ( string itemName )
{
if ( items . ContainsKey ( itemName ) & & items [ itemName ] > 0 )
{
items [ itemName ] - - ;
Debug . Log ( $"{itemName} ʹ <> óɹ<C3B3> <C9B9> <EFBFBD> ʣ<EFBFBD> <CAA3> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> {items[itemName]}" ) ;
return true ;
}
Debug . LogWarning ( $"{itemName} ʹ <> <CAB9> ʧ<EFBFBD> ܣ<EFBFBD> <DCA3> <EFBFBD> <EFBFBD> 治<EFBFBD> 㣡" ) ;
return false ;
}
}