public void OnTriggerEnter(Collider other) { if (other.tag == "Ingredient" && other.GetComponent <IngredientScript>().kind != Burger.fillings.MUSTARD && other.GetComponent <IngredientScript>().kind != Burger.fillings.KETCHUP) { Splattable splattable = other.GetComponent <Splattable>(); if (splattable == null) { Debug.LogError(other.name); } else { splattable.Splat(SplatType); } } }
void OnParticleCollision(GameObject other) { int numCollisionEvents = ParticlePhysicsExtensions.GetCollisionEvents(particleLauncher, other, collisionEvents); int i = 0; while (i < numCollisionEvents) { Splattable splatObject = collisionEvents [i].colliderComponent.gameObject.GetComponent <Splattable> (); if (splatObject != null) { splatObject.OnParticleSplat(collisionEvents [i], size, particleColorGradient); } else if (collisionEvents [i].colliderComponent.gameObject.GetComponent <Rigidbody> () == null) //Global only on static things { Splattable.SplatOnGlobal(collisionEvents [i], size, particleColorGradient); } i++; } }
private void QueueDirectionalSplat(Vector3 worldPos, Vector2 projectileDir) { Vector3 raycastDir = new Vector3(projectileDir.x, 0, projectileDir.y); RaycastHit[] collided = Physics.SphereCastAll(worldPos, sphereRadius, raycastDir, castDistance); if (collided.Length != 0) { #if UNITY_EDITOR if (debugSplats) { GameObject hitSphere = GameObject.CreatePrimitive(PrimitiveType.Capsule); hitSphere.transform.SetParent(debugMarkers.transform); hitSphere.transform.up = -raycastDir; hitSphere.transform.position = worldPos + raycastDir / 2F; hitSphere.transform.localScale = new Vector3(sphereRadius, castDistance, sphereRadius); hitSphere.GetComponent <Collider>().enabled = false; } #endif if (GoreEnabled) { SplatSO randomSplat = splats[Random.Range(0, splats.Length - 1)]; foreach (RaycastHit hit in collided) { Collider collider = hit.collider; GameObject obj = collider.gameObject; Splattable canSplat = obj.GetComponent <Splattable>(); if (canSplat) { canSplat.QueueNewSplat(randomSplat, worldPos, projectileDir); } } } } }
protected override void Awake() { base.Awake(); splattable = GetComponent <Splattable>(); Assert.IsNotNull(splattable); defaultRenderMask = splattable.RenderMask; if (MeshRenderer) { meshSizeX = meshRenderer.bounds.size.x; meshSizeY = meshRenderer.bounds.size.y; meshSizeZ = meshRenderer.bounds.size.z; Color emptyColor = new Color(0f, 0f, 0f, 0f); if (riseColor.IsAboutEqual(emptyColor)) { riseColor = Color.cyan.ChangeAlpha(.3f); flatColor = Color.black.ChangeAlpha(.8f); fallColor = Color.red.ChangeAlpha(.3f); } } colorShiftAnim.OnUpdate = OnColorChange; currentState = defaultState; InitializeStatePositions(); SetAlbedoColor(CurrentStateColor); }
LevelEditorObject LoadAssetPath(string assetPath, string relFolderPath) { string assetName = Path.GetFileName(assetPath); string relAssetPath = default(string); string trimmedPath = default(string); LevelEditorObject asset = default(LevelEditorObject); if (Application.isPlaying) { assetName = Path.GetFileNameWithoutExtension(assetName); relFolderPath = relFolderPath.Remove(0, "/Resources/".Length); relAssetPath = string.Format("{0}{1}", relFolderPath, assetName); //Debug.Log (relAssetPath); asset = Resources.Load <LevelEditorObject> (relAssetPath); //asset.SetPath(relAssetPath); } #if UNITY_EDITOR else { relAssetPath = string.Format("Assets{0}{1}", relFolderPath, assetName); asset = UnityEditor.AssetDatabase. LoadAssetAtPath <LevelEditorObject>(relAssetPath); trimmedPath = relAssetPath.Remove(0, string.Format("Assets{0}", LEVELOBJECT_PATH).Length); trimmedPath = trimmedPath.Remove(trimmedPath.IndexOf(".asset"), ".asset".Length); } #endif if (asset == default(LevelEditorObject)) { Debug.LogError(string.Format("Failed to load asset at {0}!", assetPath)); return(null); } asset.SetPath(trimmedPath); // Check prefab GameObject prefab = asset.Prefab; if (prefab == null) { Debug.LogWarning(string.Format("Asset {0} does not have a prefab!", asset)); return(null); } // Check splattable if (asset.NeedsSplattable) { Splattable splattable = asset.Prefab. GetComponentInChildren <Splattable>(); if (splattable == null) { Debug.LogWarning(string.Format(@"Asset {0} does not have a Splattable! If it doesn't need one, you can disable this check in the LevelEditorObject asset.", asset.Prefab.name), asset); } } return(asset); }