Advertisement
Deozaan

TNOUnique.cs

May 24th, 2020
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.96 KB | None | 0 0
  1. // Editor script to do the same task as if you manually clicked "Assign Unique ID" on all TNObjects
  2.  
  3. using System.Reflection;
  4. using TNet;
  5. using UnityEditor;
  6. using UnityEngine;
  7.  
  8. public static class TNOUnique
  9. {
  10.     [MenuItem ("Tools/Assign UniqueId All TNObjects")]
  11.     static void ApplyAllUnique()
  12.     {
  13.         var mStaticIDField = typeof(TNObject).GetField("mStaticID", BindingFlags.Instance | BindingFlags.NonPublic);
  14.         var tnObjects = GameObject.FindObjectsOfType<TNObject>();
  15.        
  16.         Undo.RecordObjects(tnObjects, "Assign UniqueId All TNObjects");
  17.        
  18.         int count = 0;
  19.         foreach (var tno in tnObjects)
  20.         {
  21.             if ((int) mStaticIDField.GetValue(tno) == 0)
  22.             {
  23.                 var uniqueId = (int)TNObject.GetUniqueID(false);
  24.                 mStaticIDField.SetValue(tno, uniqueId);
  25.                 count++;
  26.             }
  27.         }
  28.         Debug.Log($"Updated static id on {count} TNObjects");
  29.     }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement