private void ActionThree() { RightWheel.Stop(); LeftWheel.Stop(); MoveForward(); _actionNotification?.Invoke(); }
private void ActionTwo() { RightWheel.Stop(); LeftWheel.Stop(); MoveBack(); _actionNotification?.Invoke(); }
/// <summary> /// Update physical car (transform, properties, scale of game objects) from variables. /// </summary> public void UpdateFromVariables() { // Apply values from dictionary LeftWheelRadius = GenesToValues[GeneType.LeftWheelRadius]; RightWheelRadius = GenesToValues[GeneType.RightWheelRadius]; LeftWheelPosition = new Vector2(GenesToValues[GeneType.LeftWheelPosX], GenesToValues[GeneType.LeftWheelPosY]); RightWheelPosition = new Vector2(GenesToValues[GeneType.RightWheelPosX], GenesToValues[GeneType.RightWheelPosY]); Speed = GenesToValues[GeneType.Speed]; BaseDimensions = new Vector2(GenesToValues[GeneType.BaseDimensionsX], GenesToValues[GeneType.BaseDimensionsY]); // Reset transform BaseOfCar.transform.localPosition = Vector3.zero; BaseOfCar.transform.localRotation = Quaternion.Euler(Vector3.zero); // Apply values to base. //BaseDimensions.x *= 2f; // TO HELP FIX THE CAR JUST BEING WHEELS BaseOfCar.transform.localScale = new Vector3(BaseDimensions.x, BaseDimensions.y, 1f); Vector2 sizeOfBase = new Vector2(BaseOfCar.GetComponent <BoxCollider2D>().size.x *BaseOfCar.transform.localScale.x, BaseOfCar.GetComponent <BoxCollider2D>().size.y *BaseOfCar.transform.localScale.y); // Apply values to left wheel LeftWheel.transform.localScale = new Vector3(LeftWheelRadius, LeftWheelRadius, 1f); var leftWheelPos = new Vector2( Mathf.Clamp01(LeftWheelPosition.x) - 0.5f, Mathf.Clamp01(LeftWheelPosition.y) - 0.5f); leftWheelPos.x *= (sizeOfBase.x); leftWheelPos.y *= (sizeOfBase.y); LeftWheel.transform.localPosition = new Vector3(leftWheelPos.x, leftWheelPos.y, 1f); // Apply values to right wheel RightWheel.transform.localScale = new Vector3(RightWheelRadius, RightWheelRadius, 1f); var rightWheelPos = new Vector2( Mathf.Clamp01(RightWheelPosition.x) - 0.5f, Mathf.Clamp01(RightWheelPosition.y) - 0.5f); rightWheelPos.x *= (sizeOfBase.x); rightWheelPos.y *= (sizeOfBase.y); RightWheel.transform.localPosition = new Vector3(rightWheelPos.x, rightWheelPos.y, 1f); // Apply speed values to left and right wheels. var newMotor = new JointMotor2D { maxMotorTorque = 1000000f, motorSpeed = Speed }; LeftWheel.GetComponent <HingeJoint2D>().useMotor = true; LeftWheel.GetComponent <HingeJoint2D>().motor = newMotor; RightWheel.GetComponent <HingeJoint2D>().useMotor = true; RightWheel.GetComponent <HingeJoint2D>().motor = newMotor; }
TankInitSystem InitTankPrefabs() { #region Collision Detect if (vehicleData.modelData.MainModel.GetComponentsInChildren <BoxCollider>().Length == 0) { if (EditorUtility.DisplayDialog("Error", "Collision should be set.We will redirct you to it.", "OK,l will set it now!", "No,l will choose another one")) { EditorGUIUtility.PingObject(vehicleData.modelData.MainModel.GetInstanceID()); OpenEditorScene(); GameObject EditColliderInstance = Instantiate <GameObject>(vehicleData.modelData.MainModel); EditColliderInstance.name = vehicleData.modelData.MainModel.name; string TempPath = System.IO.Path.GetDirectoryName(AssetDatabase.GetAssetPath(vehicleData.modelData.MainModel.GetInstanceID())); string PrefabStoreDir = System.IO.Directory.CreateDirectory(string.Format(TempPath + "/Collisions_{0}", vehicleData.modelData.MainModel.name)).FullName; AssetDatabase.Refresh(); return(null); //PrefabUtility.CreatePrefab (string.Format (PrefabStoreDir + "/{0}.prefab", vehicleData.modelData.MainModel.name),EditColliderInstance); } else { return(null); } } #endregion GameObject TankPrefabs = new GameObject(); GameObject InstanceMesh = Instantiate(vehicleData.modelData.MainModel); try { #region Init InstanceMesh.name = vehicleData.modelData.MainModel.name; #endregion TankPrefabs.name = InstanceMesh.name + "_Pre"; InstanceMesh.transform.parent = TankPrefabs.transform; GameObject TankTransform = new GameObject("TankTransform"); TankTransform.transform.parent = InstanceMesh.transform; Transform RightWheel, LeftWheel, RightUpperWheels, LeftUpperWheels, Turret, Gun, GunDym; #region Find Dumps RightWheel = InstanceMesh.transform.Find("RightWheel"); LeftWheel = InstanceMesh.transform.Find("LeftWheel"); Turret = InstanceMesh.transform.Find("Turret"); Gun = Turret.transform.Find("Gun"); GunDym = Gun.GetChild(0); RightUpperWheels = InstanceMesh.transform.Find("RightUpperWheel"); LeftUpperWheels = InstanceMesh.transform.Find("LeftUpperWheel"); #endregion RightWheel.parent = TankTransform.transform; LeftWheel.parent = TankTransform.transform; LeftUpperWheels.parent = TankTransform.transform; RightUpperWheels.parent = TankTransform.transform; GameObject TurretTransform = new GameObject("TurretTransform"); GameObject GunTransform = new GameObject("GunTransform"); GameObject GunDymTransform = new GameObject("GunDym"); VehicleComponentsReferenceManager referenceManager = InstanceMesh.AddComponent <VehicleComponentsReferenceManager>(); TurretTransform.transform.SetParent(InstanceMesh.transform); TurretTransform.transform.position = Turret.transform.position; GunTransform.transform.position = Gun.transform.position; Turret.parent = TurretTransform.transform; Gun.parent = GunTransform.transform; GunTransform.transform.SetParent(TurretTransform.transform); GunDymTransform.transform.position = GunDym.transform.position; GunDymTransform.transform.SetParent(GunTransform.transform); GunDym.SetParent(GunDymTransform.transform); #region Add fire animation Animator FireAnimator = GunDymTransform.AddComponent <Animator>(); FireAnimator.runtimeAnimatorController = vehicleData.vehicleTextData.TFParameter.GymAnimation; #endregion AddDumpNode("FFPoint", GunTransform.transform, true, referenceManager); AddDumpNode("EffectStart", GunTransform.transform, true, referenceManager); AddDumpNode("FireForceFeedbackPoint", GunTransform.transform, true, referenceManager); AddDumpNode("EngineSmoke", InstanceMesh.transform, true, referenceManager); AddDumpNode("EngineSound", InstanceMesh.transform, true, referenceManager); AddDumpNode("MainCameraFollowTarget", InstanceMesh.transform, true, referenceManager); AddDumpNode("MainCameraGunner", GunTransform.transform, true, referenceManager); AddDumpNode("MachineGunFFPoint", TurretTransform.transform, true, referenceManager); AddDumpNode("CenterOfGravity", InstanceMesh.transform, true, referenceManager); referenceManager.LeftTrack = InstanceMesh.transform.Find("LeftTrack").gameObject; referenceManager.RightTrack = InstanceMesh.transform.Find("RightTrack").gameObject; GameObject HitBoxInstance = Instantiate <GameObject>(vehicleData.modelData.HitBox.HitBoxPrefab); HitBoxInstance.transform.Find("Main").name = "MainHitBox"; HitBoxInstance.transform.Find("MainHitBox").SetParent(InstanceMesh.transform); HitBoxInstance.transform.Find("Turret").name = "TurretHitBox"; HitBoxInstance.transform.Find("TurretHitBox").SetParent(TurretTransform.transform); HitBoxInstance.transform.Find("Gun").name = "GunHitBox"; HitBoxInstance.transform.Find("GunHitBox").SetParent(GunTransform.transform); HitBoxInstance.transform.Find("Dym").name = "DymHitBox"; HitBoxInstance.transform.Find("DymHitBox").SetParent(GunDymTransform.transform); DestroyImmediate(HitBoxInstance); Restore(LeftWheel.GetComponentsInChildren <Transform>()); Restore(RightWheel.GetComponentsInChildren <Transform>()); Restore(LeftUpperWheels.GetComponentsInChildren <Transform>()); Restore(RightUpperWheels.GetComponentsInChildren <Transform>()); new GameObject("MainCameraTarget").transform.SetParent(TurretTransform.transform); TankInitSystem initySystem = TankPrefabs.AddComponent <TankInitSystem>(); initySystem.PSParameter = vehicleData.vehicleTextData.PSParameter; initySystem.TFParameter = vehicleData.vehicleTextData.TFParameter; initySystem.MTParameter = vehicleData.vehicleTextData.MTParameter; initySystem.PTCParameter = vehicleData.vehicleTextData.PTCParameter; return(initySystem); } catch (System.Exception exception) { EditorUtility.DisplayDialog("Exception", exception.Message + "\n" + exception.StackTrace, "OK"); DestroyImmediate(TankPrefabs); throw exception; return(null); } }
TankInitSystem InitTankPrefabs() { #region 碰撞检测 if (vehicleData.modelData.MainModel.GetComponentsInChildren <BoxCollider> ().Length == 0) { if (EditorUtility.DisplayDialog("错误", "坦克模型必须设置完毕碰撞数据", "好的,立刻去设置", "重新选择资源")) { EditorGUIUtility.PingObject(vehicleData.modelData.MainModel.GetInstanceID()); OpenEditorScene(); GameObject EditColliderInstance = Instantiate <GameObject> (vehicleData.modelData.MainModel); EditColliderInstance.name = vehicleData.modelData.MainModel.name; string TempPath = System.IO.Path.GetDirectoryName(AssetDatabase.GetAssetPath(vehicleData.modelData.MainModel.GetInstanceID())); string PrefabStoreDir = System.IO.Directory.CreateDirectory(string.Format(TempPath + "/Collisions_{0}", vehicleData.modelData.MainModel.name)).FullName; AssetDatabase.Refresh(); //PrefabUtility.CreatePrefab (string.Format (PrefabStoreDir + "/{0}.prefab", vehicleData.modelData.MainModel.name),EditColliderInstance); } else { return(null); } } #endregion #region 初始化 坦克物体变量 GameObject TankPrefabs = new GameObject(); GameObject InstanceMesh = Instantiate(vehicleData.modelData.MainModel); InstanceMesh.name = vehicleData.modelData.MainModel.name; #endregion TankPrefabs.name = InstanceMesh.name + "_Pre"; InstanceMesh.transform.parent = TankPrefabs.transform; GameObject TankTransform = new GameObject("TankTransform"); TankTransform.transform.parent = InstanceMesh.transform; Transform RightWheel, LeftWheel, RightUpperWheels, LeftUpperWheels, Turret, Gun, GunDym; #region 在模型上寻找虚拟对象 RightWheel = InstanceMesh.transform.Find("RightWheel"); LeftWheel = InstanceMesh.transform.Find("LeftWheel"); Turret = InstanceMesh.transform.Find("Turret"); Gun = Turret.transform.Find("Gun"); GunDym = Gun.GetChild(0); RightUpperWheels = InstanceMesh.transform.Find("RightUpperWheel"); LeftUpperWheels = InstanceMesh.transform.Find("LeftUpperWheel"); #endregion RightWheel.parent = TankTransform.transform; LeftWheel.parent = TankTransform.transform; LeftUpperWheels.parent = TankTransform.transform; RightUpperWheels.parent = TankTransform.transform; #region 实例化坦克的附加物体 坦克控制器 坦克脚本 坦克ui 坦克瞄准镜 主摄像机 坦克引擎声音 坦克引擎烟雾 死亡效果 //EngineSmoke = new GameObject("EngineSmoke"); //LeftTrackEffect = new GameObject("LeftTrackEffect"); //RightTrackEffect=new GameObject("RightTrackEffect"); #endregion GameObject TurretTransform = new GameObject("TurretTransform"); GameObject GunTransform = new GameObject("GunTransform"); GameObject GunDymTransform = new GameObject("GunDym"); VehicleComponentsReferenceManager referenceManager = InstanceMesh.AddComponent <VehicleComponentsReferenceManager>(); //GameObject MainHitBox = new GameObject ("MainHitBox"); //GameObject TurretHitBox = new GameObject ("TurretHitBox"); TurretTransform.transform.SetParent(InstanceMesh.transform); TurretTransform.transform.position = Turret.transform.position; GunTransform.transform.position = Gun.transform.position; Turret.parent = TurretTransform.transform; Gun.parent = GunTransform.transform; GunTransform.transform.SetParent(TurretTransform.transform); GunDymTransform.transform.position = GunDym.transform.position; GunDymTransform.transform.SetParent(GunTransform.transform); GunDym.SetParent(GunDymTransform.transform); #region 发射动画 Animator FireAnimator = GunDymTransform.AddComponent <Animator> (); FireAnimator.runtimeAnimatorController = vehicleData.vehicleTextData.TFParameter.GymAnimation; #endregion AddDumpNode("FFPoint", GunTransform.transform, true, referenceManager); AddDumpNode("EffectStart", GunTransform.transform, true, referenceManager); AddDumpNode("FireForceFeedbackPoint", InstanceMesh.transform, true, referenceManager); AddDumpNode("EngineSmoke", InstanceMesh.transform, true, referenceManager); AddDumpNode("EngineSound", InstanceMesh.transform, true, referenceManager); AddDumpNode("MainCameraFollowTarget", InstanceMesh.transform, true, referenceManager); AddDumpNode("MainCameraGunner", GunTransform.transform, true, referenceManager); AddDumpNode("MachineGunFFPoint", TurretTransform.transform, true, referenceManager); AddDumpNode("CenterOfGravity", InstanceMesh.transform, true, referenceManager); //MainHitBox.transform.parent = TankModel.transform; //TurretHitBox.transform.parent = TurretTransform.transform; //EngineSmoke.transform.parent = TankModel.transform; //EngineSmoke.tag = "EngineSmoke"; // GameObject LODMesh = new GameObject ("LODMesh"); // LODMesh.transform.SetParent (TankModel.transform); // LODMesh.tag = "LODMesh"; GameObject HitBoxInstance = Instantiate <GameObject> (vehicleData.modelData.HitBox.HitBoxPrefab); HitBoxInstance.transform.Find("Main").name = "MainHitBox"; HitBoxInstance.transform.Find("MainHitBox").SetParent(InstanceMesh.transform); HitBoxInstance.transform.Find("Turret").name = "TurretHitBox"; HitBoxInstance.transform.Find("TurretHitBox").SetParent(TurretTransform.transform); HitBoxInstance.transform.Find("Gun").name = "GunHitBox"; HitBoxInstance.transform.Find("GunHitBox").SetParent(GunTransform.transform); HitBoxInstance.transform.Find("Dym").name = "DymHitBox"; HitBoxInstance.transform.Find("DymHitBox").SetParent(GunDymTransform.transform); DestroyImmediate(HitBoxInstance); //HitBoxInstance.transform.Find("Dym").SetParent() Restore(LeftWheel.GetComponentsInChildren <Transform> ()); Restore(RightWheel.GetComponentsInChildren <Transform> ()); Restore(LeftUpperWheels.GetComponentsInChildren <Transform> ()); Restore(RightUpperWheels.GetComponentsInChildren <Transform> ()); new GameObject("MainCameraTarget").transform.SetParent(TurretTransform.transform); TankInitSystem initySystem = TankPrefabs.AddComponent <TankInitSystem>(); initySystem.PSParameter = vehicleData.vehicleTextData.PSParameter; initySystem.TFParameter = vehicleData.vehicleTextData.TFParameter; initySystem.MTParameter = vehicleData.vehicleTextData.MTParameter; initySystem.PTCParameter = vehicleData.vehicleTextData.PTCParameter; return(initySystem); }
public void MoveLeft() { RightWheel.Stop(); LeftWheel.MoveForward(); }
public void MoveBack() { RightWheel.MoveBack(); LeftWheel.MoveBack(); }
public void MoveForwardMaxPower() { RightWheel.MoveForwardMaxPower(); LeftWheel.MoveForwardMaxPower(); }