public override void HandleEvent() { //float timeDiff = Time.time - m_lastTime; // m_lastTime = Time.time; // Debug.Log("Time since last footstep: " + timeDiff); if (FootstepPool == null || FootprintPool == null || (TargetBody == null && TargetAgent == null)) { Debug.LogWarning("Cannot issue footsteps due to missing parameter-objects"); return; } // TODO: Make this related to player move speed float speed = TargetBody != null ? TargetBody.velocity.magnitude : TargetAgent.velocity.magnitude; GameObject footstep = FootstepPool.ActivateObject(); GameObject footprint = FootprintPool.ActivateObject(); Vector3 footPosition = m_currentFootIsLeft ? LeftFoot.transform.position : RightFoot.transform.position; if (footstep != null) { footstep.transform.position = transform.position + new Vector3(0.0f, 1.0f, 0.0f); NoiseRipple ripple = footstep.GetComponent <NoiseRipple>(); if (ripple != null) { ripple.maxScale = speed; } if (footprint != null) { Vector3 printPosition = new Vector3(footPosition.x, footprint.transform.position.y, footPosition.z); footprint.transform.position = printPosition; footprint.transform.localRotation = transform.rotation; m_currentFootIsLeft = !m_currentFootIsLeft; } } // Deal with making an ear-hear-noise-screech // TODO: The 5.0f here should be the difference between floors, but it doesn't really matter RaycastHit hitInfo; if (Physics.Raycast(footPosition + Vector3.up, -Vector3.up, out hitInfo, 5.0f, RaycastFootstepMask)) { FloorFootstep surface = hitInfo.collider.gameObject.GetComponent <FloorFootstep>(); if (surface != null) { if (surface.SurfaceAudioSource != null) { Debug.Log("PLAYING FOOTSTEP"); surface.SurfaceAudioSource.Play(); } } } }
private void BuildFloor(Room room, GameObject floorObject) { GameObjectUtility.SetStaticEditorFlags(floorObject, StaticEditorFlags.NavigationStatic); Building building = (Building)target; MeshRenderer renderer = floorObject.AddComponent <MeshRenderer>(); MeshFilter filter = floorObject.AddComponent <MeshFilter>(); GameObject colliderObject = new GameObject("collider"); MeshCollider collider = colliderObject.AddComponent <MeshCollider>(); FloorFootstep surface = colliderObject.AddComponent <FloorFootstep>(); surface.SurfaceAudioSource = room.FloorAudioSource; colliderObject.layer = LayerMask.NameToLayer("Floor"); colliderObject.transform.parent = floorObject.transform; colliderObject.transform.localPosition = Vector3.zero; colliderObject.transform.localRotation = Quaternion.identity; colliderObject.transform.localScale = Vector3.one; string floorMeshName = building.BuildingName + "_" + room.Name + "_" + Building.s_floor_id; UnityEngine.Object floorMesh = AssetHelper.Instance.FindAsset <Mesh>(floorMeshName); UnityEngine.Object floorMaterial = AssetHelper.Instance.FindAsset <Material>(floorMeshName); if (floorMesh != null) { filter.mesh = floorMesh as Mesh; collider.sharedMesh = floorMesh as Mesh; } else { Debug.Log("Mesh Missing: " + floorMeshName); } if (floorMaterial != null) { renderer.material = floorMaterial as Material; } else { Debug.Log("Material Missing: " + floorMeshName); Shader flatShader = AssetHelper.Instance.FindAsset <Shader>("FlatColour") as Shader; Material newMaterial = new Material(flatShader); newMaterial.color = Color.red; string directory = System.IO.Path.GetDirectoryName(Application.dataPath + "/Materials/structures/" + building.BuildingName + "/" + floorMeshName + ".mat"); if (!System.IO.Directory.Exists(directory)) { System.IO.Directory.CreateDirectory(directory); } string path = "Assets/Materials/structures/" + building.BuildingName + "/" + floorMeshName + ".mat"; try { AssetDatabase.CreateAsset(newMaterial, path); } catch (UnityException e) { Debug.LogError(e.ToString()); } renderer.material = newMaterial as Material; } }