Last active
December 13, 2017 15:42
-
-
Save tsubaki/1965263ad6cdf8f3c454c76f0a382d47 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[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); | |
} | |
} |
Author
tsubaki
commented
Dec 13, 2017
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment