Skip to content

Instantly share code, notes, and snippets.

@hogashi
Created June 19, 2022 16:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hogashi/1d71bb2cdf34e7ab717c4fe8e49a2aa7 to your computer and use it in GitHub Desktop.
Save hogashi/1d71bb2cdf34e7ab717c4fe8e49a2aa7 to your computer and use it in GitHub Desktop.
using UnityEngine;
using UnityEditor;
public class EditorWindowSample : EditorWindow
{
[MenuItem("Editor/Sample")]
private static void Create()
{
GetWindow<EditorWindowSample>("rename samplescene");
}
private void RenameActiveScene()
{
int sceneCount = UnityEngine.SceneManagement.SceneManager.sceneCount;
for (int i = 0; i < sceneCount; i += 1) {
UnityEngine.SceneManagement.Scene scene = UnityEngine.SceneManagement.SceneManager.GetSceneAt(i);
if (scene.name == "Sample Scene") {
var path = scene.path;
var guid = AssetDatabase.AssetPathToGUID(path);
var newName = scene.name + "_" + guid;
Debug.Log("Renaming scene \"" + path + "\" to \"" + newName + "\"");
var err = AssetDatabase.RenameAsset(path, newName);
if (err != "") {
Debug.LogError(err);
}
}
}
}
private void OnGUI()
{
using (new GUILayout.HorizontalScope())
{
if (GUILayout.Button("rename"))
{
RenameActiveScene();
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment