void recalculateState() { string[] instruction = _ip.nextIns(); bool one_time_animation = false; if (instruction == null) { return; } else if (instruction[0] == Compiler.EOP) { return; } else if (Library.isSensingLibFunc(instruction[0])) { gameObject.GetComponent <SensingLib>().execute(instruction); time = 0; recalculateState(); return; } else { execute(instruction); } counter = 0; }
void resetSpawnPoint(int index) { spawnObj = Data.objects[index]; string code = null; if (code == null) { code = spawnObj.GetComponent <MainObject>().script; } Compiler.setCode(code); Compiler.compile(); Interpretor _ip = new Interpretor(); _ip.setICode(Compiler.getICode()); _ip.init(); string[] ins = _ip.nextIns(); while ((ins) != null && ins[0] != Compiler.EOP) { if (ins[0] == "movement") { if (ins[1].Replace("\"", "") == "false") { Data.movementFlag = false; } } ins = _ip.nextIns(); RCLog.append(ins[0]); } Vector3 distAboveGround = new Vector3(0, 3, 0); if (Data.vrEnabled) { VRPlayer.transform.position = spawnObj.transform.position + distAboveGround; } else { player.transform.position = spawnObj.transform.position + distAboveGround; } spawnObj.SetActive(false); }
public void generate(string code) { string[] func; //track variable information //initializing compiler and compiling code.// //parse the whole code. Compiler.setCode(code); if (!(Compiler.compile())) { return; } //interpretor setup and initilisation// _ip = new Interpretor(); _ip.setICode(Compiler.getICode()); _ip.init(); //each track instruction is provided while ((func = _ip.nextIns()) != null) { string __st = func[0]; if (errorFlag) { break; } else if (__st == Compiler.EOP) { if (wallFlag) { executeWall(); } break; } else if (__st == "place") { placeObject(func); } else if (__st == "drawline") { drawLine(func); } else if (__st == "setposition") { setPosition(func); } else if (__st == "wall") { wallFlag = true; addWall(func); } } }
//generates track and stores those objects public void generate(string code) { string[] track; //track variable information //initializing compiler and compiling code.// Compiler.setCode(code); Compiler.compile(); //interpretor setup and initilisation// _ip = new Interpretor(); _ip.setICode(Compiler.getICode()); _ip.init(); rg = new WallGenerator(this); path = new GameObject("path"); rg.setPath(path); //parse the whole code. Compiler.setCode(code); if (!(Compiler.compile())) { return; } //Debug.Log("track generation sarted-------------------"); //Debug.Log("s:" + speed_points + ",p:" + points_per_track); //each track instruction is provided while ((track = _ip.nextIns()) != null) { string __st = track[0]; if (__st == Compiler.EOP) { break; } else if (__st == "wall") { wallFunc(track); } } load(); }
//The new state of the animal is updated based on the code. All the variables are// //updated according to the state.// private void recalculateState() { if (state == -1) { return; } string[] instruction = _ip.nextIns(); rotation = 0; move_dir = 1; bool flag = false; reset(); bool one_time_animation = false; if (instruction == null) { if (state == 0) { return; } state = 0; } else if (instruction[0] == Compiler.EOP) { if (state == 0) { return; } state = 0; } else if (instruction[0] == "idle") { //bird has idle state on ground and sky if (bird_state == BirdState.LAND) { state = 0; } else { state = 60; } time = float.Parse(instruction[1]); } else if ((instruction[0] == "walk" || instruction[0] == "walkback") && bird_state == BirdState.LAND) { state = 1; float length = float.Parse(instruction[1]); //length of track for a statement Direction direction = getDirection(instruction[2]); //direction of a statement rotation = float.Parse(instruction[3]); //angle read from statememnt time = length / stats.walk_speed; rot_factor = 1; if (direction == Direction.LEFT) { rot_factor = -1; } else if (direction == Direction.FORWARD) { rot_factor = 0; } if (direction == Direction.BACKWARD) { state = 7; move_dir = -1; } //-Debug.Log("rotation:" + rotation); } //else if (instruction[0] == "run" && bird_state == BirdState.LAND) //{ // state = 2; // float length = float.Parse(instruction[1]); //length of track for a statement // Direction direction = getDirection(instruction[2]); //direction of a statement // rotation = float.Parse(instruction[3]); //angle read from statememnt // time = length / stats.run_speed; // rot_factor = 1; // if (direction == Direction.LEFT) rot_factor = -1; // else if (direction == Direction.FORWARD) rot_factor = 0; //} //else if (instruction[0] == "turn" ) //{ // Direction direction = getDirection(instruction[2]); //direction of a statement // rotation = float.Parse(instruction[3]); //angle read from statememnt // rot_factor = 1; // if (direction == Direction.LEFT) rot_factor = -1; // else if (direction == Direction.FORWARD) rot_factor = 0; //} else if ((instruction[0] == "fly" || instruction[0] == "glide") && bird_state == BirdState.FLY) { if (instruction[0] == "fly") { state = 60; } else if (instruction[0] == "glide") { state = 59; } heli_up = 0; bird_state = BirdState.FLY; float length = float.Parse(instruction[1]); //length of track for a statement Direction direction = getDirection(instruction[2]); //direction of a statement rotation = float.Parse(instruction[3]); //angle read from statememnt time = length / stats.run_speed; rot_factor = 1; if (direction == Direction.LEFT) { rot_factor = -1; } else if (direction == Direction.FORWARD) { rot_factor = 0; } else if (direction == Direction.BACKWARD) { state = 7; move_dir = -1; rot_factor = 0; } else if (direction == Direction.UP) { heli_up = 1; } else if (direction == Direction.DOWN) { heli_up = -1; } } else if (instruction[0] == "land" && bird_state == BirdState.FLY) { state = 60; bird_state = BirdState.LANDING; } else if (instruction[0] == "takeoff" && bird_state == BirdState.LAND) { state = 57; time = 0.67f; bird_state = BirdState.FLY; } if (state < 0) { anim.SetInteger("state", 0); anim.SetTrigger("makeTransition"); } else { anim.SetInteger("state", state); anim.SetTrigger("makeTransition"); } if (one_time_animation) { //UnityEditor.Animations.AnimatorController ac = anim.runtimeAnimatorController as UnityEditor.Animations.AnimatorController; //UnityEditor. //ac.GetStateEffectiveMotion(0); if (state == 41) { time = 7.3f; } else if (state == 42) { time = 4.83f; } else if (state == 43) { time = 3.33f; } if (!flag) { time = anim.GetCurrentAnimatorStateInfo(0).length; } } }
//The new state of the animal is updated based on the code. All the variables are// //updated according to the state.// private void recalculateState() { if (state == -1) { return; } string[] instruction = _ip.nextIns(); rotation = 0; move_dir = 1; bool flag = false; reset(); bool one_time_animation = false; if (instruction == null) { if (state == 0) { return; } state = 0; } else if (instruction[0] == Compiler.EOP) { if (state == 0) { return; } state = 0; } else if (Library.isSensingLibFunc(instruction[0])) { gameObject.GetComponent <SensingLib>().execute(instruction); time = 0; recalculateState(); return; } else if (instruction[0] == "raycast") { raycast(instruction); time = 0; recalculateState(); return; } else if (instruction[0] == "collidercoords") { getColliderLocation(instruction); time = 0; recalculateState(); return; } else if (instruction[0] == "collidertype") { getColliderType(instruction); time = 0; recalculateState(); return; } else if (instruction[0] == "colliderangle") { getColliderAngle(instruction); time = 0; recalculateState(); return; } else if (instruction[0] == "releasecollider") { releaseCollider(); time = 0; recalculateState(); return; } else if (instruction[0] == "setspeed") { setSpeed(instruction); time = 0; recalculateState(); return; } else if (instruction[0] == "getposition") { getPosition(instruction); time = 0; recalculateState(); return; } else if (instruction[0] == "getangle") { getAngleY(instruction); time = 0; recalculateState(); return; } else if (instruction[0] == "setposition") { setPosition(instruction); time = 0; recalculateState(); return; } else if (instruction[0] == "anglebtw2obj") { getAngleBtw2Obj(instruction); time = 0; recalculateState(); return; } else if (instruction[0] == "follow") { //if(instruction[1] == "attack") { follow_mode = true; vision.enabled = true; } //else if (instruction[1] == "eat") { eat_trigger = true; } } else if (instruction[0] == "idle") { state = 0; time = float.Parse(instruction[1]); } else if (instruction[0] == "walk" || instruction[0] == "walkback") { state = 1; float length = float.Parse(instruction[1]); //length of track for a statement Direction direction = getDirection(instruction[2]); //direction of a statement rotation = float.Parse(instruction[3]); //angle read from statememnt time = length / stats.walk_speed; rot_factor = 1; if (direction == Direction.LEFT) { rot_factor = -1; } else if (direction == Direction.FORWARD) { rot_factor = 0; } if (direction == Direction.BACKWARD) { state = 7; move_dir = -1; } //-Debug.Log("rotation:" + rotation); } else if (instruction[0] == "run") { state = 2; float length = float.Parse(instruction[1]); //length of track for a statement Direction direction = getDirection(instruction[2]); //direction of a statement rotation = float.Parse(instruction[3]); //angle read from statememnt time = length / stats.run_speed; rot_factor = 1; if (direction == Direction.LEFT) { rot_factor = -1; } else if (direction == Direction.FORWARD) { rot_factor = 0; } } else if (instruction[0] == "turn") { Direction direction = getDirection(instruction[2]); //direction of a statement rotation = float.Parse(instruction[3]); //angle read from statememnt rot_factor = 1; if (direction == Direction.LEFT) { rot_factor = -1; } else if (direction == Direction.FORWARD) { rot_factor = 0; } } else if (instruction[0] == "roar") { state = 4; one_time_animation = true; playAudio("roar"); } else if (instruction[0] == "attack") { state = 5; one_time_animation = true; } else if (instruction[0] == "sleep") { state = 6; time = float.Parse(instruction[1]); } else if (instruction[0] == "eat") { state = 8; time = float.Parse(instruction[1]); } else if (instruction[0] == "jump") { state = 9; } else if (instruction[0] == "move") { state = 1; heli_up = 0; float length = float.Parse(instruction[1]); //length of track for a statement Direction direction = getDirection(instruction[2]); //direction of a statement rotation = float.Parse(instruction[3]); //angle read from statememnt time = length / stats.walk_speed; rot_factor = 1; if (direction == Direction.LEFT) { rot_factor = -1; } else if (direction == Direction.FORWARD) { rot_factor = 0; } else if (direction == Direction.BACKWARD) { state = 7; move_dir = -1; } else if (direction == Direction.UP) { heli_up = 1; } else if (direction == Direction.DOWN) { heli_up = -1; } } else if (instruction[0].Contains("b_")) { state = boyFunctions(instruction, out flag); one_time_animation = true; flag = true; } else if (instruction[0].Contains("p_")) { //bool flag; state = princessFunctions(instruction, out flag); one_time_animation = true; flag = true; } else if (instruction[0].Contains("r_")) { //bool flag; state = roboFunctions(instruction, out flag); one_time_animation = true; flag = true; } else if (instruction[0].Contains("s_")) { //bool flag; state = snowmanFunctions(instruction, out flag); one_time_animation = true; flag = true; } else if (instruction[0].Contains("z_")) { //bool flag; state = zombieFunctions(instruction, out flag); one_time_animation = true; flag = true; } /*else if(instruction[0] == "collision") * { * collisionHandler(instruction[1]); * * }*/ if (state < 0) { anim.SetInteger("state", 0); anim.SetTrigger("makeTransition"); } else { anim.SetInteger("state", state); anim.SetTrigger("makeTransition"); } if (one_time_animation) { //UnityEditor.Animations.AnimatorController ac = anim.runtimeAnimatorController as UnityEditor.Animations.AnimatorController; //UnityEditor. //ac.GetStateEffectiveMotion(0); if (state == 41) { time = 7.3f; } else if (state == 42) { time = 4.83f; } else if (state == 43) { time = 3.33f; } if (!flag) { time = anim.GetCurrentAnimatorStateInfo(0).length; } } }