< Summary

Class:EndNameEdit
Assembly:MainEditor
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/Editor/ScriptableObjectWindow.cs
Covered lines:0
Uncovered lines:1
Coverable lines:1
Total lines:64
Line coverage:0% (0 of 1)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
Action(...)0%2100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/Editor/ScriptableObjectWindow.cs

#LineLine coverage
 1using System;
 2using System.Linq;
 3using UnityEditor;
 4using UnityEditor.ProjectWindowCallback;
 5using UnityEngine;
 6
 7internal class EndNameEdit : EndNameEditAction
 8{
 9
 10    #region implemented abstract members of EndNameEditAction
 11
 012    public override void Action (int instanceId, string pathName, string resourceFile) { AssetDatabase.CreateAsset(Edito
 13
 14    #endregion
 15
 16}
 17
 18/// <summary>
 19/// Scriptable object window.
 20/// </summary>
 21public class ScriptableObjectWindow : EditorWindow
 22{
 23    private int selectedIndex;
 24    private static string[] names;
 25
 26    private static Type[] types;
 27
 28    private static Type[] Types
 29    {
 30        get { return types; }
 31        set
 32        {
 33            types = value;
 34            names = types.Select(t => t.FullName).ToArray();
 35        }
 36    }
 37
 38    public static void Init(Type[] scriptableObjects)
 39    {
 40        Types = scriptableObjects;
 41
 42        var window = EditorWindow.GetWindow<ScriptableObjectWindow>(true, "Create a new ScriptableObject", true);
 43        window.ShowPopup();
 44    }
 45
 46    public void OnGUI()
 47    {
 48        GUILayout.Label("ScriptableObject Class");
 49        selectedIndex = EditorGUILayout.Popup(selectedIndex, names);
 50
 51        if (GUILayout.Button("Create"))
 52        {
 53            var asset = ScriptableObject.CreateInstance(types[selectedIndex]);
 54            ProjectWindowUtil.StartNameEditingIfProjectWindowExists(
 55                asset.GetInstanceID(),
 56                ScriptableObject.CreateInstance<EndNameEdit>(),
 57                string.Format("{0}.asset", names[selectedIndex]),
 58                AssetPreview.GetMiniThumbnail(asset),
 59                null);
 60
 61            Close();
 62        }
 63    }
 64}