com.amanotes.contentreader
Version:
Ama Content Reader is a free library from Amanotes that provides an efficient way to access Amanotes's content store.
216 lines (171 loc) • 6.07 kB
Markdown
# Amanotes Content Reader
### Before you begin
Ama Content Reader is a free library from Amanotes that provides an efficient way to access Amanotes's content store.
### How does it work?
Ama Content Reader helps you to read any content (bin files) of your game from Amanotes Content Store.
# Setup Content Reader for your game
Add npm registry at the top of `./Packages/manifest.json`, then add `com.amanotes.contentreader` package at the end of `dependencies` block. You can get [lastest version here](https://www.npmjs.com/package/com.amanotes.contentreader?activeTab=versions)
```
{
"scopedRegistries": [{
"name": "Amanotes",
"url": "https://registry.npmjs.org/",
"scopes": [
"com.amanotes"
]
}],
"dependencies": {
// Others config goes here
// ...
"com.amanotes.contentreader" : "<lastest_version>"
}
}
```
###Getting license key for Content Reader
Contact your PO to set up and request for a unique key to use the content reader.
### Init Content Reader for your game
Init Key: Init Content Reader in your very first init scene of your game with the license provided by Amanotes
```
/**
* Project's ID needs to be matched with the license Bundle ID. (example ID: com.amanotes.rnd)
* @param licenseKey provided by Amanotes, please contract Producer Owner from Amanotes to get your license
*/
ContentNoteGenerator.InitKey("U2FsdGVkX1+Z7MdUt2Ladzxcuy/mxlnwcSlyXGduG6uFioT/aWJ7rABeVeB8/3dEjnosq");
```
### Read Notes Data
Import the package
```
using Amanotes.ContentReader;
```
To read notes datas, use GetNotes method in NoteGeneration
```
/**
* @param contentFile MIDI content in byte[] format
* @param difficulty Which difficulty to generate note for - equals to NoteTab
* @param OnComplete Will be call when load file completed
* @param OnError Will be call when load file error
*/
void ReadNotesData(byte[] contentFile)
{
NoteGeneration.GetNotes(contentFile, NoteTab.Easy,
(res,bpm) =>
{
Debug.Log("Total notes: " + res.Count);
Debug.Log("bpm: " + bpm);
},
(err) =>
{
Debug.Log(err);
});
}
```
### Customize notes list
First, you should add three variables in your song config files for NoteTab, NoteLine and GridSnap. Bellow are the enum values for these variables:
NoteTab: SupperEasy, Easy, Medium,Hard, Expert
NoteLine: All,LineOne,LineTwo,LineThree,LineFour,LineFive
GridSnap: OneByFour, OneByEight, OneByTwelve, OneBySixTeen, OneByTwentyFour, OneByThirtyTwo, OneByFortyEight, OneBySixtyFour, OneByNinetySix
To filter notes datas, use Filter method in NoteGeneration.
```
/**
* Get notes only from specific line
*
* @param notes get from function ReaderNoteData
* @param NoteLine Which NoteLine to generate note for - this parameters should be retrieved from song configs
*/
List<NoteData> FilterNoteData(List<NoteData> notes)
{
return NoteGeneration.Filter(notes, NoteLine.All);
}
/**
* Custom the density of notes
*
* @param notes get from function ReaderNoteData
* @param bpm get from function ReaderNoteData
* @param GridSnap Which GridSnap to generate note for - this parameters should be retrieved from song configs
*/
List<NoteData> TranslateNoteData(List<NoteData> notes, float bpm)
{
return NoteGeneration.Translate(bpm, notes, GridSnap.OneByEight);
}
```
### Example Content Reader
First, you need to install ExampleContentReader.unitypackage
```
public string license; //Content Reader licensing from Amanotes
public string fileName;
public NoteTab noteTab;
private float bpm;
List<NoteData> notesData;
void Start()
{
/*Note
The Unity project's ID needs to be matched with the license Bundle ID. (example ID: com.amanotes.rnd)
*/
ContentNoteGenerator.InitKey(license);
ExampleReadContentFile();
FileUtils f = new FileUtils();
f.GetListFiles();
}
public void OnClickButtonRead()
{
ExampleReadContentFile();
}
void ExampleReadContentFile()
{
string contentPath = GetStreammingAssetsPath(fileName);
WWW reader = new WWW(contentPath);
while (!reader.isDone) { }
notesData = ReaderNoteData(reader.bytes);
Debug.Log("Total notes: " + notesData.Count);
//Use noteTimes below to generate object for your game
for (int i = 0; i < notesData.Count; i++)
{
float noteTime = notesData[i].timeAppear;
Debug.Log("noteTime: " + noteTime);
}
}
public string GetStreammingAssetsPath(string name)
{
#if UNITY_EDITOR_OSX
return "file://"+Application.streamingAssetsPath + "/" + name;
#elif UNITY_EDITOR
return Application.streamingAssetsPath + "/" + name;
#elif UNITY_ANDROID
return Path.Combine("jar:file://" + Application.dataPath + "!/assets" , name);
#elif UNITY_IOS
return Path.Combine(Application.dataPath + "/Raw" , name);
#else
return Application.streamingAssetsPath + "/" + name;
#endif
}
//To read notes datas, use GetNotes method in NoteGeneration
/**
* @param contentFile MIDI content in byte[] format
* @param NoteTab Which NoteTab to generate note for
* @param OnComplete Will be call when load file completed
* @param OnError Will be call when load file error
*/
List<NoteData> ReaderNoteData(byte[] contentfile)
{
List<NoteData> notes = new List<NoteData>();
NoteGeneration.GetNotes(contentfile, NoteTab.SupperEasy,
(res, bpm) =>
{
this.bpm = bpm;
for (int i = 0; i < res.Count; i++)
{
notes.Add(res[i]);
Debug.Log(notes[i].stringIndex);
}
},
(err) =>
{
Debug.Log(err);
});
return notes;
}
```
# Versioning
We use [SemVer](http://semver.org/) for versioning.
# License
This project is licensed under the MIT License - see the [LICENSE.md](LICENSE.md) file for details