Skip to content

Instantly share code, notes, and snippets.

@tsubaki
Last active December 13, 2017 15:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tsubaki/1965263ad6cdf8f3c454c76f0a382d47 to your computer and use it in GitHub Desktop.
Save tsubaki/1965263ad6cdf8f3c454c76f0a382d47 to your computer and use it in GitHub Desktop.
[ScriptedImporter(1, "cube")]
public class PrimitiveImporter : ScriptedImporter
{
public PrimitiveType type = PrimitiveType.Cube;
public override void OnImportAsset(AssetImportContext ctx)
{
var cube = GameObject.CreatePrimitive(type);
cube.transform.localScale = new Vector3(1, 1, 1);
var material = new Material(Shader.Find("Standard"));
material.name = "Cube Material";
cube.GetComponent<MeshRenderer> ().material = material;
try
{
var scale = JsonUtility.FromJson<Vector3>(File.ReadAllText(ctx.assetPath));
cube.transform.localScale = scale;
}catch (System.Exception e) {
Debug.LogError (e.Message, cube);
}
ctx.AddObjectToAsset("mat", material);
ctx.AddObjectToAsset("CUBE", cube);
ctx.SetMainObject(cube);
}
}
@tsubaki
Copy link
Author

tsubaki commented Dec 13, 2017

animation 64

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment