Created
October 4, 2015 16:49
-
-
Save rubit0/3fd69474adbdcf110db9 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
using UnityEngine; | |
using NextGenSprites; | |
using UnityEditor; | |
using System.Collections; | |
public class CreateMaterialPropertyBlock : MonoBehaviour | |
{ | |
[MenuItem("Assets/Create/Material Property Block")] | |
public static void GenerateMaterialPropertyBlock() | |
{ | |
var inHierarchy = (Selection.activeObject != null && AssetDatabase.Contains(Selection.activeObject) == false); | |
var _sRend = (inHierarchy) ? Selection.activeGameObject.GetComponent<SpriteRenderer>() : null; | |
if (_sRend != null) | |
{ | |
var mBlock = new MaterialPropertyBlock(); | |
_sRend.GetPropertyBlock(mBlock); | |
mBlock.CopyToPropertyBlock(_sRend.sharedMaterial); | |
var obj = ScriptableObject.CreateInstance<MaterialPropertieBlockContainer>(); | |
obj.Block = mBlock; | |
Debug.Log(obj.Block.GetFloat(KeyFloat.CurvatureDepth.GetString())); | |
var path = EditorUtility.SaveFilePanelInProject ( | |
"Create a new Material Propertie Block", | |
"Material Property Block.asset", | |
"asset", | |
"Copy Pre-Renderer Data and Material Data to this new Material Property Block"); | |
if (string.IsNullOrEmpty (path)) | |
return; | |
AssetDatabase.CreateAsset(obj, path); | |
Debug.Log(string.Format("New Material Property Block has been saved in: " + path)); | |
EditorUtility.FocusProjectWindow(); | |
Selection.activeObject = obj; | |
} | |
else | |
{ | |
EditorUtility.DisplayDialog("Error", "No GameObject with SpriteRenderer selected", "Ok"); | |
return; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment