Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Editor script to do the same task as if you manually clicked "Assign Unique ID" on all TNObjects
- using System.Reflection;
- using TNet;
- using UnityEditor;
- using UnityEngine;
- public static class TNOUnique
- {
- [MenuItem ("Tools/Assign UniqueId All TNObjects")]
- static void ApplyAllUnique()
- {
- var mStaticIDField = typeof(TNObject).GetField("mStaticID", BindingFlags.Instance | BindingFlags.NonPublic);
- var tnObjects = GameObject.FindObjectsOfType<TNObject>();
- Undo.RecordObjects(tnObjects, "Assign UniqueId All TNObjects");
- int count = 0;
- foreach (var tno in tnObjects)
- {
- if ((int) mStaticIDField.GetValue(tno) == 0)
- {
- var uniqueId = (int)TNObject.GetUniqueID(false);
- mStaticIDField.SetValue(tno, uniqueId);
- count++;
- }
- }
- Debug.Log($"Updated static id on {count} TNObjects");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement