-
Notifications
You must be signed in to change notification settings - Fork 474
/
UnityGLTFTabbedEditor.cs
64 lines (56 loc) · 1.7 KB
/
UnityGLTFTabbedEditor.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using UnityEditor;
using UnityEditor.AssetImporters;
using UnityEngine;
[assembly: InternalsVisibleTo("UnityGLTFEditor")]
namespace UnityGLTF
{
internal class UnityGLTFTabbedEditor : AssetImporterTabbedEditor
{
private readonly List<GLTFAssetImporterTab> _tabs = new List<GLTFAssetImporterTab>();
internal int TabCount => _tabs.Count;
internal BaseAssetImporterTabUI __ActiveTab => activeTab;
protected void AddTab(GLTFAssetImporterTab tab)
{
if (tab == null) return;
if (!_tabs.Contains(tab)) _tabs.Add(tab);
tabs = _tabs.Select(x => (BaseAssetImporterTabUI) x).ToArray();
m_TabNames = _tabs.Select(t => t.Label).ToArray();
}
public GLTFAssetImporterTab GetTab(int index)
{
if (_tabs == null || _tabs.Count < 1) return null;
if (index < 0) index = 0;
if (index >= _tabs.Count) index = _tabs.Count - 1;
return _tabs[index];
}
public override void OnEnable()
{
// sanitize tab index
// from AssetImporterTabbedEditor.cs
if (activeTab == null)
{
var key = GetType().Name + "ActiveEditorIndex";
var expectedTab = EditorPrefs.GetInt(key, 0);
if (tabs.Length <= expectedTab)
EditorPrefs.SetInt(key, 0);
}
base.OnEnable();
}
}
internal class GLTFAssetImporterTab : BaseAssetImporterTabUI
{
internal readonly string Label;
private readonly Action _tabGui;
public GLTFAssetImporterTab(AssetImporterEditor panelContainer, string label, Action tabGui) : base(panelContainer)
{
this.Label = label;
this._tabGui = tabGui;
}
internal override void OnEnable() { }
public override void OnInspectorGUI() => _tabGui?.Invoke();
}
}