关于unity使用导入 .unitypackage报错的解决技巧

在开发过程中,大家难免会下载网络demo用来参考,但是网络上的demo,有很大一部分demo在导入时是报错的,此时就需要修复它让它可以顺畅地运行起来。

 在使用demo时,就遇到了一种报错,拿出来跟大家分享一下此类的如何解决。下图就是我遇到的问题报错:

 

 

 

 

 

Assets/Standard Assets/Scripts/MeshCombineUtility.cs(27,39): error CS1061: Type `UnityEngine.Mesh' does not contain a definition for `GetTriangleStrip' and no extension method `GetTriangleStrip' of type `UnityEngine.Mesh' could be found. Are you missing an assembly reference?

 

报错位置在这一行代码:

int curStripCount = combine.mesh.GetTriangleStrip(combine.subMeshIndex).Length;

 

报错说的是在UnityEngine.Mesh这个类里,既没有GetTriangleStrip' 这个方法的定义,也没有相关的扩展方法。

 

我是这样思考的,这个方法可能是由于unity的更新,导致demo的作者使用的这个方法被定义了新的名字,或者被其他类似的方法所取代了。所以,要删掉这个方法名,注意不要删掉他的参数,重新再mesh的后面输入一个点(.)看一下有没有相关类似的方法。

果然我点出了这样一个方法GetTriangles:

 

public int[] GetTriangles(int submesh, [Internal.DefaultValue("true")] bool applyBaseVertex);

 

我在使用这个方法后,果然这个报错就消失了,大功告成。 搞定,插件可用了

 

错误一 GetTriangleStrip、SetTriangleStrip报错
随着Unity版本的更新,很多低版本的插件导入到高版本中后都会报错,其中一个错位为:

Assets/Quantum Theory/UCP/Scripts/Utility Scripts/MeshCombineUtility.cs(27,39): error CS1061:
Type UnityEngine.Mesh' does not contain a definition forGetTriangleStrip’ and no extension method GetTriangleStrip' of typeUnityEngine.Mesh’ could be found. Are you missing an assembly reference?

错误指出:Mesh不包含GetTriangleStrip的定义,也没有UnityEngine类型的扩展方法“GetTriangleStrip”。

解决方法:

将 GetTriangleStrip 改成 GetTriangles
对应的 SetTriangleStrip 改成 SetTriangles

 

 

 

错误二 shader错误:’vert’: output parameter ‘o’ not completely initialized
导入一个旧项目到unity5中,shader报错了:'vert': output parameter 'o' not completely initialized。

错误指出:vert输出参数o没有初始化。直接定位vert

void vert (inout appdata_full v, out Input o) {

 

添加以下下划线代码:

UNITY_INITIALIZE_OUTPUT(Input,o);

o.customColor = abs(v.normal);}

 

 

错误三 Error adding Enlighten system data (some GUID). RadiosityData is missing

Solution:

In Scene 1, select the Prefab Initial Floor, then in the Inspector use the drop down arrow next to Static, and deselect "Lightmap static" and save.
This works fine for my project since there isn't any game play in Scene 1, but there is most game play in Scene 2.

 

错误四 `UnityEditor.EditorUtility' does not contain a definition for `GetAssetPreview'

解决办法:

AssetPreview.GetAssetPreview(tarObj);
AssetPreview.GetMiniThumbnail(tarObj);

 

错误五:Level '' (1) couldn't be loaded because it has not been added to the build settings.
To add a level to the build settings use the menu File->Build Settings...

场景没有加入 生成里面

 

 

错误六"SetDestination" can only be called on an active agent that has been placed on a NavMesh.

原因:导航NavMeshAgent组件所在物体距离Navmesh导航网格太远,'NavMeshAgent.SetDestination'设置导航目标点失败

解决:在设置导航目标点之前,可以用‘ NavMeshAgent.isOnNavMesh’判断,在返回值为Ture后再'NavMeshAgent.SetDestination',如果返回值为False,说明当前NavMeshAgent不在导航网格上,可用‘NavMeshAgent.Warp’纠正位置。

此外,还可以用‘NavMesh.SamplePosition’检测地图内某点是否在导航网格NavMesh内

    public bool TestNavigation()
    {
        if (navMeshAgent.isOnNavMesh)
        {
            NavMeshHit navigationHit;
            if (NavMesh.SamplePosition(targetPosition, out navigationHit, 15, navMeshAgent.areaMask))
                return navMeshAgent.SetDestination(navigationHit.position);
            return false;
        }
        else
        {
            return navMeshAgent.Warp(warpPosition);
        }
    }

 

错误七:

unity 错误:Assets/Editor/Image Effects/CameraMotionBlurEditor.js(92,36): BCE0004: Ambiguous reference 'preview': CameraMotionBlurEditor.preview, UnityEditor.Editor.preview.

Assets/Editor/Image Effects/CameraMotionBlurEditor.js(93,9): BCE0004: Ambiguous reference 'preview': CameraMotionBlurEditor.preview, UnityEditor.Editor.preview.

原因:preview用了和系统重名的UnityEditor.Editor.preview的变量名

解决办法:把里面preview 全部改为preview_。

如下面所示:

var preview_ : SerializedProperty;

preview_ = serObj.FindProperty ("preview"); EditorGUILayout.PropertyField (preview_, new GUIContent("Preview")); if (preview_.boolValue)

 

posted @ 2023-02-01 09:52  Domefy  阅读(1088)  评论(0编辑  收藏  举报