< Summary

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

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
Init(...)0%2100%
OnGUI()0%6200%

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
 12    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    {
 030        get { return types; }
 31        set
 32        {
 033            types = value;
 034            names = types.Select(t => t.FullName).ToArray();
 035        }
 36    }
 37
 38    public static void Init(Type[] scriptableObjects)
 39    {
 040        Types = scriptableObjects;
 41
 042        var window = EditorWindow.GetWindow<ScriptableObjectWindow>(true, "Create a new ScriptableObject", true);
 043        window.ShowPopup();
 044    }
 45
 46    public void OnGUI()
 47    {
 048        GUILayout.Label("ScriptableObject Class");
 049        selectedIndex = EditorGUILayout.Popup(selectedIndex, names);
 50
 051        if (GUILayout.Button("Create"))
 52        {
 053            var asset = ScriptableObject.CreateInstance(types[selectedIndex]);
 054            ProjectWindowUtil.StartNameEditingIfProjectWindowExists(
 55                asset.GetInstanceID(),
 56                ScriptableObject.CreateInstance<EndNameEdit>(),
 57                string.Format("{0}.asset", names[selectedIndex]),
 58                AssetPreview.GetMiniThumbnail(asset),
 59                null);
 60
 061            Close();
 62        }
 063    }
 64}