OpToolReplacement.cs 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. using Sirenix.OdinInspector;
  2. using System;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. using UnityEngine;
  6. public class OpToolReplacement : MonoBehaviour
  7. {
  8. public List<ToolReplacement> replaceData;
  9. [Button("修改工器具名称")]
  10. public void ReplaceTool()
  11. {
  12. OpTrigger_ToolPack[] tmpToolPacks = FindObjectsOfType<OpTrigger_ToolPack>();
  13. foreach (var toolPackItem in tmpToolPacks)
  14. {
  15. if (toolPackItem.useTool)
  16. {
  17. for(int i = 0; i< toolPackItem.choseToolNames.Count; i++)
  18. {
  19. foreach(ToolReplacement tp in replaceData)
  20. if (toolPackItem.choseToolNames[i].Equals(tp.beforeTool))
  21. {
  22. toolPackItem.choseToolNames[i] = tp.afterTool;
  23. continue;
  24. }
  25. }
  26. }
  27. }
  28. OPTrigger_SelectToolElemet[] tmpToolSelect = FindObjectsOfType<OPTrigger_SelectToolElemet>();
  29. if (tmpToolSelect[0] != null)
  30. tmpToolSelect[0].SearchTools();
  31. }
  32. }
  33. [Serializable]
  34. public class ToolReplacement
  35. {
  36. [LabelText("要修改的名称")]
  37. public string beforeTool;
  38. [LabelText("修改之后的名称")]
  39. public string afterTool;
  40. }