- Home /
Swap ScriptableObject List Components
Hello, I am attempting to write an editor script that will allow me to swap the list order of components to move them up and down.
The code I use to do this is
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
internal static class ExtensionMethods
{
public static void Swap<T>(this IList<T> list, int indexA, int indexB)
{
T tmp = list[indexA];
list[indexA] = list[indexB];
list[indexB] = tmp;
}
}
So when I attempt to call this on any other list type (such as int, GameObject, Collider, etc.) I write
listName.Swap(i, i + 1);
and it works. However, with a list of Scriptable Objects I get the following error message...
error CS1061: Type System.Collections.Generic.List' does not contain a definition for
Swap' and no extension method Swap' of type
System.Collections.Generic.List' could be found (are you missing a using directive or an assembly reference?)
I've tried swapping out IList for List, I tried replacing the T with the ScriptableObject type none of that worked...
Any advice on what needs to be done to make this work on ScriptableObject lists??
Your answer
