- Home /
Is there a way to find the file extension of a game asset in script?
Quick Run Down: I'm using empty GameObjects in the unity editor to act as transform.position data place-holders for instantiating(player/NPC)GameObjects during run-time via scripting. Since all these place-holders are not meant to be seen in game, I'm giving them custom unity editor gizmo icons. So I can easily see where they are visually located within the editor.
I wrote the following code to create my gizmos. The code does works as intended, but I do have an issue with it. The code allows me to drop the script on the place-holder GameObjects and then drag my gizmo texture file onto the script's inspector public texture variable. Thereby showing the custom gizmo in the editor at the place-holder's location as intended. Still, I'm not really happy with using || spawnPointIcon.name + ".png" || as my name parameter. Since spawnPointIcon.name only returns the texture's file name without the file extension. Meaning if I want to use a texture file with a different file extension then .png, I would have to hard code the extension each time. Which makes the code a tad inefficient.
So back to my actual question: Is there any possible way to find the file extension of a game asset using code? Thank you very for your time and for reading my question.
C# Code:
using UnityEngine;
using System.Collections;
public class SpawnPointGizmo : MonoBehaviour {
public Texture spawnPointIcon;
void OnDrawGizmos() {
Gizmos.DrawIcon(transform.position, spawnPointIcon.name + ".png", true);
}
}
Your answer
Follow this Question
Related Questions
Gizmos.DrawIcon - is it possible to scale the icon? 2 Answers
Gizmos.DrawIcon, allowScaling = true, icons disappearing. 1 Answer
What is the best way to use the Handles class to create custom gizmos. 1 Answer
Is it possible to draw gizmos when an object is selected, but not when the parent is selected? 2 Answers
Special folders in subfolders ? 1 Answer