This repository has been archived by the owner on Jun 26, 2021. It is now read-only.
forked from MicroGSD/RoadArchitect
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathGSDRoadUtilityEditor.cs
78 lines (66 loc) · 2.1 KB
/
GSDRoadUtilityEditor.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#region "Imports"
using UnityEngine;
using System.IO;
using System;
#if UNITY_EDITOR
using UnityEditor;
#endif
#endregion
namespace GSD.Roads
{
public static class GSDRoadUtilityEditor
{
private static readonly string[] validFolders =
{
"Assets/RoadArchitect",
"Assets/RoadArchitect-master",
"Assets/Resources/RoadArchitect",
"Assets/Resources/RoadArchitect-master"
};
public static string GetBasePath()
{
// TODO this might break in future versions of Unity
#if UNITY_EDITOR
foreach (string folder in validFolders)
{
if (Directory.Exists(Environment.CurrentDirectory + "/" + folder))
{
return folder;
}
}
throw new System.Exception("RoadArchitect must be placed in one of the valid folders, read the top of this script");
#else
return "";
#endif
}
#if UNITY_EDITOR
public static void SetRoadMaterial(string tPath, MeshRenderer MR, string tPath2 = "")
{
Material tMat2;
Material[] tMats;
Material tMat = (Material) AssetDatabase.LoadAssetAtPath(tPath, typeof(Material));
if (tPath2.Length > 0)
{
tMats = new Material[2];
tMats[0] = tMat;
tMat2 = (Material) AssetDatabase.LoadAssetAtPath(tPath2, typeof(Material));
tMats[1] = tMat2;
}
else
{
tMats = new Material[1];
tMats[0] = tMat;
}
MR.sharedMaterials = tMats;
}
public static Material GiveMaterial(string tPath)
{
return (Material) AssetDatabase.LoadAssetAtPath(tPath, typeof(Material));
}
public static PhysicMaterial GivePhysicsMaterial(string tPath)
{
return (PhysicMaterial) AssetDatabase.LoadAssetAtPath(tPath, typeof(PhysicMaterial));
}
#endif
}
}