void CreateComposite(z_AdditionalVertexStreams vertexStream, bool applyToCurrent, string path = null) { GameObject go = vertexStream.gameObject; Mesh source = go.GetMesh(); Mesh stream = vertexStream.m_AdditionalVertexStreamMesh; if (source == null || stream == null) { Debug.LogWarning("Mesh filter or vertex stream mesh is null, cannot continue."); return; } if (applyToCurrent) { CreateCompositeMesh(source, stream, source); MeshRenderer renderer = go.GetComponent <MeshRenderer>(); if (renderer != null) { renderer.additionalVertexStreams = null; } GameObject.DestroyImmediate(vertexStream); } else { Mesh composite = new Mesh(); CreateCompositeMesh(source, stream, composite); if (string.IsNullOrEmpty(path)) { z_EditorUtility.SaveMeshAsset(composite, go.GetComponent <MeshFilter>(), go.GetComponent <SkinnedMeshRenderer>()); } else { AssetDatabase.CreateAsset(composite, path); MeshFilter mf = go.GetComponent <MeshFilter>(); SkinnedMeshRenderer smr = go.GetComponent <SkinnedMeshRenderer>(); if (mf != null) { mf.sharedMesh = composite; } else if (smr != null) { smr.sharedMesh = composite; } } Undo.DestroyObjectImmediate(vertexStream); } }
protected virtual void OnEnable() { this.hideFlags = HideFlags.HideAndDontSave; Component[] other = GetComponents <z_ZoomOverride>(); foreach (Component c in other) { if (c != this) { GameObject.DestroyImmediate(c); } } _additionalVertexStreams = gameObject.GetComponent <z_AdditionalVertexStreams>(); }
public override void OnInspectorGUI() { z_AdditionalVertexStreams avs = target as z_AdditionalVertexStreams; if (avs == null) { return; } MeshRenderer mr = avs.gameObject.GetComponent <MeshRenderer>(); GUILayout.Label("Additional Vertex Streams"); if (targets.Length > 1) { EditorGUI.showMixedValue = true; } EditorGUILayout.ObjectField(mr.additionalVertexStreams, typeof(Mesh), true); EditorGUI.showMixedValue = false; if (GUILayout.Button("Delete")) { foreach (z_AdditionalVertexStreams a in targets) { if (a == null) { continue; } mr = a.GetComponent <MeshRenderer>(); if (mr != null) { mr.additionalVertexStreams = null; } if (a.mesh != null) { Undo.DestroyObjectImmediate(a); Undo.RecordObject(mr, "Delete AdditionalVertexStreams"); } } } }
/** * Internal constructor. * \sa Create */ private z_EditableObject(GameObject go) { this.gameObject = go; isProBuilderObject = z_ReflectionUtil.IsProBuilderObject(go); Mesh advsMesh = null; MeshRenderer meshRenderer = this.gameObject.GetComponent <MeshRenderer>(); meshFilter = this.gameObject.GetComponent <MeshFilter>(); SkinnedMeshRenderer skinFilter = this.gameObject.GetComponent <SkinnedMeshRenderer>(); usingVertexStreams = false; this.originalMesh = meshFilter.sharedMesh; if (originalMesh == null && skinFilter != null) { this.originalMesh = skinFilter.sharedMesh; } if (z_Pref.GetBool(z_Pref.additionalVertexStreams, false) && !isProBuilderObject) { if (meshRenderer != null || skinFilter != null) { additionalVertexStreams = gameObject.GetComponent <z_AdditionalVertexStreams>(); if (additionalVertexStreams == null) { additionalVertexStreams = gameObject.AddComponent <z_AdditionalVertexStreams>(); } advsMesh = additionalVertexStreams.m_AdditionalVertexStreamMesh; if (advsMesh == null) { advsMesh = new Mesh(); advsMesh.vertices = originalMesh.vertices; advsMesh.name = string.Format("{0}({1})", originalMesh.name, additionalVertexStreams.GetInstanceID()); hadVertexStreams = false; } usingVertexStreams = true; } } if (!usingVertexStreams) { // if editing a non-scene instance mesh, make it an instance // (unity primitives are a special case - they *are* scene instances but they also aren't) string guid = INSTANCE_MESH_GUID; this.source = z_EditorUtility.GetMeshGUID(originalMesh, ref guid); if (source != z_ModelSource.Scene || UnityPrimitiveMeshNames.Contains(originalMesh.name)) { this._graphicsMesh = z_MeshUtility.DeepCopy(meshFilter.sharedMesh); } else { this._graphicsMesh = originalMesh; } } else { this._graphicsMesh = advsMesh; this.source = z_ModelSource.AdditionalVertexStreams; } // if it's a probuilder object rebuild the mesh without optimization if (isProBuilderObject) { object pb = probuilderMesh = go.GetComponent("pb_Object"); if (pb != null) { z_ReflectionUtil.ProBuilder_ToMesh(pb); z_ReflectionUtil.ProBuilder_Refresh(pb, (ushort)0xFF); } if (setVerticesMethod == null) { setVerticesMethod = pb.GetType().GetMethod( "SetVertices", BindingFlags.Public | BindingFlags.Instance, null, SetVerticesArguments, null); } if (setUvsMethod == null) { setUvsMethod = pb.GetType().GetMethod( "SetUVs", BindingFlags.Public | BindingFlags.Instance, null, SetUVsArguments, null); } if (setTangentsMethod == null) { setTangentsMethod = pb.GetType().GetMethod( "SetTangents", BindingFlags.Public | BindingFlags.Instance, null, new Type[] { typeof(Vector4[]) }, null); } if (setColorsMethod == null) { setColorsMethod = pb.GetType().GetMethod( "SetColors", BindingFlags.Public | BindingFlags.Instance, null, new Type[] { typeof(Color[]) }, null); } } _editMesh = GetCompositeMesh(); if (!isProBuilderObject) { SetMesh(graphicsMesh); } }