// Use this for initialization void OnEnable() { // Add the corresponding motion model GlobalMove globalMove = gameObject.AddComponent<GlobalMove> (); motionModel = globalMove.motionModel; switch (motionModel){ case GlobalControl.motionModels.DISCRETE:{ MonoBehaviour control = globalMove.changeMotionModel(GlobalControl.motionModels.DISCRETE); controller = new PController(control); break; } case GlobalControl.motionModels.KINEMATIC:{ MonoBehaviour control = globalMove.changeMotionModel(GlobalControl.motionModels.KINEMATIC); controller = new PController(control); break; } case GlobalControl.motionModels.DYNAMIC:{ MonoBehaviour control = globalMove.changeMotionModel(GlobalControl.motionModels.DYNAMIC); controller = new PDController(control); break; } case GlobalControl.motionModels.DIFFERENTIAL:{ MonoBehaviour control = globalMove.changeMotionModel(GlobalControl.motionModels.DIFFERENTIAL); controller = new PController(control); break; } case GlobalControl.motionModels.CAR:{ MonoBehaviour control = globalMove.changeMotionModel(GlobalControl.motionModels.CAR); controller = new PController(control); break; } } }
public void changeMotionModel(GlobalControl.motionModels newMotionModel) { GlobalMove globalMove = gameObject.GetComponent<GlobalMove> (); switch (newMotionModel){ case GlobalControl.motionModels.DISCRETE:{ MonoBehaviour control = globalMove.changeMotionModel(GlobalControl.motionModels.DISCRETE); controller = new PController(control); break; } case GlobalControl.motionModels.KINEMATIC:{ MonoBehaviour control = globalMove.changeMotionModel(GlobalControl.motionModels.KINEMATIC); controller = new PController(control); break; } case GlobalControl.motionModels.DYNAMIC:{ MonoBehaviour control = globalMove.changeMotionModel(GlobalControl.motionModels.DYNAMIC); controller = new PDController(control); break; } case GlobalControl.motionModels.DIFFERENTIAL:{ MonoBehaviour control = globalMove.changeMotionModel(GlobalControl.motionModels.DIFFERENTIAL); controller = new PController(control); break; } case GlobalControl.motionModels.CAR:{ MonoBehaviour control = globalMove.changeMotionModel(GlobalControl.motionModels.CAR); controller = new PController(control); break; } } motionModel = newMotionModel; }
public void changeMotionModel(GlobalControl.motionModels newMotionModel) { //Destroy current motion model Destroy (control); //Add new motion model switch (newMotionModel){ case GlobalControl.motionModels.DISCRETE: control = gameObject.AddComponent<MoveDiscrete>(); controller = new PController(control); break; case GlobalControl.motionModels.KINEMATIC: control = gameObject.AddComponent<MoveKinematic>(); controller = new PController(control); break; case GlobalControl.motionModels.DYNAMIC: control = gameObject.AddComponent<MoveDynamic>(); controller = new PDController(control); break; case GlobalControl.motionModels.DIFFERENTIAL: control = gameObject.AddComponent<MoveDifferential>(); controller = new PController(control); break; case GlobalControl.motionModels.CAR: control = gameObject.AddComponent<MoveCar>(); controller = new PController(control); break; } motionModel = newMotionModel; }
public MonoBehaviour changeMotionModel(GlobalControl.motionModels newMotionModel) { //First, remove previous motion model DestroyImmediate (motionComponent); //Add the new motion model switch (newMotionModel){ case GlobalControl.motionModels.DISCRETE: motionComponent = (MonoBehaviour)gameObject.AddComponent<MoveDiscrete>(); break; case GlobalControl.motionModels.KINEMATIC: motionComponent = (MonoBehaviour)gameObject.AddComponent<MoveKinematic>(); break; case GlobalControl.motionModels.DYNAMIC: motionComponent = (MonoBehaviour)gameObject.AddComponent<MoveDynamic>(); break; case GlobalControl.motionModels.DIFFERENTIAL: motionComponent = (MonoBehaviour)gameObject.AddComponent<MoveDifferential>(); break; case GlobalControl.motionModels.CAR: motionComponent = (MonoBehaviour)gameObject.AddComponent<MoveCar>(); break; } motionModel = newMotionModel; return motionComponent; }
GameObject instatiateNewRobot(GameObject prefab,GlobalControl.motionModels _motionModel) { Vector3 currentPosition = currentObject.transform.position; Quaternion currentRotation = currentObject.transform.rotation; //Remove current object DestroyImmediate(currentObject); //Create new one currentObject = (GameObject)Object.Instantiate(prefab,currentPosition,currentRotation); currentObject.name = robotName; currentObject.gameObject.SetActive(true); //Add control script gm = currentObject.gameObject.AddComponent<GlobalMove>(); gm.changeMotionModel (_motionModel); move = currentObject.AddComponent<moveTo> (); move.changeMotionModel (_motionModel); this.motionModel = _motionModel; return currentObject; }
// Use this for initialization void OnEnable() { GlobalMove m = gameObject.GetComponent<GlobalMove> (); motionModel = m.motionModel; }