Exemple #1
0
        public static VehicleUiWheelIndex GetUiWheelIndex(VehicleEntity vehicle, VehiclePartIndex index)
        {
            if (HasWheel(vehicle, index))
            {
                var controller      = GetController(vehicle);
                var controllerIndex = VehicleIndexHelper.ToVehicleControllerWheelIndex(index);
                return(controller.GetWheelUiIndex(controllerIndex));
            }

            return(VehicleUiWheelIndex.None);
        }
        public static void PlayWheelExplosion(VehicleEntity vehicle, VehiclePartIndex index)
        {
            //disable wheel mesh render
            EnableWheelRender(vehicle, index, false);

            //play explosion effect
            var go = vehicle.gameObject;
            var controllerIndex = VehicleIndexHelper.ToVehicleControllerWheelIndex(index);
            var effect          = go.UnityObjWrapper.Value.GetComponent <VehicleEventEffect>();

            effect.WheelExplosion(controllerIndex);
        }
        public static void EnableWheelRender(VehicleEntity vehicle, VehiclePartIndex index, bool enabled)
        {
            var go = vehicle.gameObject;
            var controllerIndex = VehicleIndexHelper.ToVehicleControllerWheelIndex(index);
            var controller      = go.UnityObjWrapper.Value.GetComponent <VehicleAbstractController>();
            var rendererRoot    = controller.GetTireMeshRenderRoot(controllerIndex);

            if (rendererRoot == null)
            {
                var meshRender = controller.GetTireMeshRender(controllerIndex);
                if (meshRender != null && meshRender.enabled != enabled)
                {
                    meshRender.enabled = enabled;
                }
            }
            else if (rendererRoot.gameObject.activeSelf != enabled)
            {
                rendererRoot.gameObject.SetActive(enabled);
            }
        }
        private void SetWheelBroken(VehicleEntity vehicle, VehiclePartIndex index)
        {
            AssertUtility.Assert(index != VehiclePartIndex.Body);

            var controller      = vehicle.GetController <VehicleAbstractController>();
            var controllerIndex = VehicleIndexHelper.ToVehicleControllerWheelIndex(index);

            controller.SetWheelBroken(controllerIndex);

            if (!controller.IsKinematic)
            {
                var config  = controller.GetComponent <VehicleConfig>();
                var impulse = config.wheelExplosionImpulse;
                if (impulse > 0)
                {
                    var force = controller.transform.up * impulse * controller.cachedRigidbody.mass;
                    vehicle.AddImpulseAtPosition(force, controller.GetWheel(controllerIndex).wheelTransform.position);
                }
            }

            vehicle.vehicleBrokenFlag.SetVehiclePartColliderBroken(index);
        }