//-------------------------------------------------------------------------------------- // Profile / Class Methods /// <summary> If this user exists within the database, apply their hand profile to this SenseGlove_Object. </summary> /// <param name="userName"></param> public void SetProfile(string name) { if (userName != null && userName.Length > 0) { this.canUpdate = false; this.userName = name; UserProfiles.SetLastUser(this.userName, this.senseGlove.GloveData().deviceID); HandProfile newProfile = UserProfiles.GetProfile(name); this.SetProfile(newProfile); SenseGlove_Debugger.Log("Set Profile for " + this.userName); this.canUpdate = true; //prevent additional calls to fingerCalibrationFinished while we update the profile. } else { SenseGlove_Debugger.LogWarning("Invalid Username"); } }
/// <summary> Tell the database that this user is the last used for this deviceID </summary> /// <param name="deviceID"></param> public static void SetLastUser(string userName, string deviceID) { if (userName.Length > 0) { if (GetLastUser(deviceID).Length > 0) //check if already loaded. { lastProfiles[deviceID] = userName; } else //new entry { lastProfiles.Add(deviceID, userName); } } else { SenseGlove_Debugger.LogWarning("Warning: Invalid Username"); } }
/// <summary> Load a materials library from a TextAsset </summary> /// <param name="databaseFile"></param> public static void LoadLibrary(string dir, string file) { if (!IsLoaded(file)) { string[] fLines; if (Util.FileIO.ReadTxtFile(dir + file, out fLines)) { //Splitup file int line = 0; List <string> dataBlock = new List <string>(); string lastName = ""; while (line <= fLines.Length) { if (line >= fLines.Length || (fLines[line].Length > 0 && fLines[line][0] == '#')) //its a new Material { if (dataBlock.Count > 0 && lastName.Length > 0) //parse & add previous Material if it has a good name { AddMaterial(lastName, MaterialProps.Parse(dataBlock)); } dataBlock.Clear(); if (line < fLines.Length) { try //extract name of new material { lastName = fLines[line].Split(new char[] { ' ' }, System.StringSplitOptions.RemoveEmptyEntries)[1].ToLowerInvariant(); //condition name } catch (System.Exception Ex) { SenseGlove_Debugger.LogWarning(Ex.Message); lastName = ""; } } } if (line < fLines.Length) { dataBlock.Add(fLines[line]); } line++; } } libraryNames.Add(file); //prevents us from continuously trying to open files } }
/// <summary> Check if all RigidBody settings allow us to pick up objects. </summary> protected void ValidateRB() { this.physicsBody = this.GetComponent <Rigidbody>(); if (this.physicsBody != null) { if (this.physicsBody.useGravity) { SenseGlove_Debugger.LogWarning(this.name + ".DropZone has a rigidbody that uses gravity, and might move from its desired location."); } } else //we don't have a RigidBody, so one of the ObjectsToGet should have it! { if (this.objectsToGet.Count > 0) { bool noRBs = true; for (int i = 0; i < this.objectsToGet.Count; i++) { if (this.objectsToGet[i].physicsBody == null) { SenseGlove_Debugger.LogWarning(this.objectsToGet[i].name + " will not be detected by " + this.name + ".DropZone, as neither have a RigidBody attached."); } else { noRBs = false; } } if (noRBs) { Debug.LogWarning("Since none of the ObjectsToGet in " + this.name + " have a RigidBody attached, one was autmatically attached to the GameObject."); this.physicsBody = this.gameObject.AddComponent <Rigidbody>(); this.physicsBody.useGravity = false; this.physicsBody.isKinematic = true; } } else { SenseGlove_Debugger.LogWarning(this.name + ".DropZone has no RigidBody of its own, and will therefore only " + "detect Grabables with a RigidBody attached."); } } }
/// <summary> Snaps an object to this Zone's snapPoint, based on the Grabable's grabType. </summary> /// <param name="grabable"></param> protected void AttachObject(SenseGlove_Grabable grabable) { grabable.SnapMeTo(this.snapPoint); grabable.InteractionBegun += Grabable_InteractionBegun; grabable.ObjectReset += Grabable_ObjectReset; int index = ListIndex(grabable, this.objectsInside); if (this.snapMethod == SnapMethod.FixedJoint || (this.snapMethod == SnapMethod.ObjectDependent && grabable.pickupMethod == GrabType.FixedJoint)) { if (grabable.physicsBody != null) { grabable.physicsBody.useGravity = true; if (index > -1) { this.snapProperties[index].CreateJoint(grabable, this.physicsBody, SenseGlove_Grabable.defaultBreakForce); this.snapProperties[index].isSnapped = true; } } else { SenseGlove_Debugger.LogWarning(grabable.name + " does not have a RigidBody to attach to " + this.name + " via PhysicsJoint."); } } else //any other way we snap it using the parent method. { grabable.pickupReference.parent = this.snapPoint; if (grabable.physicsBody != null) { grabable.physicsBody.useGravity = false; grabable.physicsBody.isKinematic = true; } if (index > -1) { this.snapProperties[index].isSnapped = true; } } }
/// <summary> Load the Database, if not already done. </summary> /// <param name="directory"></param> public static void LoadDB(string directory) { if (!DBLoaded) { string[] lines; if (Util.FileIO.ReadTxtFile(directory + databaseName, out lines)) { DBLoaded = true; List <string> block = new List <string>(); int line = 1; //skip the @lastProfiles //fill the block with all of the "LastProfiles" while (line <= lines.Length && !(lines[line].Length > 0 && lines[line][0] == '@')) { if (line < lines.Length) { block.Add(lines[line]); line++; } } //process lastProfiles for (int i = 0; i < block.Count; i++) { string[] split = block[i].Split('\t'); if (split.Length > 1) { lastProfiles.Add(split[0], split[1]); } } block.Clear(); line++; string lastEntry = ""; while (line <= lines.Length) { if (line >= lines.Length || (lines[line].Length > 0 && lines[line][0] == '#')) //its a new Material { if (block.Count > 0 && lastEntry.Length > 0) //parse & add previous Material if it has a good name { //UserProfiles.AddEntry(lastEntry, HandProfile.Parse(block)); profiles.Add(lastEntry, HandProfile.Parse(block)); } block.Clear(); if (line < lines.Length) { try //extract name of new material { lastEntry = lines[line].Split(new char[] { '\t' }, System.StringSplitOptions.RemoveEmptyEntries)[1]; //condition name } catch (System.Exception Ex) { SenseGlove_Debugger.LogWarning(Ex.Message); lastEntry = ""; } } } if (line < lines.Length) { block.Add(lines[line]); } line++; } DBLoaded = true; //SenseGlove_Debugger.Log("Loaded Database!"); } else { //could not load this data base asset } } }