Hi I am trying to find out if there is a function that is called when an object is dragged and dropped into a scene in the editor.
I need to run some code once when each object is added.
The editor scripting documentation is pretty thin.
Hi I am trying to find out if there is a function that is called when an object is dragged and dropped into a scene in the editor.
I need to run some code once when each object is added.
The editor scripting documentation is pretty thin.
ok i found a rather horrible way of doing what I wanted. I created a script that goes through every item in every scene and assigns them a unique ID. I’m still interested in the answer to my original question though.
using UnityEngine;
using UnityEditor;
using System.Collections;
public class SetUI : MonoBehaviour
{
static int id = 1;
[MenuItem ("GameObject/Assign All Items Unique IDS")]
static void SetItemUIS()
{
UnityEditor.EditorBuildSettingsScene[] allScenes = EditorBuildSettings.scenes;
// loop through all the scenes
foreach(UnityEditor.EditorBuildSettingsScene scene in allScenes)
{
// open scenes
EditorApplication.OpenScene(scene.path);
//find all Items in each scene
GameObject[] items = GameObject.FindGameObjectsWithTag("Item");
foreach (GameObject item in items)
{
// assign each a unique ID
Item itemScript = item.GetComponent<Item>() as Item;
itemScript.itemID = id;
Debug.Log(item.name + " " + id.ToString());
// increment id
id++;
}
}
}
}