TextureExportManager.cs
2.11 KB
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
namespace UniGLTF
{
public class TextureExportManager
{
List<Texture> m_textures;
public List<Texture> Textures
{
get { return m_textures; }
}
List<Texture> m_exportTextures;
public Texture GetExportTexture(int index)
{
if (index < 0 || index >= m_exportTextures.Count)
{
return null;
}
if (m_exportTextures[index] != null)
{
// コピー変換済み
return m_exportTextures[index];
}
// オリジナル
return m_textures[index];
}
public TextureExportManager(IEnumerable<Texture> textures)
{
/*
if (textures == null)
{
throw new System.ArgumentNullException();
}
*/
m_textures = textures.ToList();
m_exportTextures = new List<Texture>(Enumerable.Repeat<Texture>(null, m_textures.Count));
}
public int CopyAndGetIndex(Texture texture, RenderTextureReadWrite readWrite)
{
if (texture == null)
{
return -1;
}
var index = m_textures.IndexOf(texture);
if (index == -1)
{
// ありえない?
return -1;
}
// ToDo: may already exists
m_exportTextures[index] = TextureItem.CopyTexture(texture, readWrite, null);
return index;
}
public int ConvertAndGetIndex(Texture texture, ITextureConverter converter)
{
if (texture == null)
{
return -1;
}
var index = m_textures.IndexOf(texture);
if (index == -1)
{
// ありえない?
return -1;
}
m_exportTextures[index] = converter.GetExportTexture(texture as Texture2D);
return index;
}
}
}