public void StartATL(SplineLord_one splineLord_one) { LoadText(splineLord_one); //_debugLineLord = GameObject.Find ("DebugLineLord"); //take scroll speed off the accelerometer _offset = new Vector3(0.00025f, 0.0f, 0.00025f); //offset 2nd text right and down from 1st }
public void UpdateATL(PlayerController_one player_one, SplineLord_one splineLord_one) { for (int i = 0; i < _obstacles.Count; i++) { _obstacles [i].UpdateATL(); if (_obstacles[i].DidCollide(player_one.transform.position)) { print("collision"); //collision happening multiple times _obstacles[i].OnCollide(); } } //print (player.t); if (player_one.t > .15f && player_one.t <= .25f && _count < 1) { _count++; //create only one obstacle at this point ... would be easier to base this off markers in the text - TAGS - find what t will be at TAG CreateObstacle(splineLord_one.GetSpline()); } timer += Time.deltaTime; if (timer > 5.0f) { timer = 0.0f; //CreateObstacle(splineLord.GetSpline()); } }
// Update is called once per frame public void UpdateATL(SplineLord_one splineLord_one, BookController bookController) { //print (Input.mouseScrollDelta.y); speed = -Input.mouseScrollDelta.y * _sensitivity; transform.position -= transform.up * _offset.y; _jumpTimer = Mathf.Clamp01(_jumpTimer - Time.deltaTime); if (Input.GetKeyDown(KeyCode.Space) && _jumpTimer <= 0.0f) //getkeydown only true first frame down, getkeyup true first frame released, getkey is true if down and false if up { _jumpTimer = 1.0f; } _offset = new Vector3(0.0f, Mathf.Sin(AxKEasing.EaseOutQuad(0.0f, 1.0f, 1.0f - _jumpTimer) * Mathf.PI), 0.0f); CurvySpline curSpline = splineLord_one.GetSpline(); //this way gets nearest point on spline to current position t = curSpline.GetNearestPointTF(transform.position); t += (speed / curSpline.Length) * Time.deltaTime * 5.0f; transform.position = curSpline.Interpolate(t); //Vector3 sForward = curSpline.GetTangentToSpline( t ); //Vector3 sNormal = curSpline.GetOrientationOnSpline (t); //Quaternion lookRotation = Quaternion.LookRotation (sForward, sNormal); transform.rotation = Quaternion.Slerp(transform.rotation, curSpline.GetOrientationFast(t), Time.deltaTime * 5.0f); transform.position += transform.up * _offset.y; //places player over spline int indexOffset = 4; Vector3 v1 = curSpline.ControlPoints [0 + indexOffset].transform.position - curSpline.ControlPoints [1 + indexOffset].transform.position; Vector3 v2 = transform.position - curSpline.ControlPoints [1 + indexOffset].transform.position; float dot = Vector3.Dot(v1, v2); //print ( (Time.timeSinceLevelLoad % 2.0f).ToString( "F7" ) + " " + ( Time.timeSinceLevelLoad ).ToString( "F5" ) + " " + ( Time.timeSinceLevelLoad / 2.0f ).ToString( "F6") ); if (Time.timeSinceLevelLoad % 2.0f <= 0.1f) // dot < -.2) { //splineLord.CreateControlPoint (); } if (t > .5) { //SplineLord.GenerateSpline(curSpline); } /* * if (t > .5) * { * splineLord.RegisterSpline() (next: get end pt from data stream) * delete last spline * } */ }
// Use this for initialization void Start() { splineLord_one = GameObject.FindObjectOfType <SplineLord_one> (); splineLord_one.StartATL(); player_one = GameObject.FindObjectOfType <PlayerController_one> (); player_one.StartATL(); obstacleLord = GameObject.FindObjectOfType <ObstacleLord> (); obstacleLord.StartATL(); cameraController_one = GameObject.FindObjectOfType <CameraController_one> (); cameraController_one.StartATL(); bookController = GameObject.FindObjectOfType <BookController> (); bookController.StartATL(splineLord_one); }
public void UpdateATL(PlayerController_one player_one, SplineLord_one splineLord_one) { // if (GameObject.Find ("DebugLineLord") != null) // { // _yInput += Input.mouseScrollDelta.y; // //print (_yInput); // // _offset = new Vector3 (0.0f, _yInput * sensitivity, 0.0f); // // //SplineLord splineLord = GameObject.FindObjectOfType< SplineLord > (); // CurvySpline curSpline = splineLord.GetSpline (); // // float t = curSpline.GetNearestPointTF( player_one.transform.position ); //weird to get t back from the player // _debugLineLord.transform.position = curSpline.Interpolate (t + _lead) + _debugLineLord.transform.up * _offset.y; // // _debugLineLord.transform.rotation = Quaternion.Slerp( _debugLineLord.transform.rotation, curSpline.GetOrientationFast( t + _lead ), Time.deltaTime * 5.0f ); // // } if (splineLord_one.GetSpline().IsInitialized&& !_laidOutText) { float tLineSpacing = 1.0F / _lines.Count; // the height of a line _laidOutText = true; for (int i = 0; i < _lines.Count; i++) { Vector3 upAtT = splineLord_one.GetSpline().GetOrientationUpFast(tLineSpacing * i); Vector3 alongSplineAtT = splineLord_one.GetSpline().Interpolate(tLineSpacing * (i + 1.0f)) - splineLord_one.GetSpline().Interpolate(tLineSpacing * i); Vector3 right = Vector3.Cross(alongSplineAtT, upAtT); Vector3 normal2 = Vector3.Cross(right, alongSplineAtT); Vector3 position = splineLord_one.GetSpline().Interpolate(tLineSpacing * i) + upAtT * _rise + right * .3f; Vector3 normal = splineLord_one.GetSpline().GetOrientationUpFast(tLineSpacing * i); normal = Quaternion.AngleAxis(-50.0f, right) * normal; AxKDebugLines.AddText(_lines [i], position, normal, right, upAtT, fontSizeMult, tracking, lineLengthLimit, Color.white, 9999999999999); AxKDebugLines.AddText(_lines [i], position + _offset, normal, right, upAtT, fontSizeMult, tracking, lineLengthLimit, Color.white, 9999999999999); //to make the line thicker AxKDebugLines.AddText(_lines [i], position + _offset * 2.0f, normal, right, upAtT, fontSizeMult, tracking, lineLengthLimit, Color.white, 9999999999999); AxKDebugLines.AddText(_lines [i], position + _offset * 3.0f, normal, right, upAtT, fontSizeMult, tracking, lineLengthLimit, Color.white, 9999999999999); AxKDebugLines.AddText(_lines [i], position + _offset * 4.0f, normal, right, upAtT, fontSizeMult, tracking, lineLengthLimit, Color.white, 9999999999999); } } }
//note: 10-yr-old garbage collector in Unity will run randomly and halt code: boehem gc //solution: don't produce too much garbage OR allocate on stack versus heap OR clear the garbage often (which can also make issues) public void LoadText(SplineLord_one splineLord_one) { string text = ""; //use markdown? for tags: find a markdown parser text = System.IO.File.ReadAllText(Application.dataPath + "/Text/TextTest.xml"); _xmlDocument = new XmlDocument(); _xmlDocument.LoadXml(text); _words = text.Split(' ', '\t', System.Environment.NewLine.ToCharArray()[0]); System.Text.StringBuilder line = new System.Text.StringBuilder(); for (int i = 0; i < _words.Length; i++) { if (line.Length + _words [i].Length + 1 > lineLengthLimit) { _lines.Add(line.ToString()); line.Remove(0, line.Length); } line.Append(_words[i] + " "); //print (_words[ i ]); if (_words [i] == "{testing}") //finds tag in text { print("lol"); } } //if use <>= in text, use special character to escape that code //XmlNodeList pageBreak = _xmlDocument.GetElementsByTagName ("page"); //child of page is text or whatever //monospace font so you can specify the line width //AxKDebugLines.AddText parameters: string text, Vector3 position, Vector3 normal, float size, float length, Color color, float life = 0.0f //to put in the whole chapter //AxKDebugLines.AddText( pageBreak[0].ChildNodes[0].InnerText, transform.position, fontSizeMult, lineLengthLimit, Color.white, 9999999999999 ); }