Commit 6d078784 authored by mmaluschnig's avatar mmaluschnig
Browse files

added spawnKeys script to read a text file and spawn keys at certain timestamps

parent 89ba9f82
......@@ -113,6 +113,49 @@ NavMeshSettings:
debug:
m_Flags: 0
m_NavMeshData: {fileID: 0}
--- !u!1 &89139954
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 89139955}
- component: {fileID: 89139956}
m_Layer: 0
m_Name: LevelMaster
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &89139955
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 89139954}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 1
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &89139956
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 89139954}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: dc3222697207c486cbe9197b763b4ec1, type: 3}
m_Name:
m_EditorClassIdentifier:
songFile: {fileID: 4900000, guid: d66310f56c0f0487b8df20890b29e5f6, type: 3}
arrowPrefab: {fileID: 1765769401102260, guid: 72656df34da634e679741c24832b3f36,
type: 2}
--- !u!1 &519420028
GameObject:
m_ObjectHideFlags: 0
......@@ -190,3 +233,45 @@ Transform:
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1001 &1337961999
Prefab:
m_ObjectHideFlags: 0
serializedVersion: 2
m_Modification:
m_TransformParent: {fileID: 0}
m_Modifications:
- target: {fileID: 4145066122545122, guid: 72656df34da634e679741c24832b3f36, type: 2}
propertyPath: m_LocalPosition.x
value: 5
objectReference: {fileID: 0}
- target: {fileID: 4145066122545122, guid: 72656df34da634e679741c24832b3f36, type: 2}
propertyPath: m_LocalPosition.y
value: 4
objectReference: {fileID: 0}
- target: {fileID: 4145066122545122, guid: 72656df34da634e679741c24832b3f36, type: 2}
propertyPath: m_LocalPosition.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4145066122545122, guid: 72656df34da634e679741c24832b3f36, type: 2}
propertyPath: m_LocalRotation.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4145066122545122, guid: 72656df34da634e679741c24832b3f36, type: 2}
propertyPath: m_LocalRotation.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4145066122545122, guid: 72656df34da634e679741c24832b3f36, type: 2}
propertyPath: m_LocalRotation.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4145066122545122, guid: 72656df34da634e679741c24832b3f36, type: 2}
propertyPath: m_LocalRotation.w
value: 1
objectReference: {fileID: 0}
- target: {fileID: 4145066122545122, guid: 72656df34da634e679741c24832b3f36, type: 2}
propertyPath: m_RootOrder
value: 2
objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 72656df34da634e679741c24832b3f36, type: 2}
m_IsPrefabAsset: 0
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class SpawnKeys : MonoBehaviour {
public TextAsset songFile;
public GameObject arrowPrefab;
Queue<string[]> songKeys = new Queue<string[]>();
string[] nextKey;
string[] arrows;
float[] timings;
int pointer = 0;
float startTime;
// Use this for initialization
void Start () {
startTime = Time.time;
//loads data into two side-by-side arrays one holding
//the string value of the arrowkey and the other
//holding the float value of the timestamp that
//the key should be instantiated.
print("Array version");
string[] lines = songFile.text.Split('\n');
arrows = new string[lines.Length];
timings = new float[lines.Length];
int count = 0;
foreach (string line in lines)
{
arrows[count] = line.Split(' ')[0];
timings[count] = float.Parse(line.Split(' ')[1]);
count++;
}
//print out arrays
//for (int i = 0; i < arrows.Length; i++)
//{
// print(arrows[i] + " " + timings[i]);
//}
//Same as above but uses queues, will have to parse
//string of timings into a float later on.
print("Queue version!");
foreach (string line in songFile.text.Split('\n'))
{
songKeys.Enqueue(line.Split(' '));
}
nextKey = songKeys.Dequeue();
//print out queue
//while (songKeys.Count > 0)
//{
// string[] x = songKeys.Dequeue();
// print(x[0] + " " + x[1]);
//}
}
// Update is called once per frame
void Update () {
if (nextKey != null && Time.time > startTime + float.Parse(nextKey[1]))
{
switch (nextKey[0])
{
case "left":
print("left");
Instantiate(arrowPrefab, new Vector3(5f, 4f, 1f), Quaternion.identity);
break;
case "right":
print("right");
Instantiate(arrowPrefab, new Vector3(8f, 4f, 1f), Quaternion.identity);
break;
case "up":
print("up");
Instantiate(arrowPrefab, new Vector3(6f, 4f, 1f), Quaternion.identity);
break;
case "down":
print("DOWN");
Instantiate(arrowPrefab, new Vector3(7f, 4f, 1f), Quaternion.identity);
break;
default:
break;
}
if (songKeys.Count > 0)
{
nextKey = songKeys.Dequeue();
}
else
{
//no more keys
nextKey = null;
}
}
}
}
fileFormatVersion: 2
guid: dc3222697207c486cbe9197b763b4ec1
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment