-
Notifications
You must be signed in to change notification settings - Fork 212
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from legoandmars/NewModelFormat
New model format & fixes
- Loading branch information
Showing
11 changed files
with
137 additions
and
14 deletions.
There are no files selected for viewing
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
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
[System.Serializable] | ||
public class PackageJSON | ||
{ | ||
public string androidFileName; | ||
public string pcFileName; | ||
public Descriptor descriptor; | ||
public Config config; | ||
} | ||
|
||
[System.Serializable] | ||
public class Descriptor | ||
{ | ||
public string objectName; | ||
public string author; | ||
public string description; | ||
} | ||
|
||
[System.Serializable] | ||
public class Config | ||
{ | ||
public bool customColors; | ||
public bool disableInPublicLobbies; | ||
} |
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
using UnityEngine; | ||
using System.IO.Compression; | ||
using System.IO; | ||
using System.Linq; | ||
using GorillaCosmetics.Data.Descriptors; | ||
using GorillaCosmetics.Data; | ||
using Newtonsoft.Json; | ||
|
||
namespace GorillaCosmetics.Utils | ||
{ | ||
public static class PackageUtils | ||
{ | ||
public static (AssetBundle bundle, PackageJSON json) AssetBundleAndJSONFromPackage(string path) | ||
{ | ||
AssetBundle bundle = null; | ||
PackageJSON json = null; | ||
using (ZipArchive archive = ZipFile.OpenRead(path)) | ||
{ | ||
var jsonEntry = archive.Entries.First(i => i.Name == "package.json"); | ||
if (jsonEntry != null) | ||
{ | ||
var stream = new StreamReader(jsonEntry.Open(), Encoding.Default); | ||
string jsonString = stream.ReadToEnd(); | ||
json = JsonConvert.DeserializeObject<PackageJSON>(jsonString); | ||
} | ||
foreach (ZipArchiveEntry entry in archive.Entries) | ||
{ | ||
if (json != null && entry.Name == json.pcFileName) | ||
{ | ||
//here the file | ||
var SeekableStream = new MemoryStream(); | ||
entry.Open().CopyTo(SeekableStream); | ||
SeekableStream.Position = 0; | ||
bundle = AssetBundle.LoadFromStream(SeekableStream); | ||
} | ||
} | ||
} | ||
return (bundle, json); | ||
} | ||
|
||
public static AssetBundle AssetBundleFromPackage(string path) | ||
{ | ||
return AssetBundleAndJSONFromPackage(path).bundle; | ||
} | ||
|
||
public static GorillaMaterialDescriptor ConvertJsonToMaterial(PackageJSON json) | ||
{ | ||
GorillaMaterialDescriptor Descriptor = new GorillaMaterialDescriptor(); | ||
Descriptor.MaterialName = json.descriptor.objectName; | ||
Descriptor.AuthorName = json.descriptor.author; | ||
Descriptor.Description = json.descriptor.description; | ||
Descriptor.CustomColors = json.config.customColors; | ||
Descriptor.DisablePublicLobbies = json.config.disableInPublicLobbies; | ||
return Descriptor; | ||
} | ||
|
||
public static HatDescriptor ConvertJsonToHat(PackageJSON json) | ||
{ | ||
HatDescriptor Descriptor = new HatDescriptor(); | ||
Descriptor.HatName = json.descriptor.objectName; | ||
Descriptor.AuthorName = json.descriptor.author; | ||
Descriptor.Description = json.descriptor.description; | ||
Descriptor.CustomColors = json.config.customColors; | ||
Descriptor.DisablePublicLobbies = json.config.disableInPublicLobbies; | ||
return Descriptor; | ||
} | ||
} | ||
} |
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