/// combine private void CombineFreeDecals() { ++_currentBasis; if (_currentBasis > _decalType.i_destroyGenerationDelay) { SendToDestroy(); } foreach (GameObject freeDecal in _freeDecals) { // MeshFilter mFilter = freeDecal.GetComponent<MeshFilter>(); Destroy(freeDecal); } _freeDecals.Clear(); MeshFilter combinedMeshFilter = this.GetComponent <MeshFilter>(); Destroy(combinedMeshFilter.sharedMesh); combinedMeshFilter.sharedMesh = DecalCreator.CreateCombinedMesh(_allDecalMeshes, null); combinedMeshFilter.sharedMesh.RecalculateBounds(); }
/// Send new decal public override void PushNewDecalMesh(Mesh newDecalMesh) { _timeSinceLastAdd = Time.time; newDecalMesh.name = _decalType.name + " " + "SkinnedDecalMesh"; _allDecalMeshes.Add(newDecalMesh); if (_N == _decalType.i_maxSkinnedDecals) { Destroy(_allDecalMeshes[0]); _allDecalMeshes.RemoveAt(0); } else { ++_N; } Mesh combinnedSkinnedMesh = DecalCreator.CreateCombinedMesh(_allDecalMeshes, null); combinnedSkinnedMesh.name = "Combinned Skinned Decal"; combinnedSkinnedMesh.bindposes = _sourceSMR.sharedMesh.bindposes; SkinnedMeshRenderer s = this.GetComponent <SkinnedMeshRenderer>() as SkinnedMeshRenderer; Destroy(s.sharedMesh); s.sharedMesh = combinnedSkinnedMesh; }
private void BurnDecal() { // If decal in scene exit if (EditorUtility.GetPrefabType(_decalType.gameObject) == PrefabType.ModelPrefab || EditorUtility.GetPrefabType(_decalType.gameObject) == PrefabType.Prefab) { return; } // Create meshes Plane[] planes = DecalCreator.CreatePlanes(_decalType); GameObject[] allGameObjects = FindObjectsOfType(typeof(GameObject)) as GameObject[]; foreach (GameObject g in allGameObjects) { // Mask if (_decalType.i_projectionMask == 0) { continue; } if ((_decalType.i_projectionMask & MeshTypes.Mesh) == 0) { if (g.GetComponent <MeshFilter>()) { continue; } } if ((_decalType.i_projectionMask & MeshTypes.SkinedMesh) == 0) { if (g.GetComponent <SkinnedMeshRenderer>()) { continue; } } if (_decalType.i_ignoreList.Contains(g) || g.GetComponent <DecalType>()) { continue; } CreateMeshList(planes, g); } if (_newMeshes.Count == 0) { return; } // Delete previous DestroyImmediate(_decalType.GetComponent <MeshFilter>().sharedMesh); Mesh combinedMesh = DecalCreator.CreateCombinedMesh(_newMeshes, null); DecalCreator.CreateStaticDecal(combinedMesh, null, _decalType); // Delete temp foreach (Mesh mesh in _newMeshes) { DestroyImmediate(mesh); } _newMeshes.Clear(); }
public void Init( DecalCreator creator, Vertex[] vertices, int[] indices, string materialName, MapObject parentMapObject) { this.creator = creator; this.vertices = vertices; this.indices = indices; this.sourceMaterialName = materialName; this.parentMapObject = parentMapObject; if( parentMapObject != null ) AddRelationship( parentMapObject ); CreateDecal(); }
private void RightFootStep() { RaycastHit hit; Ray ray = new Ray(i_rightFoot.position, -i_rightFoot.up); bool wasHit = Physics.Raycast(ray, out hit); if (wasHit) { Mesh decalMesh = DecalCreator.CreateDecalMesh(i_decalTypeRight, hit.point, -hit.normal, hit.collider.gameObject, i_rightFoot.forward); DecalCreator.CreateDynamicDecal(decalMesh, hit.collider.gameObject, i_decalTypeRight, null); } _right = false; }
///Shoot private void Fire() { if (Input.GetMouseButton(0) && _allowFire) { //Audio shoot //this.audio.PlayOneShot(this.audio.clip); RaycastHit hit; Ray ray = Camera.main.ViewportPointToRay(new Vector3(0.5F, 0.5F, 0)); bool wasHit = Physics.Raycast(ray, out hit); if (wasHit) { //Profiler.BeginSample("BURN DECAL ON TORUS"); //Burn decal Mesh decalMesh = DecalCreator.CreateDecalMesh(i_decalType, hit.point, -hit.normal, hit.collider.gameObject); //Create Decal Object DecalCreator.CreateDynamicDecal(decalMesh, hit.collider.gameObject, i_decalType); //Profiler.EndSample(); //If we hit character if (hit.collider.transform.root.name == "Enemy") { Blood(hit, ray.direction); hit.collider.transform.root.SendMessage("ApplyDamage", SendMessageOptions.DontRequireReceiver); SkinnedMeshRenderer smr = hit.collider.transform.root.GetComponentInChildren <SkinnedMeshRenderer>(); SkinDecal(hit, smr.gameObject); } else { Dust(hit); } } StartCoroutine(Delay()); } }
private void CreateMeshList(Plane[] planes, GameObject g) { if (!g) { return; } if ((g.GetComponent <Renderer>() && GeometryUtility.TestPlanesAABB(planes, g.GetComponent <Renderer>().bounds)) || g.GetComponent <Terrain>() != null) { Mesh mesh = DecalCreator.CreateDecalMesh(_decalType, _decalType.transform.position, _decalType.transform.forward, g, Vector3.zero); if (mesh) { mesh.name = "Temp decal"; if (mesh.vertices.Length > 0) { _newMeshes.Add(mesh); } else { DestroyImmediate(mesh); } } } }
///Skin decal private void SkinDecal(RaycastHit hit, GameObject objWithSkin) { Mesh decalMesh = DecalCreator.CreateDecalMesh(i_blood, hit.point, -hit.normal, objWithSkin, Vector3.zero); DecalCreator.CreateDynamicSkinnedDecal(decalMesh, objWithSkin, i_blood, null); }
//Update is called once per frame private void Start() { //Combine all uncombined Decals DecalCreator.CreateCombinedStaticDecalInGame(); //Profiler.enabled = true; }
protected void OnSceneGUI() { // Safe deleting meshes if (Event.current.Equals(Event.KeyboardEvent("delete"))) { foreach (GameObject obj in Selection.gameObjects) { if (obj.GetComponent <DecalType>()) { DestroyImmediate(obj.GetComponent <MeshFilter>().sharedMesh); } } } // Not show if prefab if (PrefabUtility.IsPartOfPrefabAsset(_decalType.gameObject) || !_decalType.gameObject.activeSelf) { return; } if (Event.current.keyCode == KeyCode.Escape) { _dWasPressed = false; _sWasPressed = false; _cWasPressed = false; } #region HANDLES // Ignor foreach (GameObject g in _decalType.i_ignoreList) { GUI.color = Color.red; if (g) { Handles.Label(g.transform.position, "Ignore"); } GUI.color = Color.white; } // Combine if (_decalType.ObjectForCombining) { GUI.color = Color.blue; Handles.Label(_decalType.ObjectForCombining.transform.position, "Combine"); GUI.color = Color.white; } #endregion #region GUI Handles.BeginGUI(); float panelYPos = Screen.height - 55; //Panel GUI.Box(new Rect(-5, panelYPos, Screen.width + 10, 20), "", EditorStyles.toolbar); GUI.Box(new Rect(Screen.width / 2 + 150, Screen.height - 80, 300, 20), " Use MMB to pick objects or set decal position"); // Proj type _decalType._decalDragProjectionType = (DecalDragProjectionType)GUI.Toolbar(new Rect(0, Screen.height - 55, 165, 20), (int)_decalType._decalDragProjectionType, new GUIContent[2] { new GUIContent("Along Camera", "Project decal onto mesh using camera direction"), new GUIContent("Along Normal", "Project decal onto mesh using mesh normal") }, EditorStyles.toolbarButton); //Pick if (!_dWasPressed && !_sWasPressed && !_cWasPressed) { if (GUI.Button(new Rect(Screen.width / 2 - 149, Screen.height - 80, 100, 20), "Pick Ignore")) { _cWasPressed = true; } if (GUI.Button(new Rect(Screen.width / 2 - 50, Screen.height - 80, 100, 20), "Pick Combine")) { _sWasPressed = true; } if (GUI.Button(new Rect(Screen.width / 2 + 49, Screen.height - 80, 100, 20), "Set Position")) { _dWasPressed = true; } } if (_dWasPressed || _sWasPressed || _cWasPressed) { HandleUtility.Repaint(); if (GUI.Button(new Rect(Screen.width / 2 - 90, Screen.height - 80, 95, 20), "Cancel")) { _sWasPressed = _cWasPressed = _dWasPressed = false; } } //Clear ignor if (GUI.Button(new Rect(165, panelYPos, 75, 20), new GUIContent("Clear Ignore", "Clears ignorlist for this decal"), EditorStyles.toolbarButton)) { _decalType.i_ignoreList.Clear(); } // Combine if (GUI.Button(new Rect(615, panelYPos, 55, 20), new GUIContent("Combine", "Combine selected decals in one mesh. Hold down D+S buttons and select parent object"), EditorStyles.toolbarButton)) { Undo.RegisterSceneUndo("Combine Static Decals"); List <DecalType> decalTypes = new List <DecalType>(); foreach (Transform t in Selection.transforms) { if (t.GetComponent("DecalType") as DecalType) { decalTypes.Add(t.GetComponent("DecalType") as DecalType); } } if (EditorUtility.DisplayDialog("Combining", "Destroy Decal Objects", "Yes", "No")) { Selection.activeGameObject = DecalCreator.CreateCombinedStaticDecalInEditor(decalTypes, _decalType.ObjectForCombining, true); } else { Selection.activeGameObject = DecalCreator.CreateCombinedStaticDecalInEditor(decalTypes, _decalType.ObjectForCombining, false); } } GUI.contentColor = Color.black; GUI.Label(new Rect(360, panelYPos, 150, 20), new GUIContent("Combine Object", "Parent object for combining, if NULL decals will be combine in world space")); GUI.contentColor = Color.white; _decalType.ObjectForCombining = EditorGUI.ObjectField(new Rect(455, panelYPos, 150, 18), _decalType.ObjectForCombining, typeof(GameObject)) as GameObject; if (Event.current.type == EventType.MouseUp && new Rect(500, panelYPos, 150, 20).Contains(Event.current.mousePosition)) { Selection.objects = _selectedObjects; } if (Event.current.type == EventType.DragExited) { Selection.objects = _selectedObjects; _decalType.ObjectForCombining = DragAndDrop.objectReferences[0] as GameObject; } // Skin Combine if (GUI.Button(new Rect(670, panelYPos, 105, 20), new GUIContent("Combine With Skin", "Combine selected decals with skinned mesh"), EditorStyles.toolbarButton)) { Undo.RegisterSceneUndo("Combine decal with skin"); if (_decalType.ObjectForCombining) { if (_decalType.ObjectForCombining.GetComponent <SkinnedMeshRenderer>()) { // All decals from select List <DecalType> decalTypes = new List <DecalType>(); foreach (Transform t in Selection.transforms) { if (t.GetComponent("DecalType") as DecalType) { decalTypes.Add(t.GetComponent("DecalType") as DecalType); } } if (EditorUtility.DisplayDialog("Combining", "Destroy Decal Objects", "Yes", "No")) { DecalCreator.CreateCombinedSkinDecalInEditor(decalTypes, _decalType.ObjectForCombining, true); } else { DecalCreator.CreateCombinedSkinDecalInEditor(decalTypes, _decalType.ObjectForCombining, false); } } else { throw new MissingComponentException("Combinning object have no SkinnedMeshRenderer component"); } } else { throw new MissingReferenceException("Combinning object have NULL reference"); } } // Mask GUIStyle meshButton = new GUIStyle(EditorStyles.toolbarButton); if ((_decalType.i_projectionMask & MeshTypes.Mesh) != 0) { meshButton.normal.background = EditorStyles.toolbarButton.onActive.background; } else { meshButton.normal.background = EditorStyles.toolbarButton.normal.background; } GUIStyle skinedMeshButton = new GUIStyle(EditorStyles.toolbarButton); if ((_decalType.i_projectionMask & MeshTypes.SkinedMesh) != 0) { skinedMeshButton.normal.background = EditorStyles.toolbarButton.onActive.background; } else { skinedMeshButton.normal.background = EditorStyles.toolbarButton.normal.background; } if (GUI.Button(new Rect(255, panelYPos, 40, 20), new GUIContent("Mesh", "Project decal onto mesh"), meshButton)) { if ((_decalType.i_projectionMask & MeshTypes.Mesh) != 0) { _decalType.i_projectionMask ^= MeshTypes.Mesh; } else { _decalType.i_projectionMask |= MeshTypes.Mesh; } } if (GUI.Button(new Rect(295, panelYPos, 40, 20), new GUIContent("Skin", "Project decal onto skin"), skinedMeshButton)) { if ((_decalType.i_projectionMask & MeshTypes.SkinedMesh) != 0) { _decalType.i_projectionMask ^= MeshTypes.SkinedMesh; } else { _decalType.i_projectionMask |= MeshTypes.SkinedMesh; _decalType.i_boneWeights = true; } } Handles.EndGUI(); #endregion // Key Buttons if (Event.current.keyCode == KeyCode.D && Event.current.type == EventType.KeyDown) { _dWasPressed = true; } if (Event.current.keyCode == KeyCode.D && Event.current.type == EventType.KeyUp) { _dWasPressed = false; } if (Event.current.keyCode == KeyCode.C && Event.current.type == EventType.KeyDown && _dWasPressed) { _cWasPressed = true; } if (Event.current.keyCode == KeyCode.C && Event.current.type == EventType.KeyUp) { _cWasPressed = false; } if (Event.current.keyCode == KeyCode.S && Event.current.type == EventType.KeyDown && _dWasPressed) { _sWasPressed = true; } if (Event.current.keyCode == KeyCode.S && Event.current.type == EventType.KeyUp) { _sWasPressed = false; } // Smart pos if (_cWasPressed)//C { Selection.objects = _selectedObjects; if (Event.current.type == EventType.MouseDown && Event.current.button == 2) { Event.current.Use(); GameObject pickedObject = HandleUtility.PickGameObject(Event.current.mousePosition, false); if (pickedObject && pickedObject != _decalType.gameObject && !(pickedObject.GetComponent("DecalType") as DecalType)) { if (!_decalType.i_ignoreList.Contains(pickedObject)) { _decalType.i_ignoreList.Add(pickedObject); } else { _decalType.i_ignoreList.Remove(pickedObject); } } } } else if (_sWasPressed)//S { Selection.objects = _selectedObjects; if (Event.current.type == EventType.MouseDown && Event.current.button == 2) { Event.current.Use(); GameObject pickedObject = HandleUtility.PickGameObject(Event.current.mousePosition, false); if (pickedObject && !(pickedObject.GetComponent("DecalType") as DecalType)) { if (pickedObject == _decalType.ObjectForCombining) { _decalType.ObjectForCombining = null; } else { _decalType.ObjectForCombining = pickedObject; } } } } else//Only D { if (_dWasPressed && Event.current.type == EventType.MouseDown && Event.current.button == 2) { Selection.objects = _selectedObjects; _drag = true; } if (Event.current.type == EventType.MouseUp) { _drag = false; } if (_drag) { Event.current.Use(); RaycastHit hit; Physics.Raycast(HandleUtility.GUIPointToWorldRay(Event.current.mousePosition), out hit); if (hit.collider) { _decalType.transform.position = hit.point; if (_decalType._decalDragProjectionType == DecalDragProjectionType.AlongSurfaceNormal) { _decalType.transform.rotation = Quaternion.LookRotation(-hit.normal, Vector3.up); } else { _decalType.transform.rotation = Quaternion.LookRotation(HandleUtility.GUIPointToWorldRay(Event.current.mousePosition).direction, Vector3.up); } } } } // Save selection _selectedObjects = Selection.gameObjects; Repaint(); }