Advertisement
halleman19

rename tiles in grid | unity3d

Oct 13th, 2023 (edited)
783
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.61 KB | Gaming | 0 0
  1. using System.Text.RegularExpressions;
  2. using UnityEditor;
  3. using UnityEngine;
  4. using UnityEngine.UIElements;
  5.  
  6. public class EditRename : EditorWindow
  7. {
  8.     [MenuItem("dev/hierarchly")]
  9.     public static void showHierEditWind()
  10.     {
  11.         EditRename hierWind = GetWindow<EditRename>();
  12.         hierWind.titleContent = new GUIContent("rename tiles");
  13.     }
  14.  
  15.     public TextField newTagTitle;
  16.  
  17.     public void CreateGUI()
  18.     {
  19.         VisualElement rootVisual = rootVisualElement;
  20.  
  21.         Button mainBtn = new Button();
  22.         mainBtn.name = "renameBtn";
  23.         mainBtn.text = "rename tiles";
  24.         mainBtn.clicked += MainBtn_clicked;
  25.  
  26.         rootVisual.Add(mainBtn);
  27.  
  28.         Button changeTagBtn = new Button();
  29.         changeTagBtn.name = "changeTagBtn";
  30.         changeTagBtn.text = "change tag";
  31.         changeTagBtn.clicked += ChangeTagBtn_clicked;;
  32.  
  33.         newTagTitle = new TextField();
  34.         newTagTitle.value = "set title new tag";
  35.        
  36.         rootVisual.Add(newTagTitle);
  37.         rootVisual.Add(changeTagBtn);
  38.     }
  39.  
  40.     private void MainBtn_clicked()
  41.     {
  42.         GameObject[] objs = GameObject.FindGameObjectsWithTag("tile");
  43.  
  44.         for (int i = 0; i < 10; i++)
  45.         {
  46.             for (int j = 0; j < 10; j++)
  47.             {
  48.                 objs[(i * 10) + j].name = string.Format("tile {0} {1}", i, j);
  49.             }
  50.         }
  51.     }
  52.  
  53.     private void ChangeTagBtn_clicked()
  54.     {
  55.         GameObject[] objs = GameObject.FindGameObjectsWithTag("tile");
  56.  
  57.         foreach (GameObject obj in objs)
  58.             obj.transform.GetChild(0).tag = newTagTitle.value;
  59.     }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement