- Home /
Question by
mamuelSraz · Jul 29, 2020 at 01:50 PM ·
c#custom editorcustomeditor
Custom editor is activating on all scripts when i press the button on one object
I have a button in the editor witch updates the texture of a plane. The problem is when i update the texture on one plane, all planes are updated and with values from the selected plane. How can i make the customEditor run only on one script at a time?
here is the texture generating code:
[Header("INTERNAL")]
public MapDisplay display;
public int mapDimensions;
public float noiseScale;
public bool autoUpdate;
public float xPos;
public float yPos;
public float[,] noisemap;
[Header("EXTERNAL")]
public MapGenerator left;
public void GenerateMap(){
noisemap = Noise.GenerateNoiseMap(mapDimensions, noiseScale, xPos, yPos);
display.DrawNoiseMap(noisemap);
}
public void GetNeighbourMap(MapGenerator neighbour){
float[,] neighbourNoiseMap = Noise.GenerateNoiseMap(mapDimensions, noiseScale, neighbour.xPos + mapDimensions, neighbour.yPos + mapDimensions);
display.DrawNoiseMap(neighbourNoiseMap);
}
here is the custom editor code:
[CustomEditor(typeof(MapGenerator))]
public class MapGeneratorEditor : Editor
{
public override void OnInspectorGUI()
{
MapGenerator mapGen = (MapGenerator)target;
if (DrawDefaultInspector() && mapGen.autoUpdate) mapGen.GenerateMap();
if (GUILayout.Button("Generate")) mapGen.GenerateMap();
}
}
Comment
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Making a bubble level (not a game but work tool) 1 Answer
PropertyDrawer, Change property within callback 2 Answers
Override Transform Inspector for specific GameObjects 1 Answer