- Home /
Question by
Xarbrough · Dec 09, 2017 at 07:17 PM ·
c#editor-scripting
What is a better way to check if an object is a project asset, but not a folder in the editor?
I'm doing some custom logic with the currently selected object in the editor and I want to filter for:
Must be an asset in the project view, not a GameObject from the scene
Must not be folder
This is how I am currently filtering:
public override void HandleSelectionChange()
{
Object selected = Selection.activeObject;
if (IsRelevantAsset(selected))
base.Add(selected);
}
private bool IsRelevantAsset(Object obj)
{
return
obj != null &&
AssetDatabase.Contains(obj) &&
AssetDatabase.IsValidFolder(AssetDatabase.GetAssetPath(obj)) == false;
}
This works, but I fear that it's a little slow and might add up when I add more functionality.
Is there any faster/better way to check for my conditions?
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612144302im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Working with Unity Editor 1 Answer
How to play mecanim animations in Editor mode? 2 Answers
Editor Script into .dll(Solved) 1 Answer