《Unity案例:Armored Vehicle Kit》 |
版本 | 作者 | 参与者 | 完成日期 | 备注 |
UnityPro_ArmroedVehicleKit_V01_1.0 | 严立钻 |
| 2018.09.03 |
|
|
|
|
|
|
##《Unity案例:Armored Vehicle Kit》发布说明:
++++“Unity案例:Armored Vehicle Kit”是对Unity项目案例系列的一次尝试,这个例子来自Asset Store,这次探索,为后期大量的Asset Store案例剖析做个探索,由于代码剖析比较乏味,没有好的拓展经验,如何拓展,怎样才能起到好的示范作用,这些都需要摸索总结,以期能完成一套项目剖析的有效方案,给读者展示不一样的案例剖析;
++++“Unity案例:Armored Vehicle Kit”:装甲车辆系统,这是一个车辆模拟驾驶案例,有兴趣的童鞋可以试一试;
##《Unity案例:Armored Vehicle》目录:
#第一篇:项目介绍
#第二篇:代码结构
#第三篇:项目拓展
#第四篇:立钻哥哥带您汽车模拟实战
#第一篇:项目介绍
#第一篇:项目介绍 |
#第一篇:项目介绍
++++“Armored Vehicle Kit”:装甲车辆装备;
++++[Armored]:装甲的;
++++[Vehicle]:车辆;交通工具;
++++[Kit]:装备;
++[Sci-Fi Armored Vehicles Kit]
++++Animated Roof Mods, three pieces;
++++Eighteen premade vehicles;
++++Interior and Bottom;
++++Sixteen prefabs, to make your own vehicle;
++++Eight Body Variants;
++++Ten Roof Mods in total, action and support;
++++Mods are separated, ready to animate;
++++Seven paint jobs for body;
++++Three colors of dirt for tires;
++[Dot_Truck_Controller.cs(C#)]
++++Brakes;
++++Wheels reacting to surface;
++++Specify number of Axles;
++++Motor & Steering selection for each Axle;
++++Drag Wheel Collider & Visual Wheel;
++++Customize Motor Torque and Steering Angle;
++[Standard Materials]
++++Albedo;
++++Metalic;
++++Normal;
++++Occlusion;
++++Emission;
++[Cabin]
++++Interior is meant for FPS-kind of game-you look at vehicle, come to it and can see what is inside.
++++Steering Wheel is not separate;
++[Version 1.1]
++++Enhanced script: Added support of inverted steering to the wheels, for any axle;
#第二篇:代码结构
#第二篇:代码结构 |
#第二篇:代码结构
++++B.1、Dot_Truck_Controller.cs
++++B.2、PostEffectsBase.cs
++++B.3、Tonemapping.cs
##B.1、Dot_Truck_Controller.cs
##B.1、Dot_Truck_Controller.cs |
++B.1、Dot_Truck_Controller.cs
++++ArmroedVehiclesKit\Assets\Armored Vehicles Kit\Scripts\Dot_Truck_Controller.cs
usingUnityEngine; usingSystem.Collections; usingSystem.Collections.Generic;
[System.Serializable] publicclassDot_Truck :System.Object{ publicWheelColliderleftWheel; publicGameObjectleftWheelMesh; publicWheelColliderrightWheel; publicGameObjectrightWheelMesh; publicboolmotor; publicboolsteering; publicboolreverseTurn; } //立钻哥哥:public class Dot_Truck:System.Object{}
publicclassDot_Truck_Controller:MonoBehaviour{ publicList<Dot_Truck>truck_Infos; publicfloatmaxMotorTorque; publicflaotmaxSteeringAngle;
publicvoidVisualizeWheel(Dot_TruckwheelPair){ Quaternionrot; Vector3pos; wheelPair.leftWheel.GetWorldPose(outpos,outrot); wheelPair.leftWheelMesh.transform.position=pos; wheelPair.leftWheelMesh.transform.rotation=rot; wheelPair.rightWheel.GetWorldPose(outpos,outrot); wheelPair.rightWheelMesh.transform.position=pos; wheelPair.rightWheelMesh.transform.rotation=rot; }
publicvoid Update(){ floatmotor=maxMotorTorque*Input.GetAxis(“Vertical”); floatsteering=maxSteeringAngle*Input.GetAxis(“Horizontal”); floatbrakeTorque=Mathf.Abs(Input.GetAxis(“Jump”));
if(brakeTorque> 0.001){ Debug.Log(brakeTorque); brakeTorque=maxMotorTorque; motor=0; }else{ brakeTorque=0; }
foreach(Dot_Trucktruck_Infointruck_Infos){ if(truck_Info.steering==true){ truck_Info.leftWheel.steerAngle=truck_Info.rightWheel.steerAngle= ((truck_Info.reverseTurn) ? -1 :1) *steering; }
if(truck_Info.motor==true){ truck_Info.leftWheel.motorTorque=motor; truck_Info.rightWheel.motorTorque=motor; }
truck_Info.leftWheel.brakeTorque=brakeTorque; truck_Info.rightWheel.brakeTorque=brakeTorque;
VisualizedWheel(truck_Info); } } //立钻哥哥:public void Update(){}
} //立钻哥哥:public class Dot_Truck_Controller:MonoBehaviour{} |
##B.2、PostEffectsBase.cs
##B.2、PostEffectsBase.cs |
++B.2、PostEffectsBase.cs
++++\Assets\Armored Vehicles Kit\Standard Assets\Effects\ImageEffects\Scripts\PostEffectsBase.cs
usingSystem; usingUnityEngine;
namespace UnityStandardAssets.ImageEffects{ [ExecuteInEditMode] [RequireComponent(typeof(Camera))] publicclassPostEffectsBase:MonoBehaviour{ protected boolsupportHDRTextures=true; protected boolsupportDX11=false; protected boolisSupported=true;
protected MaterialCheckShaderAndCreateMaterial(Shaders,Materialm2Create){ }
protected MaterialCreateMaterial(Shaders,Materialm2Create){ }
void OnEnable(){ isSupported=true; }
protected boolCheckSupport(){ returnCheckSupport(false); }
publicvirtual boolCheckResources(){ Debug.LogWarning(“立钻哥哥:CheckResources() for” + ToString() +“should be overwritten”); returnisSupported; }
protected void Start(){ CheckResources(); }
protected boolCheckSupport(boolneedDepth){ }
protected boolCheckSupport(boolneedDepth,boolneedHdr){ }
publicboolDX11Support(){ returnsupportDX11; }
protected voidReportAutoDisable(){ }
boolCheckShader(Shaders){ }
protected voidNotSupported(){ enabled=false; isSupported=false; return; }
protected voidDrawBorder(RenderTexturedest,Materialmaterial){ }
} //立钻哥哥:public class PostEffectsBase:MonoBehaviour{}
} //立钻哥哥:namespace UnityStandardAssts.ImageEffects{}
|
++RenderTextureFormat namespace UnityEngine{ publicenumRenderTextureFormat{ ARGB32, Depth, ARGBHalf, Shadowmap, RGB565, ARGB4444, ARGB1555, Default, ARGB2101010, DefaultHDR, ARGBFloat=11, RGFloat, RGHalf, RFloat, RHalf, R8, ARGBInt, RGint, RInt, BGRA32, RGB111110Float=22 } //立钻哥哥:public enum RenderTextureFormat{} } //立钻哥哥:namespace UnityEngine{} |
##B.3、Tonemapping.cs
##B.3、Tonemapping.cs |
++B.3、Tonemapping.cs
++++\Assets\Armored Vehicles Kit\Standard Assets\Effects\ImageEffects\Scripts\Tonemapping.cs
usingSystem; usingUnityEngine;
namespace UnityStandardAssets.ImageEffects{ [ExecuteInEditMode] [RequireComponent(typeof(Camera))] [AddComponentMenu(“Image Effects/Color Adjustments/Tonemapping”)] publicclassTonemapping:PostEffectBase{ publicenumTonemapperType{ SimpleReinhard, UserCurve, Hable, Photographic, OptimizedHejiDawson, AdaptiveReinhard, AdaptiveReinhardAutoWhite, }; //立钻哥哥:public enum TonemapperType{}
publicenumAdaptiveTexSize{ };
public TonemapperTypetype=TonemapperType.Photographic; public AdaptiveTexSizeadaptiveTextureSize=AdaptiveTexSize.Square256;
publicAnimationCurverampCurve; privateTexture2DcurveTex=null;
publicfloatexposureAdjustment=1.5f;
publicfloatmiddleGrey=0.4f; publicfloatwhite=2.0f; publicfloatadaptionSpeed=1.5f;
publicShadertonemapper=null; publicboolvalidRenderTextureFormat=true; privateMaterialtonemapMaterial=null; privateRenderTexturert=null; privateRenderTextureFormatrtFormat=RenderTextureFormat.ARGBHalf;
publicoverride boolCheckResources(){ }
publicfloatUpdateCurve(){ }
privatevoidOnDisable(){ }
privateboolCreateInternalRenderTexture(){ }
[ImageEffectTransformsToLDR] privatevoidOnRenderImage(RenderTexturesource,RenderTexturedestination){ }
} //立钻哥哥:public class Tonemapping:PostEffectBase{}
} //立钻哥哥:namespace UnityStandardAssets.ImageEffects{} |
#第三篇:项目拓展
#第三篇:项目拓展 |
#第三篇:项目拓展
++++C.1、WheelCollider轮碰撞器
[UnityAPI.WheelCollider轮碰撞器:https://blog.csdn.net/VRunSoftYanlz/article/details/82356217]
##C.1、WheelCollider 轮碰撞器
##C.1、WheelCollider 轮碰撞器 |
++C.1、WheelCollider 轮碰撞器
++++立钻哥哥:WheelCollider,用于车轮的特殊碰撞器;
namespaceUnityEngine{ publicsealed classWheelCollider:Collider{ //Properties publicextern floatbrakeTorque{} publicVector3center{} publicextern floatforceAppPointDistance{} publicWheelFrictionCurveforwardFriction{} publicextern boolisGrounded{} publicextern floatmass{} publicextern floatmotorTorque{} publicextern floatradius{} publicextern floatrpm{} publicWheelFrictionCurvedidewaysFriction{} publicextern floatsprungMass{} publicextern floatsteerAngle{} publicextern floatsuspensionDistance{} publicJointSpringsuspensionSpring{} publicextern floatwheelDampingRate{}
//Constructors public WheelCollider();
//Methods publicextern voidConfigureVehicleSubsteps(floatspeedThreshold,intstepsBelowThreshold,intstepsAboveThreshold); publicextern boolGetGroundHit(out WheelHithit); publicextern voidGetWorldPose(out Vector3pos,out Quaternionquat); private extern voidINTERNAL_get_center(out Vector3value); private extern voidINTERNAL_get_forwardFriction(out WheelFrictionCurvevalue); private extern voidINTERNAL_get_sidewaysFriction(out WheelFrictionCurvevalue); private extern voidINTERNAL_get_suspensionSpring(out JointSpringvalue); private extern voidINTERNAL_set_center(ref Vector3value); private extern voidINTERNAL_set_forwardFriction(ref WheelFrictionCurvevalue); private extern voidINTERNAL_set_sidewaysFriction(ref WheelFrictionCurvevalue); private extern voidINTERNAL_set_suspensionSpring(ref JointSpringvalue); } //立钻哥哥:public sealed class WheelCollider:Collider{}
} //立钻哥哥:namespace UnityEngine{} |
++Description描述
++++立钻哥哥:class in UnityEngine/Inherits from:Collider;
++++用于车轮的特殊碰撞器;
++++轮子碰撞器用于车轮模型;(它模拟弹簧和阻尼悬挂装置,并使用一个基于滑动轮胎摩擦力模型计算车轮接触力)
++++车轮的碰撞检测是由从自身y轴中心向下投射射线;(车轮有一个半径和可以向下延长的suspensionDistance数)
++++车轮是由motorTorque,brakeTorque和steerAngle属性控制;
++++车轮碰撞器使用不同物理引擎的一个基于滑动的摩擦力模型来计算摩擦力;(这允许更加真实的行为)(而且使车轮忽略标准的PhysicMaterial设置)(通过改变车轮锁碰到的forwardFriction和sidewaysFriction来模拟不同的道路材质)
++Variables变量
++++brakeTorque(制动扭矩):制动的扭矩;(这个值必须为正)
++++center(中心):车轮的中心,基于物体的自身坐标空间;
++++forceAppPointDistance(着力点距离):从基本静止车轮测量的悬挂和轮胎的着力点;
++++forwardFriction(向前摩擦力):在车轮指向方向上的摩擦力的属性;
++++isGrounded(是否接地):表示车轮当前是否碰到什么(只读);
++++mass(质量):车轮的质量,以千克表示;(该值必须大于0,通常该值的范围是20~80)
++++motorTorque(马达扭矩):在轮轴上的马达扭矩;(根据方向正或负)
++++radius(半径):车轮的半径,基于物体的自身坐标空间;
++++rpm(转速):当前轮轴旋转速度,每分钟转速(只读);
++++sidewaysFriction(侧向摩擦力):轮胎侧面方向上的摩擦力的属性;
++++sprung(簧载质量):该车轮碰撞器支撑的质量;
++++steerAngle(转向角):转向角度,总是沿自身Y轴;
++++suspensionDistance(悬挂距离):车轮悬挂的最大伸展距离,基于自身坐标空间;
++++suspensionSpring(悬挂弹簧):车轮悬挂的参数;(通过应用线性力和阻尼力,悬挂试图达到目标位置)
++++wheelDampingRate(轮阻尼率):车轮的阻尼率;(必须大于0的值)
++Public Functions共有函数
++++ConfigureVehicleSubsteps():配置车辆子步参数;
++++GetGroundHit():(获取碰撞)获取车轮的地面碰撞数据;
++++GetWorldPose():(获取世界姿态)获取世界坐标空间车轮与地面接触、悬挂限制、转向角以及选择角度的姿态;
#第四篇:立钻哥哥带您汽车模拟实战
#第四篇:立钻哥哥带您汽车模拟实战 |
++立钻哥哥推荐的拓展学习链接(Link_Url):
++++立钻哥哥Unity学习空间:http://blog.csdn.net/VRunSoftYanlz/
++++U3D小项目参考:https://blog.csdn.net/vrunsoftyanlz/article/details/80141811
++++Unity案例(Vehicle):https://blog.csdn.net/VRunSoftYanlz/article/details/82355876
++++JSON数据结构:https://blog.csdn.net/VRunSoftYanlz/article/details/82026644
++++HTC_VIVE开发基础:https://blog.csdn.net/VRunSoftYanlz/article/details/81989970
++++Unity5.x用户手册:https://blog.csdn.net/VRunSoftYanlz/article/details/81712741
++++Unity面试题ABC:https://blog.csdn.net/vrunsoftyanlz/article/details/78630687
++++Unity面试题D:https://blog.csdn.net/VRunSoftYanlz/article/details/78630838
++++Unity面试题E:https://blog.csdn.net/vrunsoftyanlz/article/details/78630913
++++Unity面试题F:https://blog.csdn.net/VRunSoftYanlz/article/details/78630945
++++Cocos2dx面试题:https://blog.csdn.net/VRunSoftYanlz/article/details/78630967
++++Lua快速入门篇(Xlua拓展):https://blog.csdn.net/VRunSoftYanlz/article/details/81173818
++++Lua快速入门篇(XLua教程):https://blog.csdn.net/VRunSoftYanlz/article/details/81141502
++++Lua快速入门篇(基础概述):https://blog.csdn.net/VRunSoftYanlz/article/details/81041359
++++框架知识点:https://blog.csdn.net/VRunSoftYanlz/article/details/80862879
++++游戏框架(UI框架夯实篇):https://blog.csdn.net/vrunsoftyanlz/article/details/80781140
++++游戏框架(初探篇):https://blog.csdn.net/VRunSoftYanlz/article/details/80630325
++++设计模式简单整理:https://blog.csdn.net/vrunsoftyanlz/article/details/79839641
++++专题:设计模式(精华篇):https://blog.csdn.net/VRunSoftYanlz/article/details/81322678
++++UML类图:https://blog.csdn.net/vrunsoftyanlz/article/details/80289461
++++Unity知识点0001:https://blog.csdn.net/vrunsoftyanlz/article/details/80302012
++++Unity知识点0008:https://blog.csdn.net/VRunSoftYanlz/article/details/81153606
++++U3D_Shader编程(第一篇:快速入门篇):https://blog.csdn.net/vrunsoftyanlz/article/details/80372071
++++U3D_Shader编程(第二篇:基础夯实篇):https://blog.csdn.net/vrunsoftyanlz/article/details/80372628
++++Unity引擎基础:https://blog.csdn.net/vrunsoftyanlz/article/details/78881685
++++Unity面向组件开发:https://blog.csdn.net/vrunsoftyanlz/article/details/78881752
++++Unity物理系统:https://blog.csdn.net/vrunsoftyanlz/article/details/78881879
++++Unity2D平台开发:https://blog.csdn.net/vrunsoftyanlz/article/details/78882034
++++UGUI基础:https://blog.csdn.net/vrunsoftyanlz/article/details/78884693
++++UGUI进阶:https://blog.csdn.net/vrunsoftyanlz/article/details/78884882
++++UGUI综合:https://blog.csdn.net/vrunsoftyanlz/article/details/78885013
++++Unity动画系统基础:https://blog.csdn.net/vrunsoftyanlz/article/details/78886068
++++Unity动画系统进阶:https://blog.csdn.net/vrunsoftyanlz/article/details/78886198
++++Navigation导航系统:https://blog.csdn.net/vrunsoftyanlz/article/details/78886281
++++Unity特效渲染:https://blog.csdn.net/vrunsoftyanlz/article/details/78886403
++++Unity数据存储:https://blog.csdn.net/vrunsoftyanlz/article/details/79251273
++++Unity中Sqlite数据库:https://blog.csdn.net/vrunsoftyanlz/article/details/79254162
++++WWW类和协程:https://blog.csdn.net/vrunsoftyanlz/article/details/79254559
++++Unity网络:https://blog.csdn.net/vrunsoftyanlz/article/details/79254902
++++C#事件:https://blog.csdn.net/vrunsoftyanlz/article/details/78631267
++++C#委托:https://blog.csdn.net/vrunsoftyanlz/article/details/78631183
++++C#集合:https://blog.csdn.net/vrunsoftyanlz/article/details/78631175
++++C#泛型:https://blog.csdn.net/vrunsoftyanlz/article/details/78631141
++++C#接口:https://blog.csdn.net/vrunsoftyanlz/article/details/78631122
++++C#静态类:https://blog.csdn.net/vrunsoftyanlz/article/details/78630979
++++C#中System.String类:https://blog.csdn.net/vrunsoftyanlz/article/details/78630945
++++C#数据类型:https://blog.csdn.net/vrunsoftyanlz/article/details/78630913
++++Unity3D默认的快捷键:https://blog.csdn.net/vrunsoftyanlz/article/details/78630838
++++游戏相关缩写:https://blog.csdn.net/vrunsoftyanlz/article/details/78630687
++++UnityAPI.Rigidbody刚体:https://blog.csdn.net/VRunSoftYanlz/article/details/81784053
++++UnityAPI.Material材质:https://blog.csdn.net/VRunSoftYanlz/article/details/81814303
++++UnityAPI.Android安卓:https://blog.csdn.net/VRunSoftYanlz/article/details/81843193
++++UnityAPI.AndroidJNI安卓JNI:https://blog.csdn.net/VRunSoftYanlz/article/details/81879345
++++UnityAPI.Transform变换:https://blog.csdn.net/VRunSoftYanlz/article/details/81916293
++++立钻哥哥Unity 学习空间:http://blog.csdn.net/VRunSoftYanlz/
--_--VRunSoft:lovezuanzuan--_--