I have been trying to create a custom editor extension for my inventory system, however I have encountered a problem. I need to cycle through an array/list and display buttons and boxes in the editor GUI. However when I try to access a value in the array it gives be an error: “Assets/Editor/Inventory_Editor.js(51,55): BCE0048: Type ‘UnityEditor.SerializedProperty’ does not support slicing.”. I have looked all over the internet but had no luck finding any solution that worked. Could somebody help me please?
Here is my code:
#pragma strict
//import System.Collections.Generic;
@CustomEditor (Inventory)
@CanEditMultipleObjects
class Inventory_Editor extends Editor {
var scrollPos : Vector2;
var InventoryAreasProp : SerializedProperty;
function OnEnable (){
InventoryAreasProp = serializedObject.FindProperty(“inventoryAreas”);
if (!InventoryAreasProp){
Debug.LogError(“Could not find messages property”);
}else{
Debug.Log(“Found property” );
}
}
function OnInspectorGUI (){
serializedObject.Update ();
for (var a; a < InventoryAreasProp.Length - 1; a++){
GUILayout.Box (“” + InventoryAreasProp[a].invName);
}
serializedObject.ApplyModifiedProperties ();
}
}
Inventory script:
#pragma strict
import System.Collections.Generic;
var showInventory : boolean;
var inventoryAreas : InventoryArea[ ];
var myList : List.;
private var windowRect : Rect;
var defaultTexture : Texture;
function Start () {
}
function Update () {
}
function OnGUI (){
if (showInventory){
windowRect = GUI.Window (0, Rect (50, 50, Screen.width - 100, Screen.height - 100), InventoryWindow, “My Window”);
}
}
function InventoryWindow (windowID : int) {
for(var a = 0; a < inventoryAreas[0].invSpots.Length; a++){
var rect = Rect(25 + 75 * inventoryAreas[0].invSpots[a].position.x, 25 + 75 * inventoryAreas[0].invSpots[a].position.y, 75, 75);
GUI.DrawTexture(Rect(25 + 75 * inventoryAreas[0].invSpots[a].position.x, 25 + 75 * inventoryAreas[0].invSpots[a].position.y, 75, 75), inventoryAreas[0].invSpots[a].texture, ScaleMode.ScaleAndCrop, true);
if(rect.Contains(Event.current.mousePosition)){
if(Input.GetButtonDown(“Fire1”)){
Debug.Log (“Clicked”);
}
if(Input.GetButtonUp(“Fire1”)){
}
}
}
}
public class InventoryArea {
var invName : String;
var invSpots : InvSpot[ ];
}
public class InvSpot{
var occupied : boolean;
var position : Vector2;
var texture : Texture;
var item : GameObject;
}