I am attempting to create my first custom editor in unity. This is a script called PlayerEditor.cs
.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
[CustomEditor(typeof(Player))]
public class PlayerEditor : Editor
{
public override void OnInspectorGUI()
{
}
}
When I open the script in Visual Studio, it gives an error of "The type or namespace name ‘Player’ could not be found. This is what Visual Studio’s Solution Explorer looks like.
As you can see, it loads as two projects. The PlayerEditor
script is in the folder Project/SpaceShooter/Assets/Editor
. The actual folder structure is correct, but VS Solutions thinks they are two projects. If I manually drag the Editor folder to the Assets folder in the VS Solution explorer like so,
the error resolves. Player is now found in the namespace. I can create custom controls and it works fine. The only problem here was Visual Studio thinking the scopes were different. The actual folder structure has not changed at all. This would be the end of my troubles, but every time I reload, and sometimes just randomly, VS removes the Editor folder from the first project.
So far I have tried deleting all the CSProj files and all the SLN files and reloading. Visual Studio rebuilds on opening again but does the same thing. I’ve tried moving the Editor folder to different locations like my script folder. This doesn’t work either.
How does VS determine what cs files belong to which projects? Can I tell VS that the folder Editor and its contents are meant to be in the same project as everything else? Does anyone else have this problem?
TIA.