Skip to content

Instantly share code, notes, and snippets.

@tsubaki
Last active December 13, 2017 15:04
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/6f508e288c3568a3d5ca19a95ce254fe to your computer and use it in GitHub Desktop.
Save tsubaki/6f508e288c3568a3d5ca19a95ce254fe to your computer and use it in GitHub Desktop.
キューブ
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor.Experimental.AssetImporters;
using System.IO;
using UnityEditor;
using UnityEngine.Assertions;
using System.Linq;
[ScriptedImporter(1, "cube")]
public class CubeImporter : ScriptedImporter
{
public override void OnImportAsset(AssetImportContext ctx)
{
// 紐付けるGameObjectを作成する
var cube = GameObject.CreatePrimitive(PrimitiveType.Cube);
cube.transform.localScale = new Vector3(1, 1, 1);
var material = new Material(Shader.Find("Standard"));
material.name = "Cube Material";
cube.GetComponent<MeshRenderer> ().material = material;
// オブジェクトを登録する
ctx.AddObjectToAsset("CUBE", cube);
ctx.AddObjectToAsset(material.name, material);
ctx.SetMainObject(cube);
// JSONのデータを元に登録したGameObjectの設定を上書きする
try
{
var scale = JsonUtility.FromJson<Vector3>(File.ReadAllText(ctx.assetPath));
cube.transform.localScale = scale;
}catch (System.Exception e) {
Debug.LogError (e.Message, cube);
}
}
}
@tsubaki
Copy link
Author

tsubaki commented Dec 13, 2017

animation 61

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