Hi,
i´ve written an editor script to create a texture bundle from my selection.
Everytime after execution i get the same error message:
NullReferenceException: Object reference not set to an instance of an
object at
UnityEditor.DockArea.EndOffsetArea ()
[0x00000] in :0
at UnityEditor.DockArea.OnGUI ()
[0x00000] in :0
Here´s my script.
Hope someone could help me where´s the bug…
Thanks for your time…
using UnityEngine;
using UnityEditor;
using System.IO;
using System.Collections.Generic;
public class CreateTextureBundleForSelection : EditorWindow
{
private List<Object> mainAssets;
// Creates a bundle from all selected textures
// 1. Select different textures in the project view
// 2. Start execution)
[@MenuItem("AssetBuilding/Create bundle for selected textures...")]
static void Init () {
CreateTextureBundleForSelection window = (CreateTextureBundleForSelection)EditorWindow.GetWindow (typeof (CreateTextureBundleForSelection), false, "TextureBundle" );
window.Show();
}
void OnGUI()
{
EditorGUILayout.Space();
GUILayout.Label ("Single textures will be packed to one bundle!", EditorStyles.boldLabel);
GUILayout.Label ("Select textures from the project view.", EditorStyles.boldLabel);
EditorGUILayout.Space();
if(GUI.Button(new Rect(0, 70, position.width, 30), "Create texture bundle from selection"))
{
mainAssets = new List<Object>();
foreach (Object tex in Selection.objects)
{
string path = AssetDatabase.GetAssetPath(tex);
Object t = AssetDatabase.LoadMainAssetAtPath(path);
if (t != null){
mainAssets.Add(t);
Debug.Log("Path: " + path);
}
}
SaveAssetBundle();
}
}
/// <summary>
/// Save the assetbundle - bring up the panel for name description ==================================
/// </summary>
private void SaveAssetBundle()
{
if(mainAssets.ToArray().Length > 0)
{
string fileNameToSave = EditorUtility.SaveFilePanel ("Save Texture Bundle", "", "New Texturebundle Name", "unity3d");
if (fileNameToSave.Length != 0)
{
BuildPipeline.BuildAssetBundle(null, Selection.objects, fileNameToSave, BuildAssetBundleOptions.CompleteAssets);
Debug.Log("---> ASSETBUNDLE BUILD COMPLETE! Objects of type: -->" + options[index] + "<-- has element count of: --> " + Selection.objects.Length);
}
}
else{
Debug.Log("ERROR - No Assets!");
}
}
}