This package provides a way to create importer script inside asset itself.
Put this repository in the Packages directory.
[Assets > Create > Asset Script] to create new script asset.
This script creates new prefab.
cube.assetscript
#using UnityEngine
AddObjectToAsset("GameObject", GameObject.CreatePrimitive(PrimitiveType.Cube));This example is about changing an existing prefab.
New Prefab is created from Base prefab which is standard prefab. Within import process, Material and Colliders are changed.
Variant is prefab variant based on New Prefab.
#using UnityEngine
var go = CopyAsset<GameObject>("Base Prefab.prefab");
if (go)
{
// change collider type
Destroy(go.GetComponent<Collider>());
go.AddComponent<BoxCollider>();
// set material
go.GetComponent<MeshRenderer>().sharedMaterial = LoadAsset<Material>("../Source Material.mat");
AddObjectToAsset("GameObject", go);
}This example demonstrates reusable scripts.
- include.txt
- Sphere.prefab
- Cube.prefab
- Sphere.assetscript
- Cube.assetscript
Unlike previous example, source prefab is automatically chosen from name of asset script. Also all scripts shares same code via include directive.
include.txt
#using UnityEngine
var go = CopyAsset<GameObject>(GetAssetPathWithoutExtension() + ".prefab");
if (go)
{
go.GetComponent<Renderer>().sharedMaterial = LoadAsset<Material>("../Source Material.mat");
AddObjectToAsset("Prefab", go);
}Sphere.assetscript, Cube.assetscript
#include "include.txt"
#using UnityEngine
var tex = new Texture2D(64, 64);
var pixels = tex.GetPixels();
for (var i = 0; i < pixels.Length; ++i)
{
pixels[i] = new Color((float)i / pixels.Length, i % 2, (i + 1) % 2);
}
tex.SetPixels(pixels);
AddObjectToAsset("Texture", tex);
