void UpdateMove() { int rem = 0; for (int i = 0; i < motorUnits.Count; i++) { MotorUnit m = motorUnits[i]; float currentdis = m.CurrentDistance; currentdis += speed * Time.deltaTime; if (currentdis > m.AllDistance && m.id >= keyFrameGameobjects.Count - 1) { rem++; continue; } break; } while (rem > 0) { Destroy(motorUnits[0].moveGameobject); motorUnits.RemoveAt(0); rem--; } if (motorUnits.Count > 0) { float newdis = motorUnits[0].AllDistance - motorUnits[0].CurrentDistance - speed * Time.deltaTime; if (newdis < 0) { motorUnits[0].id++; motorUnits[0].start = keyFrameGameobjects[motorUnits[0].id - 1]; motorUnits[0].end = keyFrameGameobjects[motorUnits[0].id]; motorUnits[0].CurrentDistance = Mathf.Abs(newdis); } else { motorUnits[0].CurrentDistance += speed * Time.deltaTime; } } if (motorUnits.Count > 1) { for (int i = 1; i < motorUnits.Count; i++) { TargetCreatPara para = GetKeyFrameID(motorUnits[i - 1], distance); if (para.id > 0) { motorUnits[i].id = para.id; motorUnits[i].start = keyFrameGameobjects[para.id - 1]; motorUnits[i].end = keyFrameGameobjects[para.id]; motorUnits[i].CurrentDistance = para.distance; } } } }
void CreatElement() { if (templetGameobject == null) { return; } if (motorUnits.Count == 0) { GameObject game = Object.Instantiate <GameObject>(templetGameobject); if (parentGo != null) { game.transform.parent = parentGo.transform; } MotorUnit mu = new MotorUnit(); mu.moveGameobject = game; mu.start = keyFrameGameobjects[0]; mu.end = keyFrameGameobjects[1]; mu.CurrentDistance = 0; mu.id = 1; motorUnits.Add(mu); } else { int i = 10; while (i > 1) { MotorUnit father = motorUnits[motorUnits.Count - 1]; TargetCreatPara para = GetKeyFrameID(father, distance); if (para.id > 0) { GameObject game = Object.Instantiate <GameObject>(templetGameobject); GameObject parentGo = GameObject.Find("SLFather"); if (parentGo != null) { game.transform.parent = parentGo.transform; } MotorUnit mu = new MotorUnit(); mu.moveGameobject = game; mu.start = keyFrameGameobjects[para.id - 1]; mu.end = keyFrameGameobjects[para.id]; mu.CurrentDistance = para.distance; mu.id = para.id; motorUnits.Add(mu); } i = para.id; } // print("CreatElement__11"); } }
MotorUnit CreatMotorUnit(GameObject game, int index) { MotorUnit mu = new MotorUnit(); try { mu.id = index; mu.moveGameobject = game; mu.start = keyFrameGameobjects[mu.id - 1]; mu.end = keyFrameGameobjects[mu.id]; mu.CurrentDistance = 0; return(mu); } catch (System.Exception e) { return(null); } }
void ZMJIniSL() { int ladder = 0; string elementName = "SSLL"; if (elementName == null || elementName == "") { return; } for (int i = 0; i < Fuzhi.mounts * 6; i++) { GameObject game = GameObject.Find(elementName + i); if (game == null) { continue; } Vector3 gameposition = game.transform.position; for (int k = ladder; k < keyFrameGameobjects.Count - 1; k++) { Vector3 position1 = keyFrameGameobjects[k].transform.position; Vector3 position2 = keyFrameGameobjects[k + 1].transform.position; if (Vector3.Dot(position1 - gameposition, position2 - gameposition) < 0.1) { MotorUnit pair = new MotorUnit(); pair.id = k + 1; pair.start = keyFrameGameobjects[k]; pair.end = keyFrameGameobjects[k + 1]; pair.moveGameobject = game; pair.CurrentDistance = 0; motorUnits.Add(pair); ladder = k; break; } } } List <MotorUnit> list = new List <MotorUnit>(); for (int i = motorUnits.Count - 1; i >= 0; i--) { list.Add(motorUnits[i]); } motorUnits = list; }
void CreatElement() { if (templetGameobject == null) { return; } if (motorUnits.Count == 0) { CreatFirst(); } else { if (playMode == PlayMode.FixedDistance) { int i = 10; while (i > 1) { MotorUnit father = motorUnits[motorUnits.Count - 1]; TargetCreatPara para = GetKeyFrameID(father, distance); if (para.id > 0) { GameObject game = UnityEngine.Object.Instantiate <GameObject>(templetGameobject); MotorUnit mu = new MotorUnit(); mu.moveGameobject = game; mu.start = keyFrameGameobjects[para.id - 1]; mu.end = keyFrameGameobjects[para.id]; mu.CurrentDistance = para.distance; mu.id = para.id; motorUnits.Add(mu); } i = para.id; } } if (playMode == PlayMode.FixedCreatSpeed) { if (Time.time - creatTime > creatSpeed) { creatTime = Time.time; CreatFirst(); } } } }
private void Update() { if (SSLLJ && IsSSLL) { speed = 0; if (once) { once = false; MotorUnit mu = new MotorUnit(); mu.id = keyFrameGameobjects.Count - 1; mu.moveGameobject = templetGameobject; mu.start = keyFrameGameobjects[keyFrameGameobjects.Count - 2]; mu.end = keyFrameGameobjects[keyFrameGameobjects.Count - 1]; mu.CurrentDistance = 0; } if (playing) { CreatElement(); UpdateMove(); } } else if (IsSSLL) { while (motorUnits.Count > 0) { Destroy(motorUnits[0].moveGameobject); motorUnits.RemoveAt(0); } } else { if (playing) { CreatElement(); UpdateMove(); } } }
TargetCreatPara GetKeyFrameID(MotorUnit m, float dis) { float dist = m.CurrentDistance - dis; int rid = m.id; if (dist > 0) { return(new TargetCreatPara(m.id, dist)); } else { while (dist < 0) { rid--; if (rid < 1) { return(new TargetCreatPara(-1, dis)); } dist += (keyFrameGameobjects[rid].transform.position - keyFrameGameobjects[rid - 1].transform.position).magnitude; } return(new TargetCreatPara(rid, dist)); } }
void DestroyGameobject() { int rem = 0; for (int i = 0; i < motorUnits.Count; i++) { MotorUnit m = motorUnits[i]; float currentdis = m.CurrentDistance; currentdis += speed * Time.deltaTime; if (currentdis > m.AllDistance && m.id >= keyFrameGameobjects.Count - 1) { rem++; continue; } break; } while (rem > 0) { GameObject.Destroy(motorUnits[0].moveGameobject); motorUnits.RemoveAt(0); rem--; } }
void RefreshPostionAndRotateByID(MotorUnit m) { //m. }
public void InitializeTemplet() { singleGame = CreatMotorUnit(templetGameobject, 1); }