Here's a link to an example of what I'm asking about
http://www.anbsoft.com/middleware/ezs/overview/
At around 2:50 it shows a list of variables each with a toggle button. I am wanting to know how you would create the boolean for each of those variables and save them. What I'm trying to do is recreate what EZ Game Saver does since I don't have $99 to just throw on it and I'd want it to be my own anyways.
SaveMe.cs
Make a GameObject and put this script on it
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class SaveMe : MonoBehaviour {
public Component[] components;
}
SaveMeEditor.cs
Make a folder in the main Assets folder named Editor and put this script in it
using UnityEngine;
using UnityEditor;
using System;
using System.Reflection;
[CustomEditor(typeof(SaveMe))]
public class SaveMeEditor : Editor {
public SaveMe saveMe;
void Awake() {
saveMe = target as SaveMe;
}
public override void OnInspectorGUI() {
saveMe.components = saveMe.GetComponents(typeof(Component));
int i = 0;
foreach(Component a in saveMe.components) {
Type type = a.GetType();
if(saveMe.components.Length > 0) {
GUI.color = Color.Lerp(new Color(.2f, 1, .2f), Color.white, (float)i / saveMe.components.Length);
}
GUILayout.Button(type.Name);
GUI.color = Color.white;
if(!(a == saveMe)) {
foreach(PropertyInfo p in type.GetProperties(BindingFlags.Public | BindingFlags.Instance)) {
if(IsSaveable(p.PropertyType)) {
GUILayout.BeginHorizontal();
GUILayout.BeginHorizontal();
EditorGUILayout.Toggle(false, GUILayout.ExpandWidth(false), GUILayout.MaxWidth(20));
GUILayout.Label("." + p.Name, GUILayout.ExpandWidth(false));
GUILayout.EndHorizontal();
GUILayout.Label(p.PropertyType.Name, GUILayout.ExpandWidth(false));
GUILayout.EndHorizontal();
}
}
}
i++;
}
}
bool IsSaveable(object variable) {
object a = variable;
return
a == typeof(bool)
|
a == typeof(int)
|
a == typeof(float)
|
a == typeof(double)
|
a == typeof(string)
|
a == typeof(Vector3)
|
a == typeof(Quaternion)
;
}
}
What you will see when you go back to the GameObject with the SaveMe script on it, you should see at least one button named Transform and a few variables listed. On the left side is a toggle button. The toggle button is what I need the booleans for. If the boolean is True then I want to be able to save that variable. If someone can give me some ideas of how I could do that I'd appreciate it.
asked
Apr 03 '11 at 12:15 AM
GibTreaty
199
●
2
●
4
●
6