Hey guys,
I’ve got a few scripts that manage icons and such on a menu. The issue i have is this one. I want to be able to add and remove the icons in a user-friendly way.
Is it possible to take a few arrays inside of the main GUI script, and edit the properties of those arrays in separate blocks? Something like the following:
Arrays in regular script:
var icon_array : Array;
var name_array : Array;
Look to the custom editor thingy:
Icon 1
icon_texture
icon_name
Icon 2
icon_texture
icon_name
etc...
If this is possible please let me know ![]()
edit mo 21:44 :
I’ve made the classes necessary, but all I need now is a way to access the private variables from a custom editor using getters and setters. The script i’ve got for the apps is this:
using UnityEngine;
using System.Collections;
public class App : MonoBehaviour {
private string app_name = "undifined";
private Texture2D icon;
private Texture2D background;
private bool show = false;
public bool Show {
get { return show; }
set { show = value;}
}
public string Name {
get { return app_name; }
set { app_name = value; }
}
public Texture2D Icon {
get { return icon; }
set { icon = value; }
}
public Texture2D Background {
get { return background; }
set { background = value; }
}
}
Can I somehow use the get and set things in here to make something like this?
#pragma strict
@CustomEditor(GUI_Handler)
@CanEditMultipleObjects
class customEditor extends Editor {
var nameProp : SerializedProperty;
var iconProp : SerializedProperty;
var backgroundProp : SerializedProperty;
var showProp : SerializedProperty;
function OnEnable () {
// Setup the SerializedProperties
nameProp = serializedObject.FindProperty ("app_name");
iconProp = serializedObject.FindProperty ("icon");
backgroundProp = serializedObject.FindProperty ("background");
showProp = serializedObject.FindProperty ("show");
}
function OnInspectorGUI() {
// Update the serializedProperty
serializedObject.Update ();
// Show the custom GUI controls
EditorGUILayout.PropertyField(nameProp,new GUIContent("Name"));
EditorGUILayout.PropertyField(iconProp,new GUIContent("App Icon"));
EditorGUILayout.PropertyField(backgroundProp, new GUIContent("App Background"));
serializedObject.ApplyModifiedProperties ();
}
}
Something like this, but then for each array index on the name array inside the main GUI script, using that same index to cover all variables. Using those variables create a new icon, and set all the textures and such.
Is this possible or not? Please let me know and if you are kind: Leave an example ![]()
If I do it this way, is every single icon grouped in the array as far as properties go?
– LesPaulIf I were you I would try and see if it is what you need. You will get a variable icon with a size 0. The when you provide 1, you get one slot for Texture and icon_name. Give two and you get a second one. And so on. Access each of them with icon[index];
– fafase