• 大小: 14.81MB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2023-06-15
  • 语言: 其他
  • 标签: Unity3D  

资源简介

2DGameplayTutorialProject.zip for unity3d开发..

资源截图

代码片段和文件信息

using UnityEngine;
using System.Collections;
/*
Attach this script as a parent to some game objects. The script will then combine the meshes at startup.
This is useful as a performance optimization since it is faster to render one big mesh than many small meshes. See the docs on graphics performance optimization for more info.

Different materials will cause multiple meshes to be created thus it is useful to share as many textures/material as you can.
*/

[AddComponentMenu(“Mesh/Combine Children“)]
public class CombineChildren : MonoBehaviour {

/// Usually rendering with triangle strips is faster.
/// However when combining objects with very low triangle counts it can be faster to use triangles.
/// Best is to try out which value is faster in practice.
public bool generateTriangleStrips = true;
public bool castShadows = true;
public bool receiveShadows = true;

/// This option has a far longer preprocessing time at startup but leads to better runtime performance.
void Start () {
Component[] filters  = GetComponentsInChildren(typeof(MeshFilter));
Matrix4x4 myTransform = transform.worldToLocalMatrix;
Hashtable materialToMesh= new Hashtable();

for (int i=0;i MeshFilter filter = (MeshFilter)filters[i];
Renderer curRenderer  = filters[i].renderer;
MeshCombineUtility.MeshInstance instance = new MeshCombineUtility.MeshInstance ();
instance.mesh = filter.sharedMesh;
if (curRenderer != null && curRenderer.enabled && instance.mesh != null) {
instance.transform = myTransform * filter.transform.localToWorldMatrix;

Material[] materials = curRenderer.sharedMaterials;
for (int m=0;m instance.subMeshIndex = System.Math.Min(m instance.mesh.subMeshCount - 1);

ArrayList objects = (ArrayList)materialToMesh[materials[m]];
if (objects != null) {
objects.Add(instance);
}
else
{
objects = new ArrayList ();
objects.Add(instance);
materialToMesh.Add(materials[m] objects);
}
}

curRenderer.enabled = false;
}
}

foreach (DictionaryEntry de  in materialToMesh) {
ArrayList elements = (ArrayList)de.Value;
MeshCombineUtility.MeshInstance[] instances = (MeshCombineUtility.MeshInstance[])elements.ToArray(typeof(MeshCombineUtility.MeshInstance));

// We have a maximum of one material so just attach the mesh to our own game object
if (materialToMesh.Count == 1)
{
// Make sure we have a mesh filter & renderer
if (GetComponent(typeof(MeshFilter)) == null)
gameobject.AddComponent(typeof(MeshFilter));
if (!GetComponent(“MeshRenderer“))
gameobject.AddComponent(“MeshRenderer“);

MeshFilter filter = (MeshFilter)GetComponent(typeof(MeshFilter));
filter.mesh = MeshCombineUtility.Combine(instances generateTriangleStrips);
renderer.material = (Material)de.Key;
renderer.enabled = true;
renderer.castShadows = castShadows;
renderer.receiveShadows = re

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2009-11-24 14:03  2DGameplayTutorial\
     目录           0  2009-11-24 14:02  2DGameplayTutorial\Assets\
     文件      235663  2009-11-24 14:02  2DGameplayTutorial\Assets\2D Platformer.unity
     目录           0  2009-11-24 14:02  2DGameplayTutorial\Assets\Artwork\
     文件       68958  2009-11-24 14:02  2DGameplayTutorial\Assets\Artwork\Crate.fbx
     文件     1304960  2009-11-24 14:02  2DGameplayTutorial\Assets\Artwork\Lerpz.fbx
     目录           0  2009-11-24 14:02  2DGameplayTutorial\Assets\Artwork\Materials\
     文件        3301  2009-11-24 14:02  2DGameplayTutorial\Assets\Artwork\Materials\crate-_empty_.mat
     文件        3269  2009-11-24 14:02  2DGameplayTutorial\Assets\Artwork\Materials\crate-cratemat.mat
     文件        3643  2009-11-24 14:02  2DGameplayTutorial\Assets\Artwork\Materials\lerpzuv.mat
     文件        3285  2009-11-24 14:02  2DGameplayTutorial\Assets\Artwork\Materials\movingplatform-moving_platformmat.mat
     文件        3309  2009-11-24 14:02  2DGameplayTutorial\Assets\Artwork\Materials\platform slope-_empty_.mat
     文件        3285  2009-11-24 14:02  2DGameplayTutorial\Assets\Artwork\Materials\platform slope-angled_platformmat.mat
     文件        3672  2009-11-24 14:02  2DGameplayTutorial\Assets\Artwork\Materials\platform texture.mat
     文件        3301  2009-11-24 14:02  2DGameplayTutorial\Assets\Artwork\Materials\platforms-_empty_.mat
     文件        3277  2009-11-24 14:02  2DGameplayTutorial\Assets\Artwork\Materials\platforms-angled_platformmat.mat
     文件        3277  2009-11-24 14:02  2DGameplayTutorial\Assets\Artwork\Materials\platforms-end_cap_003mat.mat
     文件        3277  2009-11-24 14:02  2DGameplayTutorial\Assets\Artwork\Materials\platforms-end_cap_rightmat.mat
     文件        3269  2009-11-24 14:02  2DGameplayTutorial\Assets\Artwork\Materials\platforms-end_capmat.mat
     文件        3277  2009-11-24 14:02  2DGameplayTutorial\Assets\Artwork\Materials\platforms-level_platformmat.mat
     文件        3277  2009-11-24 14:02  2DGameplayTutorial\Assets\Artwork\Materials\platforms-moving_platformmat.mat
     文件        3674  2009-11-24 14:02  2DGameplayTutorial\Assets\Artwork\Materials\spaceship texture.mat
     文件        3309  2009-11-24 14:02  2DGameplayTutorial\Assets\Artwork\Materials\spaceship-default mat.mat
     文件        3648  2009-11-24 14:02  2DGameplayTutorial\Assets\Artwork\Materials\xplosive.mat
     文件       27312  2009-11-24 14:02  2DGameplayTutorial\Assets\Artwork\MovingPlatform.fbx
     文件       71762  2009-11-24 14:02  2DGameplayTutorial\Assets\Artwork\Platform Slope.fbx
     文件      122107  2009-11-24 14:02  2DGameplayTutorial\Assets\Artwork\Platforms.fbx
     文件      189600  2009-11-24 14:02  2DGameplayTutorial\Assets\Artwork\Spaceship.fbx
     目录           0  2009-11-24 14:02  2DGameplayTutorial\Assets\Artwork\Textures\
     文件      809020  2009-11-24 14:02  2DGameplayTutorial\Assets\Artwork\Textures\lerpzBump.tif
     文件     1079508  2009-11-24 14:02  2DGameplayTutorial\Assets\Artwork\Textures\lerpzUV.tif
............此处省略542个文件信息

评论

共有 条评论