Unity3D Editor - Creating Automatically Unique-Named Game Objects? - unity3d

I have some Unity editor integration scripts with that the user should be able to create game objects in the opened scene and I'd like to be able to automatically give each newly created object a unique, preferably sequentially numbered name, e.g.
Actor001
Actor002
Actor003
...
Actor100
etc.
So I was wondering if there are any useful methods known already or whether I have to implement this behavior myself completely, in which case I'm wondering how to figure out the sequence numbering from already existing objects. Any Ideas?

Found it:
GameObjectUtility.GetUniqueNameForSibling(parent, name);

Related

Unity Visual Scripting Variable

I have a scene that has 3 buttons, one for each level. I made buttons 2 and 3 uninteractable and I want to make it so when you win the 1st you can start the 2nd etc... So I have unchecked the interactable box from the options of button2. Then I went to the script of my player and I have connected the following parts so when he completes the 1st level the button 2 gets to be interactible. But there seems to be an issue.
(This answer only applies if you were loading new scenes.)
Perhaps, the problem is that you can’t save a variable telling which levels are allowed. (Unless you do it through, an actual save mechanic.) this is because unity destroys all objects in a scene when loading a new scene. This removes all data stored in variables. You could get around this from using
DontDestroyOnLoad(gameObject);
this saves the gameObect variable you put in the parentheses through scene loading. You can attach a script that would store the variables to this, to save information.
If you can’t figure out how to get the variables from other scripts, use this:
var newVariable = GameObjectVariable.GetComponent<scriptName>().variableName;
I see you were using visual coding, so if you can try and figure out how to find these methods in there, it should work.
If you want to use actual save mechanics, go to this link:
https://docs.unity3d.com/ScriptReference/PlayerPrefs.html/
Set Variable need to receive a flow input.

Should I add the information in both side

I am new to unity ,plz forgive me asking these questions
It bumps out : default reference will only be applied in edit mode
Is it important, what is that?
Should I need to add the information(food and border ) to both sides?
The second image are default references. If you set them they are automatically applied after adding this script to an object.
They are not required. And only apply to a script added via the Editor (not by script!). What matters later on runtime are only the values on the GameObject.
Further you can only reference assets from the Assets folder here. They make sense e.g. if you have a button script that uses a certain Click sound, a texture and e.g. a prefab. For these three you now could already define default values so someone using your component doesn't have to assign everything everytime but already has the default references as a kind of fallback.
So in your case it would only make sense, if the borders are prefabs from the Assets that are spawned by this script. The FoodPrefab is even called like this and makes sense to have as a default reference so you don't have to drag it into each and every instance of SpawnFood you create.
And btw just by looking at your settings you should probably directly make your fields of type RectTransform so you can't accidentally reference another object there.

Filtering an object field in Unity Editor Extension

I'm looking to use Unity's ObjectField to have users search for objects of a particular type. I know the constructor allows for a typeOf(objectType), but that does not seem to allow for filtering on custom components.
Essentially, a previous editor script I have sets up objects, and places a unique custom script on each of the components, but I've been unsuccessful in utilizing the ObjectField to search for just those objects. If I change the typeOf in my object field to be my component, it is always empty, despite there being many prefabs with that script attached in my project.
Has anyone had any success with this? Using GameObject finds them, but this finds all game objects. Is there any way to restrict this? Or to keep it only looking at particular folders?
Adding a filter while the field itself stays as type Object is a bit tricky. Here's one way.
Use ShowObjectPicker
Try opening a custom ObjectPicker. To do so you'll have to hide the default object picker and call one with a set searchFilter. It is quite a bit of work.
Setting searchFilter
Use https://docs.unity3d.com/ScriptReference/EditorGUIUtility.ShowObjectPicker.html with a searchFilter that matches the component you add to every object you want to show up in an ObjectPicker. for example "t:objectType".
There's some good information on using ShowObjectPicker at https://answers.unity.com/questions/554012/how-do-i-use-editorguiutilityshowobjectpicker-c.html
Hide default object picker
Here's a post with a way to hide the default object picker Is there any way to hide the "Object picker" of an EditorGUILayout.ObjectField in Unity Isnpector?
Show picker
You'll need to create your own Editor GUI.Button to bring up the ShowObjectPicker with the custom searchFilter.
Assets searchFilter
As a sidenote, to do the same with file assets use a "l:labelName" fileFilter instead of "t:objectType". You can set the label with the Unity Editor UI as shown here:
or with "ref:relative/path/from/assets/to/material/material.mat"

Swift 1.2 drag and drop controls and views in Cocoa

I'm building one application where I need to make a simple window and be able to drag&drop files onto this window. In this app I have to then parse file path and write out all paths of dropped files in table or nice order (one under another). App doesn't need to take more than one file at once, but this might be a feature for future.
Up to now I have managed to make simple drag&drop in NSView (which I extended with custom class). App is correctly registering drag&drop events and I get all file path and I have also figured how to get file names out of those strings.
My question is: How can I move this "drag&drop" to NSTableView, as I wish to have file names in nicely in table?
I have tried to put tableview under NSView but it doesn't work and if I extend NSTableView class it just registers that there was drag&drop event but nothing else happens.
Do I have to extend other class or how to make this work? I'm implementing NSDraggingDestination protocol in custom class and using performDragOperation function.
I would like to have:
- whole app window can take drag&drop-ed files, not matter where I drop it it has to accept file and put file name into table
I'm sorry if this might sound trivial but I have just started learning swift and developing OS X apps and I'm not used to this new API and don't really know how all things works here.

Unity: On scene added/changed event

Currently I'm writing a script that automatically writes a file with all the scene names as variables. I would like to catch a certain event (if it exists) so that I could know when any scene was added or changed it's name. Currently I have to manually press a button whenever I add a scene or rename one. But since I'm not going to be the only one on my team using this, I'd like to automate this.
Some kind of update cycle would work too, I could then check if the current build list matches my list and if not, update it.
I've tried OnHierarchyChange / OnProjectChange, but those only seem to work on certain assets. Any idea to catch this event?
For future readers:
For Unity 5.3 and below use function OnLevelWasLoaded
http://docs.unity3d.com/530/Documentation/ScriptReference/MonoBehaviour.OnLevelWasLoaded.html
Unity 5.4 + use event: SceneManager.sceneLoaded
http://docs.unity3d.com/540/Documentation/ScriptReference/SceneManagement.SceneManager-sceneLoaded.html