So I’m making a custom inspector so that if I mark a boolean as true inside a list of a subclass, the other variables inside it are hidden. But if it is unchecked, they appear. I’ve found an answer for this but it only applies to a boolean outside of a class. It’s a hard problem to explain, but I think these pictures will help.
This first picture below shows how it should be if all the boxes are checked, there should be no other fields.
This second image is the closest I got to solving my problem, but notice how each variable is chucked at the bottom of the inspector. I want it so that if the Dialogue Trigger box in Element 0 is unchecked, you see the Function GameObject, Function Name, and Delay under Element 0, not at the bottom of the script. Essentially, I want these fields I initialized in the custom inspector to be children of their respective elements in FunctionDatas, not direct children of the StoryManager.
Here is the story manager code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
//Controls order in which scripts are called
public class StoryManager : MonoBehaviour
{
//Creates instance of Dialogue Manager, allows it to be get from anywhere but only set in the class. Part of singleton instantiation
public static StoryManager Instance { get; private set; }
//Destroys duplicate GOs and preserves this one throughout scenes, part of singleton instantiation.
private void Awake()
{
if (Instance == null)
{
Instance = this;
DontDestroyOnLoad(gameObject);
}
else
{
Destroy(gameObject);
}
}
//Calls the Story Coroutine on start
private void Start()
{
StartCoroutine(RunDay(days.TakeOff));
}
/*
Functions for each day, so that precise timing can be preserved.
*/
//The dialogue and delays for each day
[System.Serializable]
public class DialogueWDelay
{
public Dialogue dialogue;
public int delaySecs;
}
//A class to keep necessary data on each function (So it can be called) and how long after the last function it will occur.
[System.Serializable]
public class FunctionData
{
[HideInInspector]
public GameObject FuncGO;
[HideInInspector]
public string FuncName;
[HideInInspector]
public float delay;
public bool DialogueTrigger;
}
//Stores all availible information on the day, drawn from to determine what happens that day and what order it happens in.
[System.Serializable]
public class DayData
{
//The day
public int day;
//Functions to run on each day
public FunctionData[] functionDatas;
//The dialogues
public DialogueWDelay[] dialogue;
}
//Stores all the days in the project
[System.Serializable]
public struct Days
{
public DayData TakeOff;
public DayData Attack;
}
//Defines a "day" struct (in hierarchy)
public Days days;
//Coroutine to run a day
IEnumerator RunDay(DayData thisDay)
{
/*
* Dialogue # keeps track of which dialogue is going on. Dialogue changes everytime dialogue switches to another character.
* Example: Joe: "Hey Guys" Dialogue# = 0
* Joe: "What's up?" Dialogue# = 0
* Jared: "The sky." Dialogue# = 1
* Joe: "Haha, super funny Jared." Dialogue# = 2
*/
int DialogueNumber = 0;
//Calls DayManager to change day, waits until it does so to do anything.
yield return StartCoroutine(DayManager.Instance.ChangeDay(thisDay.day));
//Foreach function in functiondata...
foreach (FunctionData fData in thisDay.functionDatas)
{
//If statement to distinguish between dialogue and non-dialogue (called in different ways)
if (fData.DialogueTrigger == true)
{
//Calls dialogue, gives a delay between next dialogue if necessary.
yield return StartCoroutine(DialogueManager.Instance.StartDialogueWDelay(thisDay.dialogue[DialogueNumber].dialogue, thisDay.dialogue[DialogueNumber].delaySecs));
//Increments DialogueNumber when a character finishes talking
DialogueNumber++;
}
else
{
//Call the function...
fData.FuncGO.SendMessage(fData.FuncName);
//And wait for a bit until you call the next one.
yield return new WaitForSecondsRealtime(fData.delay);
}
}
}
}
Here is the editor code:
[CustomEditor(typeof(StoryManager), true)]
public class StoryManagerEditor : Editor
{
public override void OnInspectorGUI()
{
base.OnInspectorGUI();
var storyManager = (StoryManager)target;
for (var i = 0; i < storyManager.days.TakeOff.functionDatas.Length; i++)
{
if (storyManager.days.TakeOff.functionDatas*.DialogueTrigger == false)*
{
storyManager.days.TakeOff.functionDatas_.FuncGO = (GameObject)EditorGUILayout.ObjectField(“Function GameObject:”, storyManager.days.TakeOff.functionDatas*.FuncGO, typeof(GameObject), true);
storyManager.days.TakeOff.functionDatas.FuncName = EditorGUILayout.TextField(“Function Name:”, storyManager.days.TakeOff.functionDatas.FuncName);
storyManager.days.TakeOff.functionDatas.delay = EditorGUILayout.FloatField("Delay: ", storyManager.days.TakeOff.functionDatas.delay);
}
}
}
}*
Any help would be much appreciated, I’ve been stuck on this for hours! Thank you!_