-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNumberFlow_autoload
96 lines (82 loc) · 3.18 KB
/
NumberFlow_autoload
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
86
87
88
89
90
91
92
93
94
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using System.Threading;
using System.Threading.Tasks;
namespace CatlikeCoding.NumberFlow
{
[ExecuteInEditMode]
public class NumberFlow_autoload : MonoBehaviour
{
public static List<DiagramMaterialLink> links = new List<DiagramMaterialLink>();
void Start()
{
Debug.Log("Loading.......");
string[] guids = AssetDatabase.FindAssets("t:Diagram");
foreach (string i in guids)
{
string path = AssetDatabase.GUIDToAssetPath(i);
System.Type a = AssetDatabase.GetMainAssetTypeAtPath(path);
if (a != typeof(Diagram)) continue;
Diagram d = (Diagram)AssetDatabase.LoadAssetAtPath(path, typeof(Diagram));
string[] l = AssetDatabase.GetLabels(d);
if (l.Length == 0) return;
string[] guid = AssetDatabase.FindAssets("l:" + l[0]);
string m = AssetDatabase.GUIDToAssetPath(guid[0]);
Debug.Log("info: " + m);
//Material mat = (Material)Resources.Load(m);
Material mat = (Material)AssetDatabase.LoadAssetAtPath(m, typeof(Material));
Debug.Log("Linking ... " + path);
DiagramMaterialLink link = new DiagramMaterialLink(d, mat);
Debug.Log("Done - " + path);
}
}
void Update()
{
List<DiagramMaterialLink> r = new List<DiagramMaterialLink>();
foreach (DiagramMaterialLink i in links)
{
if (i.done())
{
Debug.Log("Finnished thread....");
r.Add(i);
}
}
foreach (DiagramMaterialLink i in r )
{
links.Remove(i);
}
}
}
#if UNITY_EDITOR
public class NumberFlow_editor2 : AssetPostprocessor
{
void OnPreprocessAsset()
{
string path = assetPath;
Diagram d;
// Material m;
System.Type t = AssetDatabase.GetMainAssetTypeAtPath(path);
if (t == typeof(Diagram))
{
d = (Diagram)AssetDatabase.LoadAssetAtPath(path, typeof(Diagram));
string[] l = AssetDatabase.GetLabels(d);
if (l.Length == 0) return;
Debug.Log(l);
string[] guid = AssetDatabase.FindAssets("l:" + l[0]);
Debug.Log("info: " + AssetDatabase.GUIDToAssetPath(guid[0]));
string m = AssetDatabase.GUIDToAssetPath(guid[0]);
Debug.Log("info: " + m);
//Material mat = (Material)Resources.Load(m,typeof(Material));
Material mat = AssetDatabase.LoadAssetAtPath(m, typeof(Material)) as Material;
Debug.Log(AssetDatabase.GetLabels(mat)[0]);
Debug.Log("Linking ... " + path);
DiagramMaterialLink link = new DiagramMaterialLink(d, mat);
Debug.Log("added - " + path);
NumberFlow_autoload.links.Add(link);
}
}
}
#endif
}