static public string GetCreateNewAssetFromSelectionFilename(string filenameSample) { var outpath = GKEditor.GetAssetDirectoryFromSelection(); var name = System.IO.Path.GetFileNameWithoutExtension(filenameSample); var ext = System.IO.Path.GetExtension(filenameSample); int i = 0; string filename; for (; ;) { filename = outpath + "/" + name; if (i > 0) { filename += " " + i.ToString(); } filename += ext; if (!System.IO.File.Exists(filename)) { return(filename); } i++; } }
static public void PropertyDrawerArrayElementPopup(Rect rect, SerializedProperty prop, string label, float width) { float w = width; var rc = rect; rc.width -= w; EditorGUI.LabelField(rc, label); var arr = GKEditor.GetArrayPropFromElementProp(prop); var idx = GKEditor.GetArrayElementPropIndex(prop); rc.x = rect.xMax - rect.x - w; rc.width = w; var sel = EditorGUI.Popup(rc, -1, PropertyDrawerArrayElementPopupOptions); if (arr != null) { switch (sel) { case 0: arr.MoveArrayElement(idx, idx - 1); break; case 1: arr.MoveArrayElement(idx, idx + 1); break; case 2: arr.InsertArrayElementAtIndex(idx); break; case 3: arr.DeleteArrayElementAtIndex(idx); break; } } }
static public bool CreateNewScriptableObjectInAssets <T>() where T : ScriptableObject { var t = typeof(T); var filename = GetCreateNewAssetFromSelectionFilename(t.Name + ".asset"); var obj = ScriptableObject.CreateInstance <T>(); GKEditor.CreateAsset(obj, filename); Selection.activeObject = obj; return(true); }