public void NewGoal() { int goalIndex = color.Equals("Red") ? redGoals[gamepieceIndex].Count() : blueGoals[gamepieceIndex].Count(); GameObject gameobject = new GameObject("Gamepiece" + gamepieceIndex.ToString() + "Goal" + goalIndex.ToString()); BBoxShape collider = gameobject.AddComponent <BBoxShape>(); BRigidBody rigid = gameobject.AddComponent <BRigidBody>(); rigid.collisionFlags = rigid.collisionFlags | BulletSharp.CollisionFlags.NoContactResponse | BulletSharp.CollisionFlags.StaticObject; Goal goal = gameobject.AddComponent <Goal>(); collider.Extents = new UnityEngine.Vector3(0.5f, 0.5f, 0.5f); rigid.SetPosition(new UnityEngine.Vector3(0, 4, 0)); goal.position = new UnityEngine.Vector3(0, 4, 0); goal.scale = Vector3.one; goal.SetKeyword(FieldDataHandler.gamepieces[gamepieceIndex].name); goal.description = "New Goal"; goal.color = color; if (color.Equals("Red")) { redGoals[gamepieceIndex].Add(gameobject); } else { blueGoals[gamepieceIndex].Add(gameobject); } InitializeDisplay(); WriteGoals(); }
/// <summary> /// Gets blue goals as list of list of Goal objects from field_data.xml /// </summary> private static List <List <GameObject> > getBlueGoals() { List <List <GameObject> > goals = new List <List <GameObject> >(); foreach (XElement z in file.Root.Element("Goals").Element("BlueGoals").Elements()) { List <GameObject> temp = new List <GameObject>(); foreach (XElement e in z.Elements()) { GameObject g = new GameObject("Gamepiece" + goals.Count().ToString() + "Goal" + temp.Count().ToString()); BBoxShape collider = g.AddComponent <BBoxShape>(); BRigidBody rigid = g.AddComponent <BRigidBody>(); rigid.collisionFlags = rigid.collisionFlags | BulletSharp.CollisionFlags.NoContactResponse | BulletSharp.CollisionFlags.StaticObject; Goal goal = g.AddComponent <Goal>(); collider.Extents = new UnityEngine.Vector3(0.5f, 0.5f, 0.5f); goal.pointValue = int.Parse(e.Element("Points").Value); goal.position = new UnityEngine.Vector3(float.Parse(e.Element("Position").Attribute("x").Value), float.Parse(e.Element("Position").Attribute("y").Value), float.Parse(e.Element("Position").Attribute("z").Value)); rigid.SetPosition(goal.position); goal.scale = new UnityEngine.Vector3(float.Parse(e.Element("Scale").Attribute("x").Value), float.Parse(e.Element("Scale").Attribute("y").Value), float.Parse(e.Element("Scale").Attribute("z").Value)); collider.LocalScaling = goal.scale; goal.gamepieceKeyword = e.Element("Keyword").Value; goal.description = e.Element("Description").Value; goal.color = e.Attribute("Color").Value; temp.Add(g); } goals.Add(temp); } //increases depth of list to number of gamepieces for future goal writing while (goals.Count != gamepieces.Count) { goals.Add(new List <GameObject>()); } return(goals); }
/// <summary> /// Gets goals as list of list of Goal objects from field_data.xml, picking color from argument /// </summary> private static List <List <GameObject> > getGoals(string goalsName) { List <List <GameObject> > goals = new List <List <GameObject> >(); foreach (XElement z in file.Root.Element("Goals").Element(goalsName).Elements()) { List <GameObject> temp = new List <GameObject>(); foreach (XElement e in z.Elements()) { GameObject g = new GameObject("Gamepiece" + goals.Count().ToString() + "Goal" + temp.Count().ToString()); g.transform.SetParent(GoalManager.GoalParent.transform); BBoxShape collider = g.AddComponent <BBoxShape>(); BRigidBody rigid = g.AddComponent <BRigidBody>(); rigid.collisionFlags = rigid.collisionFlags | BulletSharp.CollisionFlags.NoContactResponse | BulletSharp.CollisionFlags.StaticObject; Goal goal = g.AddComponent <Goal>(); collider.Extents = new UnityEngine.Vector3(0.5f, 0.5f, 0.5f); goal.pointValue = int.Parse(e.Element("Points").Value); goal.SetKeepScored(bool.Parse(e.Element("KeepScored").Value)); goal.position = new UnityEngine.Vector3(float.Parse(e.Element("Position").Attribute("x").Value), float.Parse(e.Element("Position").Attribute("y").Value), float.Parse(e.Element("Position").Attribute("z").Value)); rigid.SetPosition(goal.position); try { goal.rotation = new UnityEngine.Vector3(float.Parse(e.Element("Position").Attribute("i").Value), float.Parse(e.Element("Position").Attribute("j").Value), float.Parse(e.Element("Position").Attribute("k").Value)); } catch (System.Exception) { goal.rotation = Vector3.zero; } rigid.SetRotation(Quaternion.Euler(goal.rotation)); goal.scale = new UnityEngine.Vector3(float.Parse(e.Element("Scale").Attribute("x").Value), float.Parse(e.Element("Scale").Attribute("y").Value), float.Parse(e.Element("Scale").Attribute("z").Value)); collider.LocalScaling = goal.scale; goal.gamepieceKeyword = e.Element("Keyword").Value; goal.description = e.Element("Description").Value; goal.color = e.Attribute("Color").Value; try { goal.Sticky = bool.Parse(e.Element("Sticky").Value); } catch (Exception excep) { goal.Sticky = false; } temp.Add(g); } goals.Add(temp); } //increases depth of list to number of gamepieces for future goal writing while (goals.Count != gamepieces.Count) { goals.Add(new List <GameObject>()); } return(goals); }
/// <summary> /// Updates the positions and rotations of each tracker's parent object according to the replay time. /// </summary> public override void LateUpdate() { if (dynamicCamera == null) { dynamicCamera = UnityEngine.Object.FindObjectOfType <DynamicCamera>(); camera = dynamicCamera.GetComponent <Camera>(); } if (InputControl.GetButtonDown(Controls.buttons[0].cameraToggle)) { dynamicCamera.ToggleCameraState(dynamicCamera.cameraState); } if (firstFrame) { firstFrame = false; } else if (Input.GetKeyDown(KeyCode.Space)) { if (Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.RightControl)) { rewindTime = Tracker.Lifetime; playbackMode = PlaybackMode.Play; } else { switch (playbackMode) { case PlaybackMode.Paused: if (rewindTime == 0f) { rewindTime = Tracker.Lifetime; } playbackMode = PlaybackMode.Play; break; case PlaybackMode.Play: case PlaybackMode.Rewind: playbackMode = PlaybackMode.Paused; break; } } } switch (playbackMode) { case PlaybackMode.Rewind: rewindTime += Time.deltaTime; break; case PlaybackMode.Play: rewindTime -= Time.deltaTime; break; } if (Input.GetKey(KeyCode.LeftArrow)) { rewindTime += Time.deltaTime * (Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.RightControl) ? 0.05f : 0.25f); playbackMode = PlaybackMode.Paused; } if (Input.GetKey(KeyCode.RightArrow)) { rewindTime -= Time.deltaTime * (Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.RightControl) ? 0.05f : 0.25f); playbackMode = PlaybackMode.Paused; } if (rewindTime < 0.0f) { rewindTime = 0.0f; playbackMode = PlaybackMode.Paused; } else if (rewindTime > Tracker.Lifetime) { rewindTime = Tracker.Lifetime; playbackMode = PlaybackMode.Paused; } foreach (Tracker t in trackers) { float replayTime = RewindFrame; int currentIndex = (int)Math.Floor(replayTime); StateDescriptor lowerState = t.States[currentIndex]; StateDescriptor upperState = currentIndex < t.States.Length - 1 ? t.States[currentIndex + 1] : lowerState; float percent = replayTime - currentIndex; BRigidBody rb = t.GetComponent <BRigidBody>(); if (!rb.GetCollisionObject().IsActive) { rb.GetCollisionObject().Activate(); } rb.SetPosition(BulletSharp.Math.Vector3.Lerp(lowerState.Position, upperState.Position, percent).ToUnity()); rb.SetRotation(BulletSharp.Math.Matrix.Lerp(lowerState.Rotation, upperState.Rotation, percent).GetOrientation().ToUnity()); } }