protected void Start() { myMaterial = GetComponent <ObjectWithMaterial>().PiekaMaterial; myCollider = GetComponent <Collider2D>(); myPhysicsMaterial = myCollider.sharedMaterial; myPhysicsMaterial.friction = MaterialFrictionTable.Default; }
private void detect(Car car, ContactPoint2D[] burnContacts, PiekaMaterial frontWheelMaterial, PiekaMaterial rearWheelMaterial) { var velocityInKmPerH = CalculateUtils.UnitsPerSecondToKmPerH(car.FrontPartRigidbody.velocity.magnitude); handleBurn(car.FrontWheelCollider, car.FrontWheelSpriteRenderer, BurnInfo.WhichWheelEnum.FRONT, car.FrontWheel.AngularVelocity < 0 ? BurnInfo.DirectionEnum.LEFT : BurnInfo.DirectionEnum.RIGHT, car.Drive.FrontWheelKmPerH, velocityInKmPerH, burnContacts, frontWheelMaterial); handleBurn(car.RearWheelCollider, car.RearWheelSpriteRenderer, BurnInfo.WhichWheelEnum.REAR, car.RearWheel.AngularVelocity < 0 ? BurnInfo.DirectionEnum.LEFT : BurnInfo.DirectionEnum.RIGHT, car.Drive.RearWheelKmPerH, velocityInKmPerH, burnContacts, rearWheelMaterial); }
public override void OnInspectorGUI() { var myTarget = (PiekaMaterialEffectTable)target; myTarget.defaultEffect = (Effect)EditorGUILayout.ObjectField("Default effect", myTarget.defaultEffect, typeof(Effect), false); EditorGUILayout.Space(); var dictionary = myTarget.dictionary; var keys = new List <MaterialMaterialPair>(dictionary.Keys); foreach (var key in keys) { EditorGUILayout.ObjectField("First", key.Key, typeof(PiekaMaterial), false); EditorGUILayout.ObjectField("Second", key.Value, typeof(PiekaMaterial), false); dictionary[key] = (Effect)EditorGUILayout.ObjectField("Effect", dictionary[key], typeof(Effect), false); if (GUILayout.Button("Delete")) { dictionary.Remove(key); } EditorGUILayout.Space(); } EditorGUILayout.Space(); material1 = (PiekaMaterial)EditorGUILayout.ObjectField("First", material1, typeof(PiekaMaterial), false); material2 = (PiekaMaterial)EditorGUILayout.ObjectField("Second", material2, typeof(PiekaMaterial), false); effect = (Effect)EditorGUILayout.ObjectField("Effect", effect, typeof(Effect), false); if (GUILayout.Button("Add")) { dictionary.Add(new MaterialMaterialPair(material1, material2), effect); } EditorUtility.SetDirty(myTarget); }
public BurnInfo(WhichWheelEnum whichWheel, DirectionEnum direction, Vector2 point, float power, GameObject otherGameObject, PiekaMaterial wheelMaterial) { WhichWheel = whichWheel; Direction = direction; Point = point; Power = power; OtherGameObject = otherGameObject; WheelMaterial = wheelMaterial; }
public Effect GetEffect(PiekaMaterial material1, PiekaMaterial material2) { var key = new MaterialMaterialPair(material1, material2); if (!dictionary.ContainsKey(key)) { return(defaultEffect); } return(dictionary[key]); }
public float GetFloat(PiekaMaterial material1, PiekaMaterial material2) { var key = new MaterialMaterialPair(material1, material2); if (!dictionary.ContainsKey(key)) { return(Default); } return(dictionary[key]); }
private void handleBurn(Collider2D wheelCollider, SpriteRenderer spriteRenderer, BurnInfo.WhichWheelEnum whichWheel, BurnInfo.DirectionEnum direction, float wheelKmPerH, float velocityInKmPerH, ContactPoint2D[] burnContacts, PiekaMaterial piekaMaterial) { if (wheelCollider.IsTouchingLayers(Consts.FloorLayerMask)) { var carSpeedPlusAcceptableDifference = velocityInKmPerH + AcceptableSpeedDifference; var wheelSpeed = wheelKmPerH; if (wheelSpeed > carSpeedPlusAcceptableDifference) { var filter = new ContactFilter2D(); filter.layerMask = Consts.FloorLayerMask; var numberOfContacts = wheelCollider.GetContacts(filter, burnContacts); for (int i = 0; i < numberOfContacts; i++) { SEventSystem.FireEvent(EventNames.TEST); var gameObject = burnContacts[i].collider.gameObject; var point = burnContacts[i].point; var power = Mathf.Clamp((wheelSpeed - carSpeedPlusAcceptableDifference) / BurnSpeedRange, 0, 1); var burnInfo = new BurnInfo(whichWheel, direction, point, power, gameObject, piekaMaterial); SEventSystem.FireEvent(EventNames.WHEEL_BURN, new PMEventArgs(burnInfo)); } } } }
public MaterialMaterialPair(PiekaMaterial key, PiekaMaterial value) { Key = key; Value = value; }