private void Update() { if (car == null) { car = GetComponent <CarInfo>().carStats; } }
void Start() { CS = CarStats.instance; input = PlayerInput.instance; rend = GetComponent <Renderer>(); rend.enabled = false; }
public ChampionshipPromotionData(Team inTeam, Championship inPreviousChampionship, ChampionshipPromotionData.TeamStatus inStatus, CarStats inStats) { this.team = inTeam; this.teamStatus = inStatus; this.previousChampionship = inPreviousChampionship; this.teamPreviousChampPartStatRankings = inStats; }
public void Initialize(string name, Car_SO car) { this.name = name; this.car = car; for (int i = 0; i < transform.childCount; i++) { GameObject child = transform.GetChild(i).gameObject; Destroy(child); } Instantiate(car.planePrefab, transform); var capsuleCollider = GetComponent <CapsuleCollider>(); capsuleCollider.radius = car.capsuleColliderRadius; capsuleCollider.height = car.capsuleColliderLength; carStats = new CarStats(car.specs.durability, car.specs.fuel, car.specs.fuelRate, this); movementScript.player = this; movementScript.SetSpecs(car.specs); movementScript.SetControls(controls); groundCollidersTouching = 0; AudioManager.Instance.Play(driveSound); }
public void CheckForValidCarStats() { if (carStats == null) { carStats = Instantiate(baseCarStats); carStats.name = gameObject.name + " Car Stats"; } }
public void PreviewStatDisplay() { CarComponent component = BuildController.GetComponent(_selectedBlock); CarStats previewStats = UpdateCarStats(component, carStats, true); float accelerationDif = previewStats.acceleration - carStats.acceleration; string acceleration = accelerationDif.ToString(); if (accelerationDif > 0f) { acceleration = acceleration.Insert(0, "+"); } if (acceleration.Length > previewStatDisplayLength) { acceleration = acceleration.Substring(0, previewStatDisplayLength); } PaccelerationText.SetText(acceleration); float speedDif = previewStats.maxSpeed - carStats.maxSpeed; string speed = speedDif.ToString(); if (speedDif > 0f) { speed = speed.Insert(0, "+"); } if (speed.Length > previewStatDisplayLength) { speed = speed.Substring(0, previewStatDisplayLength); } PspeedText.SetText(speed); float breakSpeedDif = previewStats.breakSpeed - carStats.breakSpeed; string breakSpeed = breakSpeedDif.ToString(); if (breakSpeedDif > 0f) { breakSpeed = breakSpeed.Insert(0, "+"); } if (breakSpeed.Length > previewStatDisplayLength) { breakSpeed = breakSpeed.Substring(0, previewStatDisplayLength); } PbreakSpeedText.SetText(breakSpeed); float steeringDif = previewStats.steerSpeed - carStats.steerSpeed; string steering = steeringDif.ToString(); if (steeringDif > 0f) { steering = steering.Insert(0, "+"); } if (steering.Length > previewStatDisplayLength) { steering = steering.Substring(0, previewStatDisplayLength); } PsteeringText.SetText(steering); }
// public Event PlayerDied; void Awake() { instance = this; PC = this.GetComponent <PlayerController>(); // OnPlayerDied += EventManager.OnGameReset += OnGameReset; EventManager.OnResumeAftervideo += OnResumeAftervideo; }
public void UpdateInGameUI() { RaceManager RaceGuru = GameObject.FindObjectOfType <RaceManager>(); if (RaceGuru) { CarStats Player = PlayerCarsStats[CurrentLoadedSceneIndex]; CarStats Oponent = OponentCarStats[CurrentLoadedSceneIndex]; } }
// Use this for initialization void Start() { autos = GameObject.FindGameObjectsWithTag("car"); player = GameObject.Find("Player"); start = true; carStats = GetComponent <CarStats>(); playerStats = GetComponent <PlayerStats>(); }
// Start is called before the first frame update void Start() { this.shootingScript = this.gameObject.GetComponent <PlayerShooting>(); leftStickVertical = $"GamepadVertical{id}"; leftStickHorizontal = $"GamepadHorizontal{id}"; rightStickHorizontal = $"GamepadRightHorizontal{id}"; rightStickVertical = $"GamepadRightVertical{id}"; shootButton = $"joystick {id} button 5"; this.stats = this.gameObject.GetComponent <CarStats>(); }
private void Start() { Car = new GameObject("Car"); Car.tag = "player" + _player; Car.transform.position = transform.position; _cursorPos = Vector3.zero; _placedBlocks = new Dictionary <Vector3, GameObject>(); _blocksPlaced = new Dictionary <GameObject, Vector3>(); _playerReady = false; carStats = new CarStats(); }
public void ShowVehicle(CarStats carType, Color color) { if (carType != null) { ShowVehicle(carType.index, color); } else { viewedVehicle?.gameObject.SetActive(false); } }
public static CarState TryGetCarState(CarLogic carLogic, NitronicCarController nitronicCarController, Rigidbody rigidbody, CarStats carStats) { if (carLogic == null || carLogic.IsDying_ || nitronicCarController == null || rigidbody == null || carStats == null) { return(null); } return(new CarState(carLogic, nitronicCarController, rigidbody, carStats)); }
public void Update() { var playerManager = G.Sys.PlayerManager_; var optionsManager = G.Sys.OptionsManager_; GeneralSettings = optionsManager ? optionsManager.General_ : null; var localPlayer = playerManager ? playerManager.Current_ : null; var playerDataLocal = localPlayer?.playerData_; var carGameObject = playerDataLocal ? playerDataLocal.Car_ : null; HoverScreenEmitter = carGameObject ? carGameObject.GetComponent <HoverScreenEmitter>() : null; CarLogic = playerDataLocal ? playerDataLocal.CarLogic_ : null; CarStats = CarLogic ? CarLogic.CarStats_ : null; }
private void RemoveBlock() { if (currentCollisions.Count != 0) { //find collision entry List <Collider> removeMe = new List <Collider>(); removeMe.AddRange(currentCollisions); foreach (Collider coll in removeMe) { GameObject go = coll.gameObject; if (coll.CompareTag("childmesh")) { go = go.transform.parent.gameObject; } currentCollisions.Remove(coll); if (_placedBlocks.ContainsValue(go)) { _placedBlocks.Remove(_blocksPlaced[go]); _blocksPlaced.Remove(go); } CarComponent component = go.GetComponent <BlockProperties>().data; BPText.SetText(BuildController.ModifyBuildPoints(component.buildPoints, _player).ToString()); //CarStats carStats = UpdateCarStats(component, carStats, false); UpdateStatDisplay(); PreviewStatDisplay(); Destroy(go); } } if (_placedBlocks.ContainsKey(_cursorPos)) { GameObject removeMe = _placedBlocks[_cursorPos]; _blocksPlaced.Remove(removeMe); _placedBlocks.Remove(_cursorPos); CarComponent component = removeMe.GetComponent <BlockProperties>().data; BPText.SetText(BuildController.ModifyBuildPoints(component.buildPoints, _player).ToString()); //CarStats carStats = UpdateCarStats(component, carStats, false); UpdateStatDisplay(); PreviewStatDisplay(); Destroy(removeMe); } if (currentCollisions.Count == 0) { HologramColor(new Color(1f, 1f, 1f, .5f)); } }
public void FinishCarSetup() { RaceManager RaceGuru = GameObject.FindObjectOfType <RaceManager>(); if (RaceGuru) { //CarButton Player = PlayerCarInformations[CurrentLoadedSceneIndex]; //OponentRaceInfo Oponent = RaceInformations[CurrentLoadedSceneIndex]; CarStats Player = PlayerCarsStats[CurrentLoadedSceneIndex]; CarStats Oponent = OponentCarStats[CurrentLoadedSceneIndex]; RaceGuru.SetupCars(Player, Oponent); bRaceStarted = true; InGamePlayerRaceInfo.gameObject.SetActive(true); InGamePlayerRaceInfo.CarInfo.CarImage = Player.CarImage; InGamePlayerRaceInfo.CarInfo.Acceleration = Player.Acceleration; InGamePlayerRaceInfo.CarInfo.Drive = Player.Drive; InGamePlayerRaceInfo.CarInfo.Handling = Player.Handling; InGamePlayerRaceInfo.CarInfo.TopSpeed = Player.TopSpeed; InGamePlayerRaceInfo.CarInfo.Tyres = Player.Tyres; InGamePlayerRaceInfo.Setup(); InGameOponentRaceInfo.gameObject.SetActive(true); InGameOponentRaceInfo.CarInfo.Acceleration = Oponent.Acceleration;//RaceInformations[CurrentLoadedSceneIndex]; InGameOponentRaceInfo.CarInfo.CarImage = Oponent.CarImage; InGameOponentRaceInfo.CarInfo.Drive = Oponent.Drive; InGameOponentRaceInfo.CarInfo.Handling = Oponent.Handling; InGameOponentRaceInfo.CarInfo.TopSpeed = Oponent.TopSpeed; InGameOponentRaceInfo.CarInfo.Tyres = Oponent.Tyres; InGameOponentRaceInfo.Setup(); PlayerSpeedText.gameObject.SetActive(true); OponentSpeedText.gameObject.SetActive(true); InGameScreen.gameObject.SetActive(true); } CurrentLoadedSceneIndex++; }
private void Start() { CS = CarStats.instance; playerData = PlayerData.instance; input = PlayerInput.instance; }
void Start() { CS = CarStats.instance; tilemover = TileMover.instance; PC = PlayerController.instance; }
private void LoadBuild() { if (!File.Exists(Application.dataPath + @"\PlacedBlocksCatergories" + _player + ".txt")) { Debug.Log("No Save-File could be found! Are you sure you saved something?"); return; } //If there are already blocks placed down, this will clear the placed ones. if (_placedBlocks.Count > 0) { for (int b = 0; b < _placedBlocks.Count; b++) { Destroy(_placedBlocks.ElementAt(b).Value); } _placedBlocks.Clear(); _blocksPlaced.Clear(); } //Get JSON string json = File.ReadAllText(Application.dataPath + @"\PlacedBlocksCatergories" + _player + ".txt"); Dictionary <string, BlockSave[]> stringDict = JsonConvert.DeserializeObject <Dictionary <string, BlockSave[]> >(json); Dictionary <CarComponents.Type, BlockSave[]> enumDict = new Dictionary <CarComponents.Type, BlockSave[]>(); List <BlockSave> list = new List <BlockSave>(); foreach (string enumName in stringDict.Keys) { CarComponents.Type type = (CarComponents.Type)Enum.Parse(typeof(CarComponents.Type), enumName, true); enumDict.Add(type, stringDict[enumName]); list.AddRange(stringDict[enumName]); } foreach (BlockSave blockSave in list) { CarComponent component = BuildController.GetComponent(blockSave.name); GameObject prefab = ReturnBlockToPlace(blockSave.name); GameObject placedBlock = Instantiate(prefab, Vector3.zero, StringToQuaternion(blockSave.rotation), Car.transform); placedBlock.transform.localPosition = StringToVector3(blockSave.position); placedBlock.GetComponent <MeshRenderer>().sortingOrder = -50; placedBlock.AddComponent <BlockProperties>().data = component; //if(component.customMeshChecker != null){ if (placedBlock.GetComponentInParent <MeshCollider>()) { foreach (MeshCollider coll in placedBlock.GetComponentsInChildren <MeshCollider>()) { Destroy(coll); } } GameObject meshChild = new GameObject("Mesh"); meshChild.tag = "childmesh"; MeshCollider cColl = meshChild.AddComponent <MeshCollider>(); cColl.convex = true; if (component.customMeshChecker != null) { cColl.sharedMesh = component.customMeshChecker; } else { Mesh sm = placedBlock.GetComponent <MeshCollider>().sharedMesh; cColl.sharedMesh = sm; } meshChild.transform.SetParent(placedBlock.transform); meshChild.transform.localPosition = component.colliderOffset + (cColl.sharedMesh.bounds.extents / 10f) * .8f; meshChild.transform.localRotation = Quaternion.identity; meshChild.transform.localScale = new Vector3(.8f, .8f, .8f); if (placedBlock.GetComponent <MeshCollider>()) { Destroy(placedBlock.GetComponent <MeshCollider>()); } _placedBlocks.Add(StringToVector3(blockSave.position), placedBlock); _blocksPlaced.Add(placedBlock, StringToVector3(blockSave.position)); //CarStats carStats = UpdateCarStats(component, carStats, true); UpdateStatDisplay(); PreviewStatDisplay(); } }
//TODO terrainMultiplier is not really necessary here i think, but good thing to check over. public CarStats UpdateCarStats(CarComponent component, CarStats stats, bool positive) { CarStats newStats = new CarStats(stats.maxSpeed, stats.acceleration, stats.breakSpeed, stats.steerSpeed, stats.terrainMultiplier); foreach (ComponentModifier modifier in component.modifiers) { switch (modifier.stat) { case CarStat.MaxSpeed: switch (modifier.math) { case MathOperator.plus: newStats.maxSpeed += modifier.value * (positive ? 1 : -1); break; case MathOperator.minus: newStats.maxSpeed -= modifier.value * (positive ? 1 : -1); break; } break; case CarStat.Acceleration: switch (modifier.math) { case MathOperator.plus: newStats.acceleration += modifier.value * (positive ? 1 : -1); break; case MathOperator.minus: newStats.acceleration -= modifier.value * (positive ? 1 : -1); break; } break; case CarStat.BreakSpeed: switch (modifier.math) { case MathOperator.plus: newStats.breakSpeed += modifier.value * (positive ? 1 : -1); break; case MathOperator.minus: newStats.breakSpeed -= modifier.value * (positive ? 1 : -1); break; } break; case CarStat.SteerSpeed: switch (modifier.math) { case MathOperator.plus: newStats.steerSpeed += modifier.value * (positive ? 1 : -1); break; case MathOperator.minus: newStats.steerSpeed -= modifier.value * (positive ? 1 : -1); break; } break; } } return(newStats); }
internal void UpdateCarReference(CarStats carStats) { CarStats = carStats; }
// Start is called before the first frame update void Start() { CS = GetComponent <CarStats>(); input = PlayerInput.instance; rockets = GetComponent <RocketsManager>(); }
private void PlaceBlock() { if (_placedBlocks.ContainsKey(_cursorPos)) { return; } CarComponent component = BuildController.GetComponent(_selectedBlock); if (BuildController.GetBuidPoints(_player) < component.buildPoints) { return; } BPText.SetText(BuildController.ModifyBuildPoints(-component.buildPoints, _player).ToString()); GameObject placedBlock; if (component.BuildGFX != null) { placedBlock = Instantiate(component.GFX, _cursorPos + buildOffset, _cursorBlock.transform.rotation, Car.transform); } else { placedBlock = Instantiate(component.GFX, _cursorPos + buildOffset, _cursorBlock.transform.rotation, Car.transform); } placedBlock.GetComponent <MeshRenderer>().sortingOrder = -50; placedBlock.AddComponent <BlockProperties>().data = component; //if(component.customMeshChecker != null){ if (placedBlock.GetComponentInParent <MeshCollider>()) { foreach (MeshCollider coll in placedBlock.GetComponentsInChildren <MeshCollider>()) { Destroy(coll); } } GameObject meshChild = new GameObject("Mesh"); meshChild.tag = "childmesh"; MeshCollider cColl = meshChild.AddComponent <MeshCollider>(); cColl.convex = true; if (component.customMeshChecker != null) { cColl.sharedMesh = component.customMeshChecker; } else { Mesh sm = placedBlock.GetComponent <MeshCollider>().sharedMesh; cColl.sharedMesh = sm; } meshChild.transform.SetParent(placedBlock.transform); meshChild.transform.localPosition = component.colliderOffset + (cColl.sharedMesh.bounds.extents / 10f) * .8f; meshChild.transform.localRotation = Quaternion.identity; meshChild.transform.localScale = new Vector3(.8f, .8f, .8f); if (placedBlock.GetComponent <MeshCollider>()) { Destroy(placedBlock.GetComponent <MeshCollider>()); } /*if(placedBlock.GetComponentInParent<MeshCollider>()){ * foreach(MeshCollider coll in placedBlock.GetComponentsInChildren<MeshCollider>()){ * Destroy(coll); * } * }*/ //} _placedBlocks.Add(_cursorPos, placedBlock); _blocksPlaced.Add(placedBlock, _cursorPos); //CarStats carStats = UpdateCarStats(component, carStats, true); UpdateStatDisplay(); PreviewStatDisplay(); HologramColor(new Color(1f, 0f, 0f, .5f)); }
private GameObject Construct(int player) { if (!File.Exists(Application.dataPath + @"\PlacedBlocksCatergories" + player + ".txt")) { Debug.Log("No Save-File could be found! Are you sure you saved something?"); //TODO show on screen. return(null); } //Get JSON string json = File.ReadAllText(Application.dataPath + @"\PlacedBlocksCatergories" + player + ".txt"); Dictionary <string, BlockSave[]> stringDict = JsonConvert.DeserializeObject <Dictionary <string, BlockSave[]> >(json); Dictionary <CarComponents.Type, BlockSave[]> enumDict = new Dictionary <CarComponents.Type, BlockSave[]>(); List <BlockSave> list = new List <BlockSave>(); foreach (string enumName in stringDict.Keys) { CarComponents.Type type = (CarComponents.Type)Enum.Parse(typeof(CarComponents.Type), enumName, true); enumDict.Add(type, stringDict[enumName]); list.AddRange(stringDict[enumName]); } GameObject car = new GameObject("Car P" + player); //1. Static meshes (hull) GameObject hull = new GameObject("Hull"); hull.transform.SetParent(car.transform); //2. Wheel Visuals (renderers) GameObject wheelRenderers = new GameObject("Wheels"); wheelRenderers.transform.SetParent(car.transform); CarStats carStats = new CarStats(); //Fill the containers foreach (BlockSave blockSave in list) { GameObject prefab = ReturnBlockToPlace(blockSave.name); CarComponent component = (CarComponent)BuildController.GetComponent(blockSave.name); GameObject block; switch (component.type) { case CarComponents.Type.Wheel: block = Instantiate(prefab, StringToVector3(blockSave.position), StringToQuaternion(blockSave.rotation), wheelRenderers.transform); break; default: block = Instantiate(prefab, StringToVector3(blockSave.position), StringToQuaternion(blockSave.rotation), hull.transform); break; } carStats = ModifyCarStats(component, carStats); } ///Setup rigidbody + collider //Combine all meshes into one MeshFilter[] meshFilters = hull.GetComponentsInChildren <MeshFilter>(); CombineInstance[] combine = new CombineInstance[meshFilters.Length]; for (int i = 0; i < meshFilters.Length; i++) { combine[i].mesh = meshFilters[i].sharedMesh; combine[i].transform = meshFilters[i].transform.localToWorldMatrix; if (meshFilters[i].GetComponent <MeshCollider>()) { meshFilters[i].GetComponent <MeshCollider>().enabled = false; } } Mesh combinedMesh = new Mesh(); combinedMesh.CombineMeshes(combine); MeshCollider combinedCollider = car.gameObject.AddComponent <MeshCollider>(); combinedCollider.sharedMesh = combinedMesh; combinedCollider.convex = true; Rigidbody carRb = car.AddComponent <Rigidbody>(); carRb.mass = 1500; //3. Wheel Colliders (colliders) List <WheelCollider> wheelColls = new List <WheelCollider>(); List <Transform> wheelCollsTs = new List <Transform>(); List <Transform> wheelTrans = new List <Transform>(); GameObject wheelColliders = Instantiate(wheelRenderers, wheelRenderers.transform.position, wheelRenderers.transform.rotation, car.transform); wheelColliders.name = "WheelCollliders"; //we need the lists to start with the two front wheels Transform front1col = null; Transform front2col = null; for (int i = 0; i < wheelColliders.transform.childCount; i++) { Transform child = wheelColliders.transform.GetChild(i); if (front1col == null) { front1col = child; } else { if (child.position.z > front1col.position.z) { front1col = child; } } } for (int i = 0; i < wheelColliders.transform.childCount; i++) { Transform child = wheelColliders.transform.GetChild(i); if (child != front1col) { if (front2col == null) { front2col = child; } else { if (child.position.z > front2col.position.z) { front2col = child; } } } } wheelCollsTs.Add(front1col); wheelCollsTs.Add(front2col); for (int child = 0; child < wheelColliders.transform.childCount; child++) { Transform wheel = wheelColliders.transform.GetChild(child); //Remove all renderers List <MeshRenderer> renderers = new List <MeshRenderer>(); renderers.AddRange(wheel.GetComponents <MeshRenderer>()); renderers.AddRange(wheel.GetComponentsInChildren <MeshRenderer>()); foreach (MeshRenderer renderer in renderers) { Destroy(renderer); } List <MeshFilter> filters = new List <MeshFilter>(); filters.AddRange(wheel.GetComponents <MeshFilter>()); filters.AddRange(wheel.GetComponentsInChildren <MeshFilter>()); foreach (MeshFilter filter in filters) { Destroy(filter); } //Remove all colliders List <Collider> colls = new List <Collider>(); colls.AddRange(wheel.GetComponents <Collider>()); colls.AddRange(wheel.GetComponentsInChildren <Collider>()); //Add Wheel Colliders WheelCollider wheelColl = wheel.gameObject.AddComponent <WheelCollider>(); wheelColl.mass = 10f; wheelColl.radius = 1f; wheelColl.wheelDampingRate = 1f; wheelColl.suspensionDistance = .08f; if (!wheelCollsTs.Contains(wheel)) { wheelCollsTs.Add(wheel); } foreach (Collider coll in colls) { Destroy(coll); } } foreach (Transform wheelColTs in wheelCollsTs) { wheelColls.Add(wheelColTs.GetComponent <WheelCollider>()); } //Clear components from the wheel renderers Transform front1ts = null; Transform front2ts = null; for (int i = 0; i < wheelRenderers.transform.childCount; i++) { Transform child = wheelRenderers.transform.GetChild(i); if (front1ts == null) { front1ts = child; } else { if (child.position.z > front1ts.position.z) { front1ts = child; } } } for (int i = 0; i < wheelRenderers.transform.childCount; i++) { Transform child = wheelRenderers.transform.GetChild(i); if (child != front1ts) { if (front2ts == null) { front2ts = child; } else { if (child.position.z > front2ts.position.z) { front2ts = child; } } } } wheelTrans.Add(front1ts); wheelTrans.Add(front2ts); GameObject[] wheelRender = new GameObject[wheelRenderers.transform.childCount]; for (int i = 0; i < wheelRenderers.transform.childCount; i++) { wheelRender[i] = wheelRenderers.transform.GetChild(i).gameObject; } foreach (GameObject wheel in wheelRender) { GameObject wheelParent = new GameObject("Wheelparent"); wheelParent.transform.SetParent(wheel.transform.parent); wheelParent.transform.position = wheel.transform.position; wheelParent.transform.rotation = wheel.transform.rotation; wheel.transform.SetParent(wheelParent.transform); if (!wheelTrans.Contains(wheel.transform)) { wheelTrans.Add(wheel.transform); } //Remove all colliders List <Collider> colls = new List <Collider>(); colls.AddRange(wheelParent.GetComponents <Collider>()); colls.AddRange(wheelParent.GetComponentsInChildren <Collider>()); foreach (Collider coll in colls) { Destroy(coll); } } NewCarController controller = car.AddComponent <NewCarController>(); controller.wheelColliders = wheelColls.ToArray(); controller.wheelTransforms = wheelTrans.ToArray(); controller.player = player; controller.particleSystems = car.GetComponentsInChildren <ParticleSystem>(); controller.rb = carRb; controller.carStats = carStats; if (player == 1) { car.transform.position = spawnPosP1; controller.spawnPos = spawnPosP1; } else { car.transform.position = spawnPosP2; controller.spawnPos = spawnPosP2; } SetLayerRecursively(car, 9); carRb.drag = .5f; carStats.terrainMultiplier = 1f; //carRb.angularDrag = .5f; return(car); }
//TODO we dont need to add terrainmultiplier here right? :thinking: private CarStats ModifyCarStats(CarComponent component, CarStats stats) { CarStats carStats = new CarStats(stats.maxSpeed, stats.acceleration, stats.breakSpeed, stats.steerSpeed, stats.terrainMultiplier); foreach (ComponentModifier modifier in component.modifiers) { switch (modifier.stat) { case CarStat.MaxSpeed: switch (modifier.math) { case MathOperator.plus: carStats.maxSpeed += modifier.value; break; case MathOperator.minus: carStats.maxSpeed -= modifier.value; break; } break; case CarStat.Acceleration: switch (modifier.math) { case MathOperator.plus: carStats.acceleration += modifier.value; break; case MathOperator.minus: carStats.acceleration -= modifier.value; break; } break; case CarStat.BreakSpeed: switch (modifier.math) { case MathOperator.plus: carStats.breakSpeed += modifier.value; break; case MathOperator.minus: carStats.breakSpeed -= modifier.value; break; } break; case CarStat.SteerSpeed: switch (modifier.math) { case MathOperator.plus: carStats.steerSpeed += modifier.value; break; case MathOperator.minus: carStats.steerSpeed -= modifier.value; break; } break; case CarStat.Offroad: carStats.offroad += modifier.value; break; } } return(carStats); }
private void Start() { CS = CarStats.instance; }
public GameObject Construct(int player) { if (!File.Exists(Application.dataPath + @"\PlacedBlocksCatergories" + player + ".txt")) { Debug.Log("No Save-File could be found! Are you sure you saved something?"); return(null); } //Get JSON string json = File.ReadAllText(Application.dataPath + @"\PlacedBlocksCatergories" + player + ".txt"); Dictionary <string, BlockSave[]> stringDict = JsonConvert.DeserializeObject <Dictionary <string, BlockSave[]> >(json); Dictionary <CarComponents.Type, BlockSave[]> enumDict = new Dictionary <CarComponents.Type, BlockSave[]>(); List <BlockSave> list = new List <BlockSave>(); foreach (string enumName in stringDict.Keys) { CarComponents.Type type = (CarComponents.Type)Enum.Parse(typeof(CarComponents.Type), enumName, true); enumDict.Add(type, stringDict[enumName]); list.AddRange(stringDict[enumName]); } //Create car GameObject car = new GameObject("Car (Player" + player + ")"); car.transform.position = new Vector3(0f, 5f, 0f); Transform hull = new GameObject("Hull").transform; hull.SetParent(car.transform); hull.position = Vector3.zero; //CarStats! CarStats carStats = new CarStats(); foreach (BlockSave blockSave in list) { GameObject prefab = ReturnBlockToPlace(blockSave.name); GameObject block = Instantiate(prefab, StringToVector3(blockSave.position), StringToQuaternion(blockSave.rotation), hull); CarComponent component = (CarComponent)BuildController.GetComponent(blockSave.name); foreach (ComponentModifier modifier in component.modifiers) { switch (modifier.stat) { case CarStat.MaxSpeed: switch (modifier.math) { case MathOperator.plus: carStats.maxSpeed += modifier.value; break; case MathOperator.minus: carStats.maxSpeed -= modifier.value; break; } break; case CarStat.Acceleration: switch (modifier.math) { case MathOperator.plus: carStats.acceleration += modifier.value; break; case MathOperator.minus: carStats.acceleration -= modifier.value; break; } break; case CarStat.BreakSpeed: switch (modifier.math) { case MathOperator.plus: carStats.breakSpeed += modifier.value; break; case MathOperator.minus: carStats.breakSpeed -= modifier.value; break; } break; case CarStat.SteerSpeed: switch (modifier.math) { case MathOperator.plus: carStats.steerSpeed += modifier.value; break; case MathOperator.minus: carStats.steerSpeed -= modifier.value; break; } break; } } if (BuildController.GetComponent(blockSave.name).type == CarComponents.Type.Wheel) { if (StringToQuaternion(blockSave.rotation).eulerAngles.y == 90) { wheelsL.Add(block); } else if (StringToQuaternion(blockSave.rotation).eulerAngles.y == 270) { wheelsR.Add(block); } } } if (overideStats) { carStats = editorStats; } //Combine all meshes into one MeshFilter[] meshFilters = car.GetComponentsInChildren <MeshFilter>(); CombineInstance[] combine = new CombineInstance[meshFilters.Length]; for (int i = 0; i < meshFilters.Length; i++) { combine[i].mesh = meshFilters[i].sharedMesh; combine[i].transform = meshFilters[i].transform.localToWorldMatrix; if (meshFilters[i].GetComponent <MeshCollider>()) { meshFilters[i].GetComponent <MeshCollider>().enabled = false; } } Mesh combinedMesh = new Mesh(); combinedMesh.CombineMeshes(combine); /*BoxCollider boxCollider = hull.gameObject.AddComponent<BoxCollider>(); * boxCollider.size = combinedMesh.bounds.extents * 2f; * boxCollider.center = combinedMesh.bounds.center;*/ MeshCollider combinedCollider = hull.gameObject.AddComponent <MeshCollider>(); combinedCollider.sharedMesh = combinedMesh; combinedCollider.convex = true; //Setting up Car Controls Rigidbody hullRB = hull.gameObject.AddComponent <Rigidbody>(); hullRB.interpolation = RigidbodyInterpolation.Extrapolate; hullRB.collisionDetectionMode = CollisionDetectionMode.ContinuousDynamic; hullRB.angularDrag = 30f; hullRB.mass = .5f; hullRB.gameObject.layer = 9; CarController cCont = hull.gameObject.AddComponent <CarController>(); cCont.player = player; cCont.carStats = carStats; cCont.collider = combinedCollider; cCont._drive = true; GameObject cam = GameObject.FindGameObjectWithTag("player" + player); Vector3 pos = cam.transform.position; cam.transform.SetParent(hull); cam.transform.position = new Vector3(0f, pos.y, pos.z); car.transform.position += new Vector3(player * 25f, 0f, 0f); // endpoint of Construct. return(car); }
private CarState(CarLogic carLogic, NitronicCarController carController, Rigidbody rigidbody, CarStats carStats) { _gameObject = new GameObject(); Object.DontDestroyOnLoad(_gameObject); _gameObject.transform.position = rigidbody.position; _gameObject.transform.rotation = rigidbody.rotation; Velocity = rigidbody.velocity; AngularVelocity = rigidbody.angularVelocity; DragMultiplier = carController.dragMultiplier_; AngularDrag = rigidbody.angularDrag; InfiniteCooldown = carLogic.infiniteCooldown_; Heat = carLogic.Heat_; GravityEnabled = rigidbody.useGravity; WheelsContacting = carStats.WheelsContacting_; ThrusterBoostTimer = Traverse.Create(carLogic.Jets_).Field("thrusterBoostTimer_").GetValue <float>(); }