本文整理汇总了C#中pb_Object.GetComponent方法的典型用法代码示例。如果您正苦于以下问题:C# pb_Object.GetComponent方法的具体用法?C# pb_Object.GetComponent怎么用?C# pb_Object.GetComponent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pb_Object
的用法示例。
在下文中一共展示了pb_Object.GetComponent方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Mirror
/**
* \brief Duplicates and mirrors the passed pb_Object.
* @param pb The donor pb_Object.
* @param axe The axis to mirror the object on.
* \returns The newly duplicated pb_Object.
* \sa ProBuilder.Axis
*/
public static pb_Object Mirror(pb_Object pb, Vector3 scale)
{
pb_Object p = pb_Object.InitWithObject(pb);
p.MakeUnique();
p.transform.parent = pb.transform.parent;
p.transform.localRotation = pb.transform.localRotation;
Vector3 lScale = p.gameObject.transform.localScale;
p.transform.localScale = new Vector3(lScale.x * scale.x, lScale.y * scale.y, lScale.z * scale.z);
// if flipping on an odd number of axes, flip winding order
if( (scale.x * scale.y * scale.z) < 0)
p.ReverseWindingOrder(p.faces);
p.FreezeScaleTransform();
p.transform.localScale = pb.transform.localScale;
Collider col = pb.GetComponent<Collider>();
ColliderType colType = ColliderType.None;
if(col != null)
{
if(col is MeshCollider)
colType = ColliderType.MeshCollider;
else
colType = ColliderType.BoxCollider;
}
pb_Editor_Utility.InitObjectFlags(p, colType, pb.GetComponent<pb_Entity>().entityType);
p.ToMesh();
p.Refresh();
// InitObjectFlags runs ScreenCenter()
p.transform.position = pb.transform.position;
Undo.RegisterCreatedObjectUndo(p.gameObject, "Mirror Object");
return p;
}
示例2: OnFaceChanged
private static void OnFaceChanged( pb_Object pb )
{
StaticEditorFlags flags = GameObjectUtility.GetStaticEditorFlags( pb.gameObject );
// if nodraw found
if(pb.containsNodraw)
{
if( (flags & StaticEditorFlags.BatchingStatic) == StaticEditorFlags.BatchingStatic )
{
flags ^= StaticEditorFlags.BatchingStatic;
GameObjectUtility.SetStaticEditorFlags(pb.gameObject, flags);
}
}
else
{
// if nodraw not found, and entity type should be batching static
if(pb.GetComponent<pb_Entity>().entityType != EntityType.Mover)
{
flags = flags | StaticEditorFlags.BatchingStatic;
GameObjectUtility.SetStaticEditorFlags(pb.gameObject, flags);
}
}
}
示例3: CombineObjects
/**
* \brief Given an array of "donors", this method returns a merged #pb_Object.
*/
public static bool CombineObjects(pb_Object[] pbs, out pb_Object combined)
{
combined = null;
if(pbs.Length < 1) return false;
List<Vector3> v = new List<Vector3>();
List<Vector2> u = new List<Vector2>();
List<Color> c = new List<Color>();
List<pb_Face> f = new List<pb_Face>();
List<pb_IntArray> s = new List<pb_IntArray>();
List<pb_IntArray> suv = new List<pb_IntArray>();
foreach(pb_Object pb in pbs)
{
int vertexCount = v.Count;
// Vertices
v.AddRange(pb.VerticesInWorldSpace());
// UVs
u.AddRange(pb.uv);
// Colors
c.AddRange(pb.colors);
// Faces
pb_Face[] faces = new pb_Face[pb.faces.Length];
for(int i = 0; i < faces.Length; i++)
{
faces[i] = new pb_Face(pb.faces[i]);
faces[i].manualUV = true;
faces[i].ShiftIndices(vertexCount);
faces[i].RebuildCaches();
}
f.AddRange(faces);
// Shared Indices
pb_IntArray[] si = pb.GetSharedIndices();
for(int i = 0; i < si.Length; i++)
{
for(int n = 0; n < si[i].Length; n++)
si[i][n] += vertexCount;
}
s.AddRange(si);
// Shared Indices UV
{
pb_IntArray[] si_uv = pb.GetSharedIndicesUV();
for(int i = 0; i < si_uv.Length; i++)
{
for(int n = 0; n < si_uv[i].Length; n++)
si_uv[i][n] += vertexCount;
}
suv.AddRange(si_uv);
}
}
GameObject go = (GameObject)GameObject.Instantiate(pbs[0].gameObject);
go.transform.position = Vector3.zero;
go.transform.localRotation = Quaternion.identity;
go.transform.localScale = Vector3.one;
// Destroy the children
foreach(Transform t in go.transform)
GameObject.DestroyImmediate(t.gameObject);
if(go.GetComponent<pb_Object>()) GameObject.DestroyImmediate(go.GetComponent<pb_Object>());
if(go.GetComponent<pb_Entity>()) GameObject.DestroyImmediate(go.GetComponent<pb_Entity>());
combined = go.AddComponent<pb_Object>();
combined.SetVertices(v.ToArray());
combined.SetUV(u.ToArray());
combined.SetColors(c.ToArray());
combined.SetFaces(f.ToArray());
combined.SetSharedIndices( s.ToArray() ?? pb_IntArrayUtility.ExtractSharedIndices(v.ToArray()) );
combined.SetSharedIndicesUV( suv.ToArray() ?? new pb_IntArray[0] {});
combined.ToMesh();
combined.GetComponent<pb_Entity>().SetEntity( pbs[0].GetComponent<pb_Entity>().entityType );
combined.CenterPivot( pbs[0].transform.position );
combined.Refresh();
// refresh donors since deleting the children of the instantiated object could cause them to lose references
foreach(pb_Object pb in pbs)
pb.Verify();
return true;
}