/////////////////////////////////////////////////////////////////////////////////////////////////////// /// <summary> /// BuildMesh /// # Creates decal's mesh and applys new texture coords /// </summary> /////////////////////////////////////////////////////////////////////////////////////////////////////// public void BuildMesh(GenericMeshDecal decal) { MeshFilter filter = decal.GetComponent <MeshFilter> (); if (filter == null) { filter = decal.gameObject.AddComponent <MeshFilter> (); } if (decal.GetComponent <Renderer> () == null) { decal.gameObject.AddComponent <MeshRenderer> (); } decal.GetComponent <Renderer> ().material = decal.material; if (decal.material == null || decal.sprite == null) { filter.mesh = null; return; } affectedObjects = BasicFunctions.GetAllAffectedObjects(BasicFunctions.GetTransformBounds(decal.transform), decal.affectedLayers); foreach (GameObject go in affectedObjects) { if (!go.GetComponent <WayPoint> () && !go.GetComponent <GenericMeshDecal> ()) { BasicFunctions.BuildDecalForObject(decal, go); } } BasicFunctions.Push(decal.distanceFromHit); Mesh mesh = null; if (planarDecal) { mesh = CreatePlanarMesh(1, 1); } else { mesh = BasicFunctions.CreateMesh(); //// ModifyPlanarMesh (ref mesh, 1, 1); } if (mesh != null) { mesh.name = "GenericPoly"; filter.mesh = mesh; } }
/////////////////////////////////////////////////////////////////////////////////////////////////////// /// <summary> /// CreateNewDecal /// # Create a new mesh decal in the scene /// </summary> /////////////////////////////////////////////////////////////////////////////////////////////////////// public GenericMeshDecal CreateNewMeshDecal(Material decalMaterial, Transform parent, Vector3 point, Vector3 normal, float scaleMultiplier, Vector2 rotationRange, bool attachDecalToCollisionObject) { //print ("CreateNewDecal"); GenericMeshDecal actualDecal = Instantiate(decalPrefab.gameObject).GetComponent <GenericMeshDecal> (); actualDecal.material = decalMaterial; actualDecal.transform.position = point + 0.001f * normal; actualDecal.transform.localScale = scaleMultiplier * actualDecal.transform.localScale; actualDecal.transform.rotation = Quaternion.FromToRotation(Vector3.up, normal); if (attachDecalToCollisionObject) { actualDecal.transform.parent = parent; } else { GameObject decalsContainer = BasicFunctions.CreateContainerIfNotExists(BasicDefines.MESH_DECAL_CONTAINER_NAME); actualDecal.transform.parent = decalsContainer.transform; } actualDecal.rotationRange = rotationRange; actualDecal.name = "RunTimeDecal"; actualDecal.UpdateDecallShape(true, false); return(actualDecal.GetComponent <GenericMeshDecal> ()); }
/////////////////////////////////////////////////////////////////////////////////////////////////////// /// <summary> /// OnInspectorGUI /// </summary> /////////////////////////////////////////////////////////////////////////////////////////////////////// public override void OnInspectorGUI() { GenericMeshDecal decal = (GenericMeshDecal)target; bool updateShape = false; if (decal.material) { string actualMaterialName = decal.material.name; decal.material = EditorBasicFunctions.DrawMeshDecalElements(decal, false, new Rect(0, 0, EditorGUIUtility.currentViewWidth, EditorGUIUtility.singleLineHeight), null); if (decal.material.name != actualMaterialName) { updateShape = true; //Debug.Log ("Material Change: "+decal.material); decal.GetComponent <Renderer>().sharedMaterial = decal.material; } } if (GUI.changed || updateShape) { decal.UpdateDecallShape(false, false); } }