Скрипт ищет в объекте чилды, имя которых содержит указанный ключ и назначает им, заданный tag

Таг по имени

CsCarsEditor.cs (в папку Editor)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
//Created by Neodrop
//neodrop@unity3d.ru
using UnityEditor;
using UnityEngine;

[CustomEditor(typeof(CsCarSettings))]
public class CsCarsEditor : Editor
{
   CsCarSettings targetObject;

void OnEnable ()
{
    targetObject = target as CsCarSettings;
}

public override void OnInspectorGUI()
{
    EditorGUILayout.Separator();

   GUILayout.Label("Set Tag : ");// instead of RigidBody : ");
   targetObject.tagTo = EditorGUILayout.TagField(targetObject.tagTo, EditorStyles.miniButton, GUILayout.Width(128));

   GUILayout.BeginHorizontal(); GUILayout.Space(5);
   targetObject.nameToAddTag = EditorGUILayout.TextField("Name to add tag : ", targetObject.nameToAddTag);
   GUILayout.EndHorizontal();

   if(GUILayout.Button("OK", EditorStyles.miniButton, GUILayout.Width(128)))
   {
      int index = 0;
      foreach (Transform tr in targetObject.gameObject.GetComponentsInChildren() as Transform[])
      {
          if (tr == targetObject.transform) continue;
          if (tr.gameObject.name.Contains(targetObject.nameToAddTag))
      {
          tr.gameObject.tag = targetObject.tagTo;
          index++;
      }
   }
   EditorUtility.SetDirty(targetObject.gameObject);
   EditorUtility.DisplayDialog("DONE", "Tag " + targetObject.tagTo + " added to " + index + " objects.", "OK");
   }
}
}

CsCarSettings.cs (в папку Scripts)

1
2
3
4
5
6
7
8
//Created by Neodrop
//neodrop@unity3d.ru
using UnityEngine;

public class CsCarSettings : MonoBehaviour
{
   public string tagTo = "", nameToAddTag = "Collision";
}
VN:F [1.9.3_1094]
Rating: 10.0/10 (1 vote cast)
VN:F [1.9.3_1094]
Rating: 0 (from 0 votes)
Назначить Таг по имени объекта, 10.0 out of 10 based on 1 rating

4 комментария на «Назначить Таг по имени объекта»

  1. Armando

    lewisohn@dora.progandist” rel=”nofollow”>.…

    спс….

    VA:F [1.9.3_1094]
    Rating: 0.0/5 (0 votes cast)
    VA:F [1.9.3_1094]
    Rating: 0 (from 0 votes)
  2. Kyle

    mocking@flakes.unmanageably” rel=”nofollow”>.…

    спс!!…

    VA:F [1.9.3_1094]
    Rating: 0.0/5 (0 votes cast)
    VA:F [1.9.3_1094]
    Rating: 0 (from 0 votes)
  3. Everett

    ptc@waters.virtues” rel=”nofollow”>.…

    спс….

    VA:F [1.9.3_1094]
    Rating: 0.0/5 (0 votes cast)
    VA:F [1.9.3_1094]
    Rating: 0 (from 0 votes)
  4. Bernard

    canine@binoculars.administrators” rel=”nofollow”>.…

    спс за инфу!…

    VA:F [1.9.3_1094]
    Rating: 0.0/5 (0 votes cast)
    VA:F [1.9.3_1094]
    Rating: 0 (from 0 votes)

Ваш отзыв

Вы должны войти, чтобы оставлять комментарии.



Страница 1 of 0