I have written Custom Property Drawer but it does not seem to tell the GUI when to end and it also overlaps with other other objects!
This is when params size of Wave Params is 1
When I increase this size , I get,
Even if I add another Component here, there is overlapping.
This is the Custom Property Drawer class
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
[CustomPropertyDrawer(typeof(WaveParameters))]
public class WaveParamPropertyDrawer : PropertyDrawer {
SerializedProperty startWait, spawnNextWhen, nextAfterTime, inbetweenWait, prefab, movementMode, bezierPath, positions, count;
static int numOfParams = 0;
float rows = 0;
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label){
/*numOfParams++;
if(numOfParams ==1)
position.y += 10f;
else if(numOfParams>1)
position.y+=numOfParams*60f;*/
float positionAdjustment = 1.5f;
EditorGUI.BeginProperty(position,label, property);
startWait = property.FindPropertyRelative ("startWait");
spawnNextWhen = property.FindPropertyRelative ("spawnNextWhen");
nextAfterTime = property.FindPropertyRelative ("nextAfterTime");
inbetweenWait = property.FindPropertyRelative ("inbetweenWait");
prefab = property.FindPropertyRelative ("prefab");
movementMode = property.FindPropertyRelative ("movementMode");
positions = property.FindPropertyRelative ("positions");
count = property.FindPropertyRelative ("count");
bezierPath = property.FindPropertyRelative ("bezierPath");
EditorGUI.indentLevel++;
EditorGUI.PropertyField (new Rect (position.x, position.y, position.width, position.height / 4.0f), startWait, new GUIContent("Start Delay"));
EditorGUI.PropertyField (new Rect (position.x, position.y + (position.height/4f)*positionAdjustment, position.width, position.height / 2.0f), spawnNextWhen, new GUIContent("Spawn Next When"));
positionAdjustment += 1.5f;
if (spawnNextWhen.enumValueIndex == 3) { // Checks if spawnNextWhen == SpawnNextWhen.AfterTime
EditorGUI.PropertyField (new Rect (position.x, position.y + (position.height / 4f) * positionAdjustment, position.width, position.height / 4.0f), nextAfterTime, new GUIContent ("Next After Time"));
positionAdjustment += 1.5f;
}
EditorGUI.PropertyField (new Rect (position.x, position.y + (position.height/4f)*positionAdjustment, position.width, position.height / 4.0f), inbetweenWait, new GUIContent("In Between Wait"));
positionAdjustment += 1.5f;
EditorGUI.PropertyField (new Rect (position.x, position.y + (position.height/4f)*positionAdjustment, position.width, position.height / 4.0f), prefab, new GUIContent("Prefab"));
positionAdjustment += 1.5f;
EditorGUI.PropertyField (new Rect (position.x, position.y + (position.height/4f)*positionAdjustment, position.width, position.height / 4.0f), movementMode, new GUIContent("Movement Mode"));
positionAdjustment += 1.5f;
if (movementMode.enumValueIndex == 1) {// checks if movementMode == MovementMode.BezeirPath
EditorGUI.PropertyField (new Rect (position.x, position.y + (position.height / 4f) * positionAdjustment, position.width, position.height / 4.0f), bezierPath, new GUIContent ("Bezier Path"));
positionAdjustment += 1.5f;
}
EditorGUI.PropertyField (new Rect (position.x, position.y + (position.height/4f)*positionAdjustment, position.width, position.height / 4.0f), count, new GUIContent("Count"));
positionAdjustment += 1.5f;
if (count.intValue > 0) {
EditorGUI.PropertyField (new Rect (position.x, position.y + (position.height / 4f) * positionAdjustment, position.width, position.height / 4.0f), positions, new GUIContent ("Positions"));
positionAdjustment += 1.5f;
}
EditorGUI.DrawRect(new Rect(position.x, position.y + (position.height/4f)*positionAdjustment, position.width, position.height/8f), Color.black);
positionAdjustment += 1.5f;
position.y = position.y + 100f;
EditorGUI.indentLevel++;
EditorGUI.EndProperty();
Debug.Log (position);
}
public override float GetPropertyHeight(SerializedProperty property, GUIContent label){
return base.GetPropertyHeight (property, label) *4f;
}
}
Here is the WaveParameters class
[Serializable]
public class WaveParameters {
public float startWait = 0;
public SpawnNextWhen spawnNextWhen = SpawnNextWhen.AllSpawned;
public float nextAfterTime = 0;
public float inbetweenWait = 0.2f;
public GameObject prefab;
public MovementMode movementMode = MovementMode.BezierPath;
public BezierSpline bezierPath;
public int count;
public Vector2[] positions;
}
public enum MovementMode
{
NoMovement,
BezierPath,
}
public enum SpawnNextWhen
{
AllSpawned,
Started,
AllDestroyed,
AfterTime,
}
And this is where WaveParameters are used in the Wave class
public class Waves : MonoBehaviour
{
public bool debug_SpawnNext = false;
[SerializeField]
WaveParameters[] _waveParams;
int _currentWaveIndex;
IEnumerator _spawnWaveCoroutine;//just holds the last spawning coroutine called,
//there might be more than one routine running at the same time
//so don't expect to stop all routines by stopping this one
//Convert this to a list of IEnumerators for that functionality
int _enemiesToMonitor;//will hold the total amount of enemies we spawned and will be used
//if the next wave has to spawn after all the enemies are dead
.
.
.
.
}
Anyone knows how to fix this? Thanks!