- 最后登录
- 2016-8-29
- 注册时间
- 2012-8-25
- 阅读权限
- 90
- 积分
- 23585
  
- 纳金币
- 20645
- 精华
- 62
|
change : UpdateCharacterElementDatabase.cs
class UpdateCharacterElementDatabase
{
// This method collects information about all available
// CharacterElements stores it in the CharacterElementDatabase
// assetbundle. Which CharacterElements are available is
// determined by checking the generated materials.
[MenuItem("Character Generator/Update Character Element Database")]
public static void Execute()
{
List<CharacterElement> characterElements = new List<CharacterElement>();
// As a CharacterElement needs the name of the assetbundle
// that contains its assets, we go through all assetbundles
// to match them to the materials we find.
string[] assetbundles = Directory.GetFiles(CreateAssetbundles.AssetbundlePath);
string[] materials = Directory.GetFiles("Assets/CharacterCustomization/characters", "*.mat", SearchOption.AllDirectories);
foreach (string material in materials)
{
foreach (string bundle in assetbundles)
{
FileInfo bundleFI = new FileInfo(bundle);
FileInfo materialFI = new FileInfo(material);
string bundleName = bundleFI.Name.Replace(".assetbundle", "");
if (!materialFI.Name.StartsWith(bundleName)) continue;
if (!material.Contains("Per Texture Materials")) continue;
characterElements.Add(new CharacterElement(materialFI.Name.Replace(".mat", ""), bundleFI.Name));
break;
}
}
// After collecting all CharacterElements we store them in an
// assetbundle using a ScriptableObject.
// Create a ScriptableObject that contains the list of CharacterElements.
CharacterElementHolder t = ScriptableObject.CreateInstance<CharacterElementHolder> ();
t.content = characterElements;
// Save the ScriptableObject and load the resulting asset so it can
// be added to an assetbundle.
string p = "Assets/assetbundles/CharacterElementDatabase.asset";
AssetDatabase.CreateAsset(t, p);
Object o = AssetDatabase.LoadAssetAtPath(p, typeof(CharacterElementHolder));
// Build the CharacterElementDatabase assetbundle.
BuildPipeline.BuildAssetBundle(o, null, CreateAssetbundles.AssetbundlePath + "CharacterElementDatabase.assetbundle");
// Delete the ScriptableObject.
AssetDatabase.DeleteAsset(p);
Debug.Log("******* Updated Character Element Database, added " + characterElements.Count + " elements *******");
}
}
and in CharacterGenerator.cs
public static string AssetbundleBaseURL
{
get
{
if (Application.platform == RuntimePlatform.WindowsWebPlayer || Application.platform == RuntimePlatform.OSXWebPlayer)
return Application.dataPath+"/assetbundles/";
else
return "file://" + Application.dataPath + "/assetbundles/";
}
}
After that rebuild asset and update element database
|
|