Hi,
I wanted to make a cursor system for unity and made this script to extend the editor of a ScriptabeObject. It should preview the frames of the animated cursor by looping through the array where they are stored. (the array is contained in the ScriptableObject) Now here’s my problem: I’d like to use coroutines for timing & looping through the array, but the StartCoroutine() method doesn’t seem to be available in Editor derrived scripts. Is there sth. i am missing? Or do they just don’t work in Editor scripts?
using System.Collections;
using UnityEditor;
using UnityEngine;
[CustomEditor(typeof(CursorObject))]
public class CursorEditorPreview : Editor
{
CursorObject cursorObject;
int currentFrame = 0;
void OnEnable()
{
cursorObject = target as CursorObject;
}
public override void OnInspectorGUI()
{
base.OnInspectorGUI();
if (cursorObject.frames == null)
{
return;
}
StartCoroutine(LoopAniamtion());
}
IEnumerator LoopAniamtion()
{
if(currentFrame == cursorObject.frames.Length - 1)
{
currentFrame = 0;
}
Texture2D texture = AssetPreview.GetAssetPreview(cursorObject.frames[0]);
GUILayout.Label("Preview", GUILayout.Height(80), GUILayout.Width(80));
GUI.DrawTexture(GUILayoutUtility.GetLastRect(), texture);
currentFrame++;
yield return new WaitForSeconds(1 / cursorObject.frameRate);
StartCoroutine(LoopAniamtion());
}
}