Last active
January 23, 2016 23:19
-
-
Save abhisuri97/201286d041540b647d12 to your computer and use it in GitHub Desktop.
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
using UnityEngine; | |
using System.Collections; | |
using SocketIO; | |
using System; | |
using System.Linq; | |
using System.Collections.Generic; | |
[RequireComponent (typeof (AudioSource))] | |
public class Test : MonoBehaviour { | |
// Use this for initialization | |
private SocketIOComponent socket; | |
private bool startedSocket = false; | |
//A boolean that flags whether there's a connected microphone | |
//The maximum and minimum available recording frequencies | |
private int minFreq; | |
private int maxFreq; | |
private string type; | |
private int rotate; | |
private int zoom; | |
private int x; | |
private int y; | |
private int z; | |
private int rotate_rate; | |
private string equation; | |
//A handle to the attached AudioSource | |
private AudioSource goAudioSource; | |
public static ArrayList Elements = new ArrayList(); | |
public Test(string type, int rotate, int zoom, int x, int y, | |
int z, int rotate_rate, string equation) { | |
this.type = type; | |
this.rotate = rotate; | |
this.zoom = zoom; | |
this.x = x; | |
this.y = y; | |
this.z = z; | |
this.rotate_rate = rotate; | |
if(type.Equals("equation")) { | |
this.equation = equation; | |
} | |
} | |
public int getX() { | |
return this.x; | |
} | |
public int getY() { | |
return this.y; | |
} | |
public int getZ() { | |
return this.z; | |
} | |
public string getType() { | |
return this.type; | |
} | |
public int getRotate() { | |
return this.rotate; | |
} | |
public int getZoom() { | |
return this.zoom; | |
} | |
public int getRotateRate() { | |
return this.rotate_rate; | |
} | |
public string getEquation() { | |
return this.equation; | |
} | |
public void addObject(SocketIOEvent e) { | |
bool triggered = false; | |
foreach (Test s in Elements) { | |
if (s.type.Equals (e.data.GetField("type"))) { | |
triggered = true; | |
s.rotate = Int32.Parse(e.data.GetField ("rotate").ToString()); | |
s.x= Int32.Parse(e.data.GetField ("x").ToString()); | |
s.y = Int32.Parse(e.data.GetField ("y").ToString()); | |
s.z = Int32.Parse(e.data.GetField ("z").ToString()); | |
s.rotate_rate = Int32.Parse(e.data.GetField ("rotate-rate").ToString()); | |
s.zoom = Int32.Parse(e.data.GetField ("zoom").ToString()); | |
if (type.Equals ("graph")) { | |
Int32.Parse(s.equation = e.data.GetField ("equation").ToString()); | |
} | |
} | |
} | |
if (triggered == false) { | |
string equation; | |
if (e.data.GetField ("type").Equals("equation")) { | |
equation = (e.data.GetField ("equation").ToString()); | |
} else { | |
equation = null; | |
} | |
Test newElem = new Test (e.data.GetField ("type").ToString(), | |
Int32.Parse(e.data.GetField ("rotate").ToString()), | |
Int32.Parse(e.data.GetField ("x").ToString()), | |
Int32.Parse(e.data.GetField ("y").ToString()), | |
Int32.Parse(e.data.GetField ("z").ToString()), | |
Int32.Parse(e.data.GetField ("rotate_rate").ToString()), | |
Int32.Parse(e.data.GetField ("zoom").ToString()), | |
equation); | |
Elements.Add (e.data.GetField ("type").ToString()); //when initialized, no new characteristics | |
newElem.tag = "Visible"; | |
} | |
} | |
public void removeObject(SocketIOEvent e) { | |
foreach (Test s in Elements) { | |
if (s.type.Equals (e.data.GetField("type"))) { | |
Elements.Remove (s); | |
break; | |
s.tag = "Untagged"; | |
} | |
} | |
} | |
void Start () { | |
print ("hihihihii"); | |
GameObject go = GameObject.Find("SocketIO"); | |
socket = go.GetComponent<SocketIOComponent>(); | |
socket.On ("ADD_VIEW", addObject); | |
socket.On ("REMOVE_VIEW", removeObject); | |
} | |
// Update is called once per frame | |
void Update () { | |
//potentially add update code here | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment