public static void UpdateMaterials( FrameContainer frames, int[] colors, float[] lights, MaterialPropertyBlock materialPropertyBlock) { var indices = CarColors.FromIndices(colors); Color32 headLightColor = new Color32(255, 255, 255, 255); Color32 tailLightColor = new Color32(255, 255, 255, 255); // compute car colors Color32[] carColors = new [] { new Color32(255, 255, 255, 255), indices[0], indices[1], indices[2], indices[3], headLightColor, headLightColor, tailLightColor, tailLightColor, }; // compute car emissions float[] carEmissions = new[] { 0f, 0f, 0f, 0f, 0f, Mathf.Exp(lights[0] * 2) - 1, Mathf.Exp(lights[1] * 2) - 1, Mathf.Exp(lights[2] * 2) - 1, Mathf.Exp(lights[3] * 2) - 1, }; foreach (var frame in frames) { var mr = frame.GetComponent <MeshRenderer>(); if (mr == null) { continue; } // get color index from each material, and assign properties accordingly var materials = mr.sharedMaterials; for (int i = 0; i < materials.Length; i++) { int carColorIndex = materials[i].GetInt(Importing.Conversion.Geometry.CarColorIndexId); materialPropertyBlock.SetColor(CarColorPropertyId, carColors[carColorIndex]); materialPropertyBlock.SetFloat(CarEmissionPropertyId, carEmissions[carColorIndex]); mr.SetPropertyBlock(materialPropertyBlock, i); } } }
public static void SetColors(FrameContainer frames, int[] colors) { var props = new MaterialPropertyBlock(); var indices = CarColors.FromIndices(colors); int[] vehicleColorIds = Vehicle.CarColorIds; for (int i = 0; i < vehicleColorIds.Length; ++i) { props.SetColor(vehicleColorIds[i], indices[i]); } foreach (var mr in frames.Select(f => f.GetComponent <MeshRenderer>()).Where(mr => mr != null)) { mr.SetPropertyBlock(props); } }
private void UpdateColors() { _colorsChanged = false; var indices = CarColors.FromIndices(_colors); for (var i = 0; i < 4; ++i) { _props.SetColor(CarColorIds[i], indices[i]); } _props.SetVector(LightsId, new Vector4(_lights[0], _lights[1], _lights[2], _lights[3])); foreach (var frame in _frames) { var mr = frame.GetComponent <MeshRenderer>(); if (mr == null) { continue; } mr.SetPropertyBlock(_props); } }