Skip to content

Commit bbcc7ee

Browse files
committed
update template
1 parent 86a44dc commit bbcc7ee

File tree

3 files changed

+25
-26
lines changed

3 files changed

+25
-26
lines changed

Editor/ScriptTemplate/MyGenerator.cs.template

+6
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@ public class MyGenerator : IAssetGenerator {
3434
return true;
3535
}
3636

37+
public bool CanGenerateAsset(AssetReference asset)
38+
{
39+
var tex = AssetDatabase.LoadAssetAtPath<Texture2D>(asset.importFrom);
40+
return tex != null;
41+
}
42+
3743
/**
3844
* Generate asset.
3945
*/

Editor/ScriptTemplate/MyImportSettingsConfigurator.cs.template

+2-10
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ using UnityEngine;
22
using UnityEditor;
33

44
using System;
5-
using System.Linq;
5+
using System.IO;
66
using System.Collections.Generic;
7+
using UnityEditor.Experimental.AssetImporters;
78

89
using UnityEngine.AssetGraph;
910
using Model=UnityEngine.AssetGraph.DataModel.Version2;
@@ -73,12 +74,6 @@ public class MyImportSettingsConfigurator : IAssetImporterConfigurator
7374
XYZObject class must be placed in "XYZObject.cs" file to be properly serialized.
7475
*/
7576

76-
using System.IO;
77-
using System.Collections;
78-
using System.Collections.Generic;
79-
using UnityEngine;
80-
using UnityEditor.Experimental.AssetImporters;
81-
8277
public class XYZObject : ScriptableObject {
8378

8479
[SerializeField] public List<List<string>> list;
@@ -123,6 +118,3 @@ public class XYZImporter : ScriptedImporter
123118
ctx.SetMainObject (xyzobj);
124119
}
125120
}
126-
127-
128-
*/

Editor/ScriptTemplate/MyPrefabBuilder.cs.template

+17-16
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@ using System.Linq;
88
using UnityEngine.AssetGraph;
99

1010
[CustomPrefabBuilder("MyPrefabBuilder")]
11-
public class MyPrefabBuilder : IPrefabBuilder {
12-
13-
[SerializeField] private Color color;
11+
public class MyPrefabBuilder : IPrefabBuilder
12+
{
1413

14+
[SerializeField] private Vector3 m_size;
15+
1516
public void OnValidate () {
1617
}
1718

@@ -21,28 +22,28 @@ public class MyPrefabBuilder : IPrefabBuilder {
2122
*/
2223
public bool CanCreatePrefab (string groupKey, List<UnityEngine.Object> objects, ref PrefabCreateDescription description) {
2324

24-
var tex = objects.Find(o => o.GetType() == typeof(UnityEngine.Texture2D));
25+
var pMat = objects.Find(o => o.GetType() == typeof(PhysicMaterial));
2526

26-
if(tex != null) {
27-
description.prefabName = string.Format("MyPrefab{0}", groupKey);
27+
if(pMat != null) {
28+
description.prefabName = $"MyPrefab{groupKey}";
2829
}
2930

30-
return tex != null;
31+
return pMat != null;
3132
}
3233

3334
/**
3435
* Create Prefab.
3536
*/
36-
public UnityEngine.GameObject CreatePrefab (string groupKey, List<UnityEngine.Object> objects) {
37+
public GameObject CreatePrefab (string groupKey, List<UnityEngine.Object> objects, GameObject previous) {
3738

38-
GameObject go = new GameObject(string.Format("MyPrefab{0}", groupKey));
39+
var pMat = (PhysicMaterial)objects.Find(o => o.GetType() == typeof(PhysicMaterial));
3940

40-
GUITexture t = go.AddComponent<GUITexture>();
41+
var go = new GameObject($"MyPrefab{groupKey}");
4142

42-
Texture2D tex = (Texture2D)objects.Find(o => o.GetType() == typeof(UnityEngine.Texture2D));
43+
var c = go.AddComponent<BoxCollider>();
4344

44-
t.texture = tex;
45-
t.color = color;
45+
c.size = m_size;
46+
c.material = pMat;
4647

4748
return go;
4849
}
@@ -54,9 +55,9 @@ public class MyPrefabBuilder : IPrefabBuilder {
5455

5556
EditorGUILayout.HelpBox("This is the inspector of your custom PrefabBuilder. You can customize by implementing OnInspectorGUI().", MessageType.Info);
5657

57-
var newValue = EditorGUILayout.ColorField("Example", color);
58-
if(newValue != color) {
59-
color = newValue;
58+
var newValue = EditorGUILayout.Vector3Field("Size", m_size);
59+
if(newValue != m_size) {
60+
m_size = newValue;
6061
onValueChanged();
6162
}
6263
}

0 commit comments

Comments
 (0)