- Home /
Changes to Object made in custom Editor Window don't persist
I am working on an editor that will be used to build the world of a game. The editor as of now manages in the inspector lists of cell types that will be used as building blocks for the world.
Each cell has its own set of information that will be adjusted using an editor window that is accessed by clicking on the button with the plus sign image.
The problem is, the information that is adjusted using the movement settings keeps resetting itself to whatever the default was each time the editor window is closed. The information that is adjusted using the grid of hexagons does persist when changes are made.
The inspector creates the editor window using the following code
// Menu for altering the information of a cell
void AdvOptMenu(CellData cell)
{
// Begin Change Check
EditorGUI.BeginChangeCheck();
Debug.Log("Change standard cell");
advOptWindow = (CellDataWindow)EditorWindow.GetWindow(typeof(CellDataWindow), true, "Cell Data");
advOptWindow.info = cell;
advOptWindow.curType = curList;
advOptWindow.Show(true);
}
The class CellData holds its information in three objects. One if of class type OverworldMvmt and the other two of class type HexRect.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[System.Serializable]
public class CellData
{
// Arena map info for the cell
// TODO: need to test for the "optimal" size
public HexRect encounterMapUD;
public HexRect encounterMapLR;
// Movement options for oveworld cell
public OverworldMvmt mvmt;
// The path for the cell model
[SerializeField]
private string path;
// The model for the 3D object
[SerializeField]
private GameObject model;
// Constructor
public CellData(int type)
{
model = null;
path = "";
encounterMapUD = new HexRect(GlobalVals.ENC_MAP_RAD);
encounterMapLR = new HexRect(GlobalVals.ENC_MAP_RAD);
int cellsPerCol = GlobalVals.ENC_MAP_HPC;
int cols = GlobalVals.ENC_MAP_COL;
int r, c;
switch (type)
{
// Default floor
case 0:
mvmt = new OverworldMvmt(15, 0);
for (int i = 0; i < (cellsPerCol * cols); i++)
{
r = i / cols;
c = i - (r * cols);
encounterMapUD[r, c] = new EnctrCell(0);
encounterMapLR[r, c] = new EnctrCell(0);
}
break;
// Default wall
case 1:
mvmt = new OverworldMvmt(0, 0);
for (int i = 0; i < (cellsPerCol * cols); i++)
{
r = i / cols;
c = i - (r * cols);
encounterMapUD[r, c] = new EnctrCell(0);
encounterMapLR[r, c] = new EnctrCell(0);
}
break;
// Default platform
case 2:
mvmt = new OverworldMvmt(0, 15);
for (int i = 0; i < (cellsPerCol * cols); i++)
{
r = i / cols;
c = i - (r * cols);
// Borders
if (r == 0 || r == (cellsPerCol - 1) || c == 0 || c == (cols - 1))
{
encounterMapUD[r, c] = new EnctrCell(0);
encounterMapLR[r, c] = new EnctrCell(0);
}
// Center
else
{
encounterMapUD[r, c] = new EnctrCell(GlobalVals.ENC_MAP_MX_HT);
encounterMapLR[r, c] = new EnctrCell(GlobalVals.ENC_MAP_MX_HT);
}
}
break;
// Default ramp
case 3:
mvmt = new OverworldMvmt(15, 15);
for (int i = 0; i < (cellsPerCol * cols); i++)
{
r = i / cols;
c = i - (r * cols);
// Up-Down orientation
encounterMapUD[r, c] = new EnctrCell(GlobalVals.ENC_MAP_HPC - r);
// Left-Right orientation
encounterMapLR[r, c] = new EnctrCell(c);
}
break;
default:
mvmt = new OverworldMvmt(0, 0);
for (int i = 0; i < (cellsPerCol * cols); i++)
{
r = i / cols;
c = i - (r * cols);
encounterMapUD[r, c] = null;
encounterMapLR[r, c] = null;
}
break;
}
}
// Copy constructor
public CellData(CellData toCopy)
{
path = toCopy.path;
model = toCopy.model;
mvmt = new OverworldMvmt(toCopy.mvmt);
encounterMapUD = new HexRect(toCopy.encounterMapUD);
encounterMapLR = new HexRect(toCopy.encounterMapLR);
}
}
The OverworldMvmt class object holds two integers. These integers are adjusted using the movement settings menu in the editor window.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public enum MVMT
{
TOP = 3,
LFT = 2,
BOT = 1,
RGT = 0
}
[System.Serializable]
public class OverworldMvmt
{
// Movement options are coded in 4 bits
// 1, you can move in that direction
// 0, you can't move in that direction
// bit 3: up movement
// bit 2: left movement
// bit 1: down movement
// bit 0: right movement
// Movement options for the 'ground' layer
[SerializeField]
private int mvLyr1;
// Movemnet options for the next layer up
[SerializeField]
private int mvLyr2;
public OverworldMvmt(int ml1 = 0, int ml2 = 0)
{
mvLyr1 = ml1;
mvLyr2 = ml2;
}
// Copy Consructor
public OverworldMvmt(OverworldMvmt toCopy)
{
mvLyr1 = toCopy.mvLyr1;
mvLyr2 = toCopy.mvLyr2;
}
// Accessor
public bool this[bool lyr, MVMT dir]
{
get
{
switch (dir)
{
case MVMT.TOP:
return CanMvTop(lyr);
case MVMT.LFT:
return CanMvLeft(lyr);
case MVMT.BOT:
return CanMvBot(lyr);
case MVMT.RGT:
return CanMvRight(lyr);
default:
return false;
}
}
set
{
switch (dir)
{
case MVMT.TOP:
SetTop(value, lyr);
break;
case MVMT.LFT:
SetLeft(value, lyr);
break;
case MVMT.BOT:
SetBot(value, lyr);
break;
case MVMT.RGT:
SetRight(value, lyr);
break;
default:
break;
}
}
}
// Helper function used to set movement options
private void MvSet(int mvMask, int stpMask, bool mv, bool lyr)
{
if (lyr) // layer 2
{
mvLyr2 = mv ? (mvMask | mvLyr2) : (stpMask & mvLyr2);
}
else // layer 1
{
mvLyr1 = mv ? (mvMask | mvLyr1) : (stpMask & mvLyr1);
}
}
// Helper function used to check movement options
private bool MvCheck(int mask, bool lyr)
{
if (lyr) // layer 2
{
if ((mvLyr2 & mask) == 0)
{
return false;
}
}
else // layer 1
{
if ((mvLyr1 & mask) == 0)
{
return false;
}
}
return true;
}
// Set bit 3 of mvLyr lyr to value of mv
// 0 is layer 1
// 1 is layer 2
private void SetTop(bool mv, bool lyr)
{
int mvMask = 8; // 1000
int stpMask = 7; // 0111
MvSet(mvMask, stpMask, mv, lyr);
}
// Set bit 2 of mvLyr lyr to value of mv
// 0 is layer 1
// 1 is layer 2
private void SetLeft(bool mv, bool lyr)
{
int mvMask = 4; // 0100
int stpMask = 11; // 1011
MvSet(mvMask, stpMask, mv, lyr);
}
// Set bit 1 of mvLyr lyr to value of mv
// 0 is layer 1
// 1 is layer 2
private void SetBot(bool mv, bool lyr)
{
int mvMask = 2; // 0010
int stpMask = 13; // 1101
MvSet(mvMask, stpMask, mv, lyr);
}
// Set bit 0 of mvLyr lyr to value of mv
// 0 is layer 1
// 1 is layer 2
private void SetRight(bool mv, bool lyr)
{
int mvMask = 1; // 0001
int stpMask = 14; // 1110
MvSet(mvMask, stpMask, mv, lyr);
}
// Return if you can move up from the cell
// 0 is layer 1
// 1 is layer 2
private bool CanMvTop(bool lyr)
{
int mask = 8; // 1000
return MvCheck(mask, lyr);
}
// Return if you can move left from the cell
// 0 is layer 1
// 1 is layer 2
private bool CanMvLeft(bool lyr)
{
int mask = 4; // 0100
return MvCheck(mask, lyr);
}
// Return if you can move down from the cell
// 0 is layer 1
// 1 is layer 2
private bool CanMvBot(bool lyr)
{
int mask = 2; // 0010
return MvCheck(mask, lyr);
}
// Return if you can move right from the cell
// 0 is layer 1
// 1 is layer 2
private bool CanMvRight(bool lyr)
{
int mask = 1; // 0001
return MvCheck(mask, lyr);
}
// true is lyr 2
// false is lyr 1
public int GetMv(bool lyr)
{
if (lyr)
{
return mvLyr2;
}
else
{
return mvLyr1;
}
}
}
The HexRect class objects hold an array of objects of the class type EnctrCell. The class EnctrCell currently holds only an integer but will eventually hold more information. The information in the arrays of the HexRect class objects are adjusted by the grid of hexagons in the encounter window.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[System.Serializable]
public class HexRect
{
[SerializeField]
private int cCnt;
[SerializeField]
private int hPc;
[SerializeField]
private int rad;
[SerializeField]
private bool sharpCor;
[SerializeField]
private EnctrCell[] hRect;
// Constructor
public HexRect(int radius = 0)
{
rad = radius;
hPc = 2 * (radius + 1);
cCnt = hPc + 1;
sharpCor = (radius % 2 == 0) ? true : false;
hRect = new EnctrCell[hPc * cCnt];
for (int i = 0; i < (hPc * cCnt); i++)
{
hRect[i] = null;
}
}
// Copy Constructor
public HexRect(HexRect toCopy)
{
cCnt = toCopy.cCnt;
hPc = toCopy.hPc;
sharpCor = toCopy.sharpCor;
hRect = new EnctrCell[hPc * cCnt];
for (int i = 0; i < (hPc * cCnt); i++)
{
hRect[i] = toCopy.hRect[i];
}
}
// Index Operator
public EnctrCell this[int rowKey, int colKey]
{
get
{
if (sharpCor && (colKey % 2 != 0) && (rowKey == (hPc - 1)))
{
return null;
}
else if (!sharpCor && (colKey % 2 == 0) && (rowKey == 0))
{
return null;
}
else
{
return hRect[(rowKey * cCnt) + colKey];
}
}
set
{
if (sharpCor && (colKey % 2 != 0) && (rowKey == (hPc - 1)))
{
hRect[(rowKey * cCnt) + colKey] = new EnctrCell();
}
else if (!sharpCor && (colKey % 2 == 0) && (rowKey == 0))
{
hRect[(rowKey * cCnt) + colKey] = new EnctrCell();
}
else
{
hRect[(rowKey * cCnt) + colKey] = value;
}
}
}
// Get row count
public int HexPerCol()
{
return hPc;
}
// Get column count
public int ColCnt()
{
return cCnt;
}
// Is corner sharp
public bool SharpCor()
{
return sharpCor;
}
// Make a HexRect with trimmed corners
// Argument is true if corner is to be trimmed
public HexRect TrimCorners(bool TL = false, bool TR = false, bool BL = false, bool BR = false)
{
HexRect hRectTrim = new HexRect(this);
// dimensions for corner rectangle
int tCorRowCnt;
int bCorRowCnt;
int corColCnt;
if (rad == 0)
{
// trim top-left corner
if (TL)
{
hRectTrim[0, 0] = new EnctrCell();
}
// trim top-right corner
if (TR)
{
hRectTrim[0, (cCnt - 1)] = new EnctrCell();
}
// trim bottom-left corner
if (BL)
{
hRectTrim[(hPc - 1), 0] = new EnctrCell();
}
// trim bottom-right corner
if (BR)
{
hRectTrim[(hPc - 1), (cCnt - 1)] = new EnctrCell();
}
}
else if (rad == 1)
{
// trim top-left corner
if (TL)
{
hRectTrim[0, 1] = new EnctrCell();
hRectTrim[1, 0] = new EnctrCell();
}
// trim top-right corner
if (TR)
{
hRectTrim[0, (cCnt - 2)] = new EnctrCell();
hRectTrim[1, (cCnt - 1)] = new EnctrCell();
}
// trim bottom-left corner
if (BL)
{
hRectTrim[(hPc - 1), 0] = new EnctrCell();
hRectTrim[(hPc - 1), 1] = new EnctrCell();
}
// trim bottom-right corner
if (BR)
{
hRectTrim[(hPc - 1), (cCnt - 1)] = new EnctrCell();
hRectTrim[(hPc - 1), (cCnt - 2)] = new EnctrCell();
}
}
else if(sharpCor)
{
// top and bottom dimensions are the same
tCorRowCnt = rad / 2;
corColCnt = rad - 1;
for (int r = 0; r < tCorRowCnt; r++)
{
for (int c = 0; c < corColCnt; c++)
{
// trim top-left corner
if (TL && (c < corColCnt - (2 * r)))
{
hRectTrim[r, c] = new EnctrCell();
}
// trim top-right corner
if (TR && (c >= 2 * r))
{
hRectTrim[r, c + (cCnt - corColCnt)] = new EnctrCell();
}
// trim bottom-left corner
if (BL && (c < 2 * (r + 1)))
{
hRectTrim[r + (hPc - tCorRowCnt), c] = new EnctrCell();
}
// trim bottom-right corner
if (BR && (c >= (corColCnt - (2 * (r + 1)))))
{
hRectTrim[r + (hPc - tCorRowCnt), c + (cCnt - corColCnt)] = new EnctrCell();
}
}
}
}
else
{
tCorRowCnt = ((rad - 1) / 2) + 1;
bCorRowCnt = (rad - 1) / 2;
corColCnt = rad - 1;
for (int r = 0; r < tCorRowCnt; r++)
{
for (int c = 0; c < corColCnt; c++)
{
// trim top-left corner
if (TL && ((c < corColCnt - (2 * r) + 1) || (c == 0)))
{
hRectTrim[r, c] = new EnctrCell();
}
// trim top-right corner
if (TR && ((c >= (2 * r) - 1) || (c == corColCnt - 1)))
{
hRectTrim[r, c + (cCnt - corColCnt)] = new EnctrCell();
}
if (r < bCorRowCnt)
{
// trim bottom-left corner
if (BL && (c < (r + 1) * 2))
{
hRectTrim[r + (hPc - tCorRowCnt + 1), c] = new EnctrCell();
}
// trim bottom-right corner
if (BR && (c >= corColCnt - ((r + 1) * 2)))
{
hRectTrim[r + (hPc - tCorRowCnt + 1), c + (cCnt - corColCnt)] = new EnctrCell();
}
}
}
}
}
return hRectTrim;
}
}
This is the code the editor window uses for adjusting the various classes.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEditor;
// Window for editing the information of a cell
public class CellDataWindow : EditorWindow
{
public CellData info;
public CELLTYPES curType;
// Sizes and values for movement GUI
private int boxLen = 40;
private int mvButWdth = 25;
private int mvButLen = 40;
private int elemSpacing = 8;
private float LRButScale = 1.3f;
// GUI images
private string mvArrLROn_path = "Assets/Resources/Materials/GUI Images/Movement Arrow On LR.png";
private string mvArrUDOn_path = "Assets/Resources/Materials/GUI Images/Movement Arrow On UD.png";
private string mvArrLROff_path = "Assets/Resources/Materials/GUI Images/Movement Arrow Off LR.png";
private string mvArrUDOff_path = "Assets/Resources/Materials/GUI Images/Movement Arrow Off UD.png";
private string mvReference_path = "Assets/Resources/Materials/GUI Images/Cell Movement Reference.png";
private string htReference_path = "Assets/Resources/Materials/GUI Images/Enc Cell Ht Reference.png";
private string encCell_path = "Assets/Resources/Materials/GUI Images/Encounter Cell.png";
private string encCellSel_path = "Assets/Resources/Materials/GUI Images/Selected Encounter Cell.png";
// Sizes and values for Encounter Map GUI
private GUIStyle encCellNrm_Style;
private GUIStyle encCellSel_Style;
private string encMapOr = "Left - Right";
private bool type = true;
private bool ulTog = false;
private bool blTog = false;
private bool urTog = false;
private bool brTog = false;
private int cellButWdt = 40;
private int curInd = 0;
private void OnGUI()
{
encCellNrm_Style = new GUIStyle
{
alignment = TextAnchor.MiddleCenter,
fixedHeight = cellButWdt,
fixedWidth = cellButWdt,
margin = new RectOffset(2, 2, 2, 2)
};
encCellNrm_Style.normal.background = (Texture2D)AssetDatabase.LoadAssetAtPath(encCell_path, typeof(Texture2D));
encCellSel_Style = new GUIStyle(encCellNrm_Style);
encCellSel_Style.normal.background = (Texture2D)AssetDatabase.LoadAssetAtPath(encCellSel_path, typeof(Texture2D));
//EditorGUILayout.BeginVertical();
EditorGUILayout.BeginHorizontal();
// Movement settings GUI
// This doesn't change movement settings for some reason
MovementGui();
// Where a preview of model should go
// Encounter map GUI
EncounterMapGUI();
EditorGUILayout.EndHorizontal();
//EditorGUILayout.EndVertical();
}
// Interface for editing movement settings of a cell
private void MovementGui()
{
bool butEnableLyr1;
bool butEnableLyr2;
Texture2D mvReference = (Texture2D)AssetDatabase.LoadAssetAtPath(mvReference_path, typeof(Texture2D));
EditorGUILayout.BeginVertical("Box", GUILayout.Width((2 * elemSpacing) + (2 * LRButScale * mvButWdth) + boxLen));
GUILayout.Label("Movement Settings");
switch (curType)
{
case CELLTYPES.FLOOR:
// Layer 2 Cell movement editor
butEnableLyr2 = false;
// Layer 1 Cell movement editor
butEnableLyr1 = true;
break;
case CELLTYPES.WALL:
// Layer 2 Cell movement editor
butEnableLyr2 = false;
// Layer 1 Cell movement editor
butEnableLyr1 = false;
break;
case CELLTYPES.PLATFORM:
// Layer 2 Cell movement editor
butEnableLyr2 = true;
// Layer 1 Cell movement editor
butEnableLyr1 = false;
break;
case CELLTYPES.RAMP:
GUI.enabled = true;
// Layer 2 Cell movement editor
butEnableLyr2 = true;
// Layer 1 Cell movement editor
butEnableLyr1 = true;
break;
default:
GUI.enabled = false;
// Layer 2 Cell movement editor
butEnableLyr2 = false;
// Layer 1 Cell movement editor
butEnableLyr1 = false;
Debug.LogError("Tried to access CellData of special cell");
break;
}
MovementGuiButtons(true, butEnableLyr2);
// Rotation reference image
GUI.enabled = true;
GUILayout.Label(mvReference, GUILayout.Height(100), GUILayout.Width((2 * elemSpacing) + (2 * LRButScale * mvButWdth) + boxLen));
MovementGuiButtons(false, butEnableLyr1);
EditorGUILayout.EndVertical();
}
// Buttons for editing the movement settings of a cell
// true is layer 2
// false is layer 1
private void MovementGuiButtons(bool lyr, bool butEnable)
{
Texture2D mvArrowLR;
Texture2D mvArrowUD;
GUI.enabled = butEnable;
EditorGUILayout.BeginVertical();
// Top button Label
if (info.mvmt[lyr, MVMT.TOP])
{
mvArrowUD = (Texture2D)AssetDatabase.LoadAssetAtPath(mvArrUDOn_path, typeof(Texture2D));
}
else
{
mvArrowUD = (Texture2D)AssetDatabase.LoadAssetAtPath(mvArrUDOff_path, typeof(Texture2D));
}
EditorGUILayout.BeginHorizontal();
// Space used to position button
GUILayout.Space((mvButWdth * LRButScale) + elemSpacing);
// Top button
if (GUILayout.Button(mvArrowUD, GUILayout.Width(mvButLen), GUILayout.Height(mvButWdth)))
{
info.mvmt[lyr, MVMT.TOP] = !info.mvmt[lyr, MVMT.TOP];
}
EditorGUILayout.EndHorizontal();
EditorGUILayout.BeginHorizontal();
// Left button label
if (info.mvmt[lyr, MVMT.LFT])
{
mvArrowLR = (Texture2D)AssetDatabase.LoadAssetAtPath(mvArrLROn_path, typeof(Texture2D));
}
else
{
mvArrowLR = (Texture2D)AssetDatabase.LoadAssetAtPath(mvArrLROff_path, typeof(Texture2D));
}
// Left button
if (GUILayout.Button(mvArrowLR, GUILayout.Width(mvButWdth * LRButScale), GUILayout.Height(mvButLen)))
{
info.mvmt[lyr, MVMT.LFT] = !info.mvmt[lyr, MVMT.LFT];
}
// Layer label
GUI.enabled = true;
if(lyr)
{
GUILayout.Box("Layer 2", GUILayout.Width(boxLen), GUILayout.Height(boxLen));
}
else
{
GUILayout.Box("Layer 1", GUILayout.Width(boxLen), GUILayout.Height(boxLen));
}
GUI.enabled = butEnable;
// Right button label
if (info.mvmt[lyr, MVMT.RGT])
{
mvArrowLR = (Texture2D)AssetDatabase.LoadAssetAtPath(mvArrLROn_path, typeof(Texture2D));
}
else
{
mvArrowLR = (Texture2D)AssetDatabase.LoadAssetAtPath(mvArrLROff_path, typeof(Texture2D));
}
// Right button
if (GUILayout.Button(mvArrowLR, GUILayout.Width(mvButWdth * LRButScale), GUILayout.Height(mvButLen)))
{
info.mvmt[lyr, MVMT.RGT] = !info.mvmt[lyr, MVMT.RGT];
}
EditorGUILayout.EndHorizontal();
// Bot button label
if (info.mvmt[lyr, MVMT.BOT])
{
mvArrowUD = (Texture2D)AssetDatabase.LoadAssetAtPath(mvArrUDOn_path, typeof(Texture2D));
}
else
{
mvArrowUD = (Texture2D)AssetDatabase.LoadAssetAtPath(mvArrUDOff_path, typeof(Texture2D));
}
EditorGUILayout.BeginHorizontal();
// Space used to position button
GUILayout.Space((mvButWdth * LRButScale) + elemSpacing);
// Bot button
if (GUILayout.Button(mvArrowUD, GUILayout.Width(mvButLen), GUILayout.Height(mvButWdth)))
{
info.mvmt[lyr, MVMT.BOT] = !info.mvmt[lyr, MVMT.BOT];
}
EditorGUILayout.EndHorizontal();
EditorGUILayout.EndVertical();
}
// Interface for editing the layout of a cell's encounter map
private void EncounterMapGUI()
{
GUI.enabled = true;
Texture2D htReference = (Texture2D)AssetDatabase.LoadAssetAtPath(htReference_path, typeof(Texture2D));
GUILayout.BeginHorizontal();
// Height color reference image
GUILayout.Label(htReference, GUILayout.Width(htReference.width));
GUILayout.BeginVertical();
// Button to pick orientation
if(GUILayout.Button(encMapOr))
{
type = !type;
encMapOr = type ? "Left - Right" : "Up - Down";
}
// Create menu to alter a cell's properties
if (type)
{
EncounterMapCellProp(info.encounterMapLR);
}
else
{
EncounterMapCellProp(info.encounterMapUD);
}
// Menu to see trimmed corners
EncounterMapTrimMenu();
GUILayout.EndVertical();
// Create selection grid
if (type)
{
EncounterMapSelGrid(info.encounterMapLR, type);
}
else
{
EncounterMapSelGrid(info.encounterMapUD, type);
}
GUILayout.EndHorizontal();
}
// GUI for editing an ecounter cell's properties
private void EncounterMapCellProp(HexRect hexRect)
{
int r = curInd / GlobalVals.ENC_MAP_COL;
int c = curInd - (r * GlobalVals.ENC_MAP_COL);
EditorGUIUtility.labelWidth = 75.0f;
hexRect[r,c].height = EditorGUILayout.IntSlider("Height:", hexRect[r, c].height, 0, GlobalVals.ENC_MAP_MX_HT);
EditorGUIUtility.labelWidth = 0.0f;
}
// Toggle buttons used to see trimmed corners
private void EncounterMapTrimMenu()
{
GUILayout.BeginVertical("Box");
EditorGUILayout.LabelField("Trim Corner Preview");
GUILayout.BeginHorizontal();
EditorGUIUtility.labelWidth = 70.0f;
ulTog = EditorGUILayout.Toggle("Top - Left", ulTog);
urTog = EditorGUILayout.ToggleLeft("Top - Right", urTog);
GUILayout.EndHorizontal();
GUILayout.BeginHorizontal();
blTog = EditorGUILayout.Toggle("Bot - Left", blTog);
brTog = EditorGUILayout.ToggleLeft("Bot - Right", brTog);
EditorGUIUtility.labelWidth = 0.0f;
GUILayout.EndHorizontal();
GUILayout.EndVertical();
}
// Selection grid for an encounter map
// true is Left - Right orientation
// false is Up - Down orientaton
private void EncounterMapSelGrid(HexRect hexRect, bool type)
{
int w = cellButWdt;
float hVal;
GUIStyle gUIStyle;
HexRect trimHexRect = hexRect.TrimCorners(ulTog, urTog, blTog, brTog);
GUILayout.BeginVertical("Box", GUILayout.Width(w * hexRect.ColCnt()));
if (type)
{
GUILayout.Label("Left-Right Orientation");
}
else
{
GUILayout.Label("Up-Down Orientation");
}
GUILayout.BeginHorizontal(GUILayout.ExpandWidth(false));
for (int c = 0; c < trimHexRect.ColCnt(); c++)
{
GUILayout.BeginVertical();
for (int r = 0; r < trimHexRect.HexPerCol(); r++)
{
// Format layout of encounter cells GUI
if (trimHexRect.SharpCor())
{
if ((r == 0) && (c % 2 != 0))
{
GUILayout.Space(w / 2);
}
}
else
{
if ((r == 0) && (c % 2 == 0))
{
GUILayout.Space(w / 2);
}
}
// Display the encounter cells GUI
if (trimHexRect[r,c] != null)
{
// "Trim" the encounter cell
if (trimHexRect[r,c].height < 0)
{
GUI.color = Color.blue;
GUI.enabled = false;
GUILayout.Box("", encCellNrm_Style);
GUI.enabled = true;
}
// Create button to interact with encounter cell
else
{
hVal = (trimHexRect[r, c].height / (float)GlobalVals.ENC_MAP_MX_HT) * 0.33f;
GUI.color = Color.HSVToRGB(hVal, 1.0f, 1.0f);
// Set style for button
gUIStyle = (curInd == ((r * GlobalVals.ENC_MAP_COL) + c)) ? encCellSel_Style : encCellNrm_Style;
if (GUILayout.Button(trimHexRect[r, c].height.ToString(), gUIStyle))
{
curInd = (r * GlobalVals.ENC_MAP_COL) + c;
}
}
}
}
GUI.color = Color.white;
GUILayout.EndVertical();
}
GUILayout.EndHorizontal();
GUILayout.EndVertical();
}
}
Again, the problem I am having is that the editor window is able to adjust the settings of all three objects, but any adjustments made to the OverworldMvmt object are not preserved whenever the window is closed.
I found a post that is trying to find an answer to a similar problem I am having, communicating between a custom editor and an editor window. link text
Your answer
Follow this Question
Related Questions
why I Cant Add Multiple Objects to the "Object Field" in Editor Window? 3 Answers
How do I make a progress bar in the editor lock the background? 0 Answers
Editor window script only works when window is open? 1 Answer
Weird bug when dragging object onto EditorGUILayout.ObjectField 0 Answers
Custom scene view in editor window 2 Answers