Skip to content

Instantly share code, notes, and snippets.

@wmiller
wmiller / Infos.cs
Created February 4, 2014 13:55
XML Database part 2 Infos.cs
View Infos.cs
using UnityEngine;
using System.Collections;
using System.Xml;
using System.Xml.Serialization;
[XmlRoot]
public sealed class TileInfo : DatabaseEntry
{
[XmlElement]
public int Height { get; private set; }
@wmiller
wmiller / AsyncMapBuilder.cs
Created February 3, 2014 21:20
XML Database AsyncMapBuilder.cs
View AsyncMapBuilder.cs
public class AsyncMapBuilder : MapBuilder
{
protected override void InitMapObjects()
{
for (int y = 0; y < Height; ++y)
{
for (int x = 0; x < Width; ++x)
{
int height = HeightField[y * Width + x];
int tempX = x;
@wmiller
wmiller / ResourceManager.cs
Created February 3, 2014 21:19
XML Database ValidateAssetBundleAssetsInternal
View ResourceManager.cs
private static void ValidateAssetBundleAssetsInternal()
{
// Get all asset infos from the database and iterate over them
AssetInfo[] assetInfos = Database.Instance.GetEntries<AssetInfo>();
foreach (AssetInfo assetInfo in assetInfos)
{
// Load the object referenced by the asset info. Warn if the
// object fails to load
Object asset = Resources.LoadAssetAtPath<Object>(assetInfo.Path);
if (!asset)
@wmiller
wmiller / ResourceManager.cs
Created February 3, 2014 21:18
XML Database LoadBundlesCo
View ResourceManager.cs
private IEnumerator LoadBundlesCo(System.Action onComplete)
{
// Get bundle infos from the database
AssetBundleInfo[] bundleInfos = Database.Instance.GetEntries<AssetBundleInfo>();
// Load each bundle using the path in the bundle info
foreach (AssetBundleInfo info in bundleInfos)
{
string url = "file://" + AssetBundlePath + "/" + info.Name + ".unity3d";
@wmiller
wmiller / ResourceManager.cs
Created February 3, 2014 21:17
XML Database LoadAssetAsyncCo
View ResourceManager.cs
private IEnumerator LoadAssetAsyncCo<T>(AssetInfo info, System.Action<T> onComplete) where T : UnityEngine.Object
{
if (info.AssetBundleInfoRef != null)
{
// Get the bundle from the loaded bundles collection
AssetBundle bundle;
if (!loadedBundles.TryGetValue(info.AssetBundleInfoRef.Entry.DatabaseID, out bundle))
{
throw new System.Exception("Asset bundle not found: " + info.AssetBundleInfoRef.Entry.Name);
}
@wmiller
wmiller / ResourceManager.cs
Created February 3, 2014 21:15
XML Database BuildAssetBundles
View ResourceManager.cs
[MenuItem("Assets/Build AssetBundles")]
private static void BuildAssetBundles()
{
ClearAssetBundles();
// You would probably want to parameterize this part
Database.Instance.ReadFiles(AssetInfoXMLPath);
// Validate asset infos
ValidateAssetBundleAssetsInternal();
@wmiller
wmiller / AssetData.xml
Created February 3, 2014 21:13
XML Database AssetData.xml
View AssetData.xml
<Database>
<!-- Asset Bundle Infos -->
<AssetBundleInfo ID="ASSET_BUNDLE_MAIN_CONTENT">
<Name>MainContent</Name>
<URL>StreamingAssets/AssetBundles/MainContent.unity3d</URL>
</AssetBundleInfo>
<!-- Asset Infos -->
@wmiller
wmiller / AssetInfo.cs
Created February 3, 2014 21:12
XML Database AssetInfo.cs
View AssetInfo.cs
using UnityEngine;
using System.Collections;
using System.IO;
using System.Text;
using System.Xml;
using System.Xml.Serialization;
[XmlRoot("AssetInfo")]
public sealed class AssetInfo : DatabaseEntry
{
@wmiller
wmiller / AssetBundleInfo.cs
Created February 3, 2014 21:11
XML Database AssetBundleInfo.cs
View AssetBundleInfo.cs
using UnityEngine;
using System.Collections;
using System.IO;
using System.Text;
using System.Xml;
using System.Xml.Serialization;
[XmlRoot("AssetBundleInfo")]
public sealed class AssetBundleInfo : DatabaseEntry
{
@wmiller
wmiller / ID.cs
Created February 3, 2014 05:14
XML Database ID.cs
View ID.cs
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Xml;
using System.Xml.Schema;
using System.Xml.Serialization;
public class ID
{