//---------------------------------------------- // Realistic Car Controller // // Copyright © 2014 - 2023 BoneCracker Games // https://www.bonecrackergames.com // Buğra Özdoğanlar // //---------------------------------------------- using System.Collections; using System.Collections.Generic; using UnityEngine; /// /// API for instantiating, registering new RCC vehicles, and changes at runtime. /// public class RCC { /// /// Spawn a RCC vehicle prefab with given position, rotation, sets its controllable, and engine state. /// public static RCC_CarControllerV3 SpawnRCC(RCC_CarControllerV3 vehiclePrefab, Vector3 position, Quaternion rotation, bool registerAsPlayerVehicle, bool isControllable, bool isEngineRunning) { RCC_CarControllerV3 spawnedRCC = (RCC_CarControllerV3)GameObject.Instantiate(vehiclePrefab, position, rotation); spawnedRCC.gameObject.SetActive(true); spawnedRCC.SetCanControl(isControllable); if (registerAsPlayerVehicle) RCC_SceneManager.Instance.RegisterPlayer(spawnedRCC); if (isEngineRunning) spawnedRCC.StartEngine(true); else spawnedRCC.KillEngine(); return spawnedRCC; } /// /// Registers the vehicle as player vehicle. /// public static void RegisterPlayerVehicle(RCC_CarControllerV3 vehicle) { RCC_SceneManager.Instance.RegisterPlayer(vehicle); } /// /// Registers the vehicle as player vehicle with controllable state. /// public static void RegisterPlayerVehicle(RCC_CarControllerV3 vehicle, bool isControllable) { RCC_SceneManager.Instance.RegisterPlayer(vehicle, isControllable); } /// /// Registers the vehicle as player vehicle with controllable and engine state. /// public static void RegisterPlayerVehicle(RCC_CarControllerV3 vehicle, bool isControllable, bool engineState) { RCC_SceneManager.Instance.RegisterPlayer(vehicle, isControllable, engineState); } /// /// De-Registers the player vehicle. /// public static void DeRegisterPlayerVehicle() { RCC_SceneManager.Instance.DeRegisterPlayer(); } /// /// Sets controllable state of the vehicle. /// public static void SetControl(RCC_CarControllerV3 vehicle, bool isControllable) { vehicle.SetCanControl(isControllable); } /// /// Sets engine state of the vehicle. /// public static void SetEngine(RCC_CarControllerV3 vehicle, bool engineState) { if (engineState) vehicle.StartEngine(); else vehicle.KillEngine(); } /// /// Sets the mobile controller type. /// public static void SetMobileController(RCC_Settings.MobileController mobileController) { RCC_Settings.Instance.mobileController = mobileController; Debug.Log("Mobile Controller has been changed to " + mobileController.ToString()); } /// /// Sets the units. /// public static void SetUnits() { } /// /// Sets the Automatic Gear. /// public static void SetAutomaticGear() { } /// /// Starts / stops to record the player vehicle. /// public static void StartStopRecord() { RCC_SceneManager.Instance.Record(); } /// /// Start / stops replay of the last record. /// public static void StartStopReplay() { RCC_SceneManager.Instance.Play(); } /// /// Stops record / replay of the last record. /// public static void StopRecordReplay() { RCC_SceneManager.Instance.Stop(); } /// /// Sets new behavior. /// public static void SetBehavior(int behaviorIndex) { RCC_SceneManager.Instance.SetBehavior(behaviorIndex); Debug.Log("Behavior has been changed to " + behaviorIndex.ToString()); } /// /// Changes the camera mode. /// public static void ChangeCamera() { RCC_SceneManager.Instance.ChangeCamera(); } /// /// Transport player vehicle the specified position and rotation. /// /// Position. /// Rotation. public static void Transport(Vector3 position, Quaternion rotation) { RCC_SceneManager.Instance.Transport(position, rotation); } /// /// Transport the target vehicle to specified position and rotation. /// /// /// /// public static void Transport(RCC_CarControllerV3 vehicle, Vector3 position, Quaternion rotation) { RCC_SceneManager.Instance.Transport(vehicle, position, rotation); } /// /// Cleans all skidmarks on the current scene. /// public static void CleanSkidmarks() { RCC_SkidmarksManager.Instance.CleanSkidmarks(); } /// /// Cleans target skidmarks on the current scene. /// public static void CleanSkidmarks(int index) { RCC_SkidmarksManager.Instance.CleanSkidmarks(index); } /// /// Repairs the target vehicle. /// /// public static void Repair(RCC_CarControllerV3 carController) { carController.damage.repairNow = true; } /// /// Repairs the player vehicle. /// public static void Repair() { RCC_CarControllerV3 carController = RCC_SceneManager.Instance.activePlayerVehicle; if (!carController) carController.damage.repairNow = true; } }