Quantcast
Viewing all articles
Browse latest Browse all 97

Null Reference from Custom Editor

So Ive been getting null errors on the SoundObj In the DropAreaGUI function in the SoundInspector Class. Im unsure what im doing wrong, but even if i try and play it all the data gets wiped away and im really confused what Im doing wrong. please help. //SoundManager using UnityEngine; using System.Collections; using System.Collections.Generic; [System.Serializable] public class SoundManager : MonoBehaviour { [SerializeField] public List list; public void Start() { list = new List(); } } //SoundObj using UnityEngine; using System.Collections; using FMOD.Studio; [System.Serializable] public class SoundObj : MonoBehaviour { //Nothing in here right now } //SoundInspector using UnityEngine; using System.Collections; using System.Collections.Generic; using UnityEditor; [CanEditMultipleObjects] [CustomEditor(typeof(SoundManager))] public class SoundInspector : Editor { private SerializedObject obj; public List list; public SoundManager TargetObject; public List objFold; public void OnEnable() { obj = new SerializedObject(target); TargetObject = target as SoundManager; list = TargetObject.list; objFold = new List(); if(list!=null){ for (int n = 0; n < list.Count; n++) objFold.Add(true); } } private void RemovePoolAtIndex(int index) { for (int n = index; n < list.Count - 1; n++) list[n] = list[n + 1]; list.RemoveAt(list.Count - 1); } public void DropAreaGUI() { Event evt = Event.current; Rect drop_area = GUILayoutUtility.GetRect(0.0f, 50.0f, GUILayout.ExpandWidth(true)); GUI.Box(drop_area, "Add FMODASSET Into Box"); switch (evt.type) { case EventType.DragUpdated: case EventType.DragPerform: if (!drop_area.Contains(evt.mousePosition)) return; DragAndDrop.visualMode = DragAndDropVisualMode.Copy; if (evt.type == EventType.DragPerform) { DragAndDrop.AcceptDrag(); foreach (Object dragged_object in DragAndDrop.objectReferences) { FMODAsset asset = dragged_object as FMODAsset; if (asset == null) { continue; } SoundObj obj = new SoundObj(); list.Add(new SoundObj()); } } Event.current.Use(); break; } } }

Viewing all articles
Browse latest Browse all 97

Trending Articles