public static NetLaneProps Clone(this NetLaneProps nLP, string newName = null) { var newNLP = ScriptableObject.CreateInstance <NetLaneProps>(); if (newName != null) { newNLP.name = newName; } else { if (nLP != null) { newNLP.name = nLP.name; } } if (nLP == null || nLP.m_props == null) { newNLP.m_props = new NetLaneProps.Prop[0]; } else { newNLP.m_props = nLP.m_props.Where(p => p != null).Select(p => p.ShallowClone()).ToArray(); } return(newNLP); }
// Replace road sign prop x with road sign prop y: public static void ReplaceRoadsignProp(NetLaneProps affectedProps, CustomizableRoadsignItem affectedSign, int selectedValue) { // Init: PropInfo oldProp = (selectedValue == 0) ? PrefabCollection <PropInfo> .FindLoaded(affectedSign._originalSign.name) : PrefabCollection <PropInfo> .FindLoaded(affectedSign._customSign.name); PropInfo newProp = (selectedValue == 0) ? PrefabCollection <PropInfo> .FindLoaded(affectedSign._customSign.name) : PrefabCollection <PropInfo> .FindLoaded(affectedSign._originalSign.name); // Null check: if (!newProp) { return; } foreach (var prop in affectedProps.m_props) { if (prop.m_prop != null) { var propInstance = prop.m_finalProp; if (propInstance == null) { continue; } if (propInstance.name == oldProp.name || propInstance.name == newProp.name) { // Make visible: prop.m_prop.m_maxRenderDistance = 1000; prop.m_prop.m_maxScale = 1; prop.m_prop.m_minScale = 1; prop.m_finalProp = newProp; prop.m_prop = newProp; } } } }
private static void SetLane(NetInfo.Lane newLane, NetInfo.Lane closestLane) { newLane.m_direction = closestLane.m_direction; newLane.m_finalDirection = closestLane.m_finalDirection; newLane.m_allowConnect = closestLane.m_allowConnect; newLane.m_allowStop = closestLane.m_allowStop; if (closestLane.m_allowStop) { closestLane.m_allowStop = false; closestLane.m_stopOffset = 0; } if (newLane.m_allowStop) { if (newLane.m_position < 0) { newLane.m_stopOffset = -1f; } else { newLane.m_stopOffset = 1f; } } newLane.m_laneType = closestLane.m_laneType; newLane.m_similarLaneCount = closestLane.m_similarLaneCount = closestLane.m_similarLaneCount + 1; newLane.m_similarLaneIndex = closestLane.m_similarLaneIndex + 1; newLane.m_speedLimit = closestLane.m_speedLimit; newLane.m_vehicleType = closestLane.m_vehicleType; newLane.m_verticalOffset = closestLane.m_verticalOffset; newLane.m_width = closestLane.m_width; NetLaneProps templateLaneProps; if (closestLane.m_laneProps != null) { templateLaneProps = closestLane.m_laneProps; } else { templateLaneProps = new NetLaneProps(); } if (templateLaneProps.m_props == null) { templateLaneProps.m_props = new NetLaneProps.Prop[0]; } if (newLane.m_laneProps == null) { newLane.m_laneProps = new NetLaneProps(); } newLane.m_laneProps.m_props = templateLaneProps .m_props .Select(p => p.ShallowClone()) .ToArray(); }
static NetLaneProps GetNetLaneProps(Package p, PackageReader r) { int count = r.ReadInt32(); NetLaneProps laneProps = ScriptableObject.CreateInstance <NetLaneProps>(); laneProps.m_props = new NetLaneProps.Prop[count]; for (int i = 0; i < count; i++) { laneProps.m_props[i] = GetNetLaneProp(p, r); } return(laneProps); }
private void DumpPropsofString(string findString) { for (int i = 0; i < loadedPrefab.m_lanes.Length; i++) { NetLaneProps LaneJProps = loadedPrefab.m_lanes[i].m_laneProps; for (int j = 0; j < LaneJProps.m_props.Length; j++) { PropInfo a = loadedPrefab.m_lanes[i].m_laneProps.m_props[j].m_prop; if (a.name.Contains(findString)) { DumpUtil.DumpMeshAndTextures(a.name, a.m_mesh, a.m_material); propsDumped += 1; } } } }
public void RenderInstance(RenderManager.CameraInfo cameraInfo, ushort segmentID, uint laneID, NetInfo.Lane laneInfo, NetNode.Flags startFlags, NetNode.Flags endFlags, Color startColor, Color endColor, float startAngle, float endAngle, bool segmentInverted, int layerMask, Vector4 objectIndex1, Vector4 objectIndex2, ref RenderManager.Instance data, ref int propIndex) { NetLaneProps laneProps = laneInfo.m_laneProps; bool backward = (byte)(laneInfo.m_finalDirection & NetInfo.Direction.Both) == 2 || (byte)(laneInfo.m_finalDirection & NetInfo.Direction.AvoidBoth) == 11; bool inverted = backward != segmentInverted; if (backward) { NetNode.Flags flags = startFlags; startFlags = endFlags; endFlags = flags; NetLaneProps.Prop prop = laneProps.m_props[0]; float num4 = prop.m_segmentOffset * 0.5f; num4 = Mathf.Clamp(num4 + prop.m_position.z / this.m_length, -0.5f, 0.5f); if (inverted) { num4 = -num4; } } }
public static int DumpPropsofString(NetInfo loadedPrefab, string findString) { Debug.Log("Standalone Method Fired"); int num = 0; for (int i = 0; i < loadedPrefab.m_lanes.Length; i++) { NetLaneProps LaneJProps = loadedPrefab.m_lanes[i].m_laneProps; for (int j = 0; j < LaneJProps.m_props.Length; j++) { PropInfo a = loadedPrefab.m_lanes[i].m_laneProps.m_props[j].m_prop; if (a.name.Contains(findString)) { DumpUtil.DumpMeshAndTextures(a.name, a.m_mesh, a.m_material); num++; } } } return(num); }
public void DumpProps() { //so far dumps all props in road - problem is that dumping the mesh for most props doesn't work since most are "unreadable" in ModTools //tried investigating getting mesh from the sharedassets11.assets file in /Cities_Data but can't figure out how to load the file directly into the mod //Open to any pointers in how to solve this, If you are reading this and know a way feel free to make a new issue in GitHub Debug.Log(loadedPrefab.m_lanes.Length + " Lanes Exist"); for (int i = 0; i < loadedPrefab.m_lanes.Length; i++) { NetLaneProps LaneJProps = loadedPrefab.m_lanes[i].m_laneProps; Debug.Log("lane" + i + "props len: " + LaneJProps.m_props.Length); for (int j = 0; j < LaneJProps.m_props.Length; j++) { PropInfo a = loadedPrefab.m_lanes[i].m_laneProps.m_props[j].m_prop; Debug.Log(a.name); DumpUtil.DumpMeshAndTextures(a.name, a.m_mesh, a.m_material); } } }
public static void SetupHighwayProps(NetInfo info) { var randomProp = Prefabs.Find <PropInfo>("Random Street Prop", false); var streetLight = Prefabs.Find <PropInfo>("New Street Light", false); var streetLight2 = Prefabs.Find <PropInfo>("New Street Light Small Road", false); var manhole = Prefabs.Find <PropInfo>("Manhole", false); var speed40 = Prefabs.Find <PropInfo>("40 Speed Limit", false); var speed100 = Prefabs.Find <PropInfo>("100 Speed Limit", false); if (randomProp == null) { return; } foreach (var lane in info.m_lanes) { if (lane == null) { continue; } if (lane.m_laneProps == null) { continue; } NetLaneProps sideProps = null; if (lane.m_laneProps.name.ToLower().Contains("left")) { sideProps = ScriptableObject.CreateInstance <NetLaneProps>(); sideProps.name = "Highway1L Left Props"; } if (lane.m_laneProps.name.ToLower().Contains("right")) { sideProps = ScriptableObject.CreateInstance <NetLaneProps>(); sideProps.name = "Highway1L Right Props"; } if (sideProps == null) { continue; } var remainingProps = new List <NetLaneProps.Prop>(); foreach (var prop in lane.m_laneProps.m_props) { if (prop.m_prop == null) { continue; } if (prop.m_prop == randomProp) { continue; } if (prop.m_prop == manhole) { continue; } if (prop.m_prop == streetLight) { continue; } if (prop.m_prop == streetLight2) { continue; } if (prop.m_prop == speed40) { if (speed100 == null) { continue; } else { var speed100Prop = prop.ShallowClone(); speed100Prop.m_prop = speed100; speed100Prop.m_finalProp = null; remainingProps.Add(speed100Prop); continue; } } remainingProps.Add(prop); } sideProps.m_props = remainingProps.ToArray(); lane.m_laneProps = sideProps; } }
public static bool RenderDestroyedInstancePrefix(NetLane __instance, RenderManager.CameraInfo cameraInfo, ushort segmentID, uint laneID, NetInfo netInfo, NetInfo.Lane laneInfo, NetNode.Flags startFlags, NetNode.Flags endFlags, Color startColor, Color endColor, float startAngle, float endAngle, bool invert, int layerMask, Vector4 objectIndex1, Vector4 objectIndex2, ref RenderManager.Instance data, ref int propIndex) { NetLaneProps laneProps = laneInfo.m_laneProps; if (laneProps != null && laneProps.m_props != null) { bool flag = (laneInfo.m_finalDirection & NetInfo.Direction.Both) == NetInfo.Direction.Backward || (laneInfo.m_finalDirection & NetInfo.Direction.AvoidBoth) == NetInfo.Direction.AvoidForward; bool flag2 = flag != invert; if (flag) { NetNode.Flags flags = startFlags; startFlags = endFlags; endFlags = flags; } int num = laneProps.m_props.Length; for (int i = 0; i < num; i++) { NetLaneProps.Prop prop = laneProps.m_props[i]; if (__instance.m_length < prop.m_minLength) { continue; } int num2 = 2; if (prop.m_repeatDistance > 1f) { num2 *= Mathf.Max(1, Mathf.RoundToInt(__instance.m_length / prop.m_repeatDistance)); } int num3 = propIndex; if (propIndex != -1) { propIndex = num3 + (num2 + 1 >> 1); } if (!prop.CheckFlags((NetLane.Flags)__instance.m_flags, startFlags, endFlags)) { continue; } float num4 = prop.m_segmentOffset * 0.5f; if (__instance.m_length != 0f) { num4 = Mathf.Clamp(num4 + prop.m_position.z / __instance.m_length, -0.5f, 0.5f); } if (flag2) { num4 = 0f - num4; } PropInfo finalProp = prop.m_finalProp; if (!(finalProp != null) || (layerMask & (1 << finalProp.m_prefabDataLayer)) == 0) { continue; } Color color = (prop.m_colorMode != NetLaneProps.ColorMode.EndState) ? startColor : endColor; Randomizer r = new Randomizer((int)laneID + i); for (int j = 1; j <= num2; j += 2) { if (r.Int32(100u) >= prop.m_probability) { continue; } float num5 = num4 + (float)j / (float)num2; PropInfo variation = finalProp.GetVariation(ref r); float scale = variation.m_minScale + (float)r.Int32(10000u) * (variation.m_maxScale - variation.m_minScale) * 0.0001f; if (prop.m_colorMode == NetLaneProps.ColorMode.Default) { color = variation.GetColor(ref r); } if (!variation.m_isDecal && !variation.m_surviveCollapse) { continue; } Vector3 vector = __instance.m_bezier.Position(num5); if (propIndex != -1) { vector.y = (float)(int)data.m_extraData.GetUShort(num3++) * 0.015625f; } vector.y += prop.m_position.y; if (!cameraInfo.CheckRenderDistance(vector, variation.m_maxRenderDistance)) { continue; } Vector3 vector2 = __instance.m_bezier.Tangent(num5); if (!(vector2 != Vector3.zero)) { continue; } if (flag2) { vector2 = -vector2; } vector2.y = 0f; if (prop.m_position.x != 0f) { vector2 = Vector3.Normalize(vector2); vector.x += vector2.z * prop.m_position.x; vector.z -= vector2.x * prop.m_position.x; } float num6 = Mathf.Atan2(vector2.x, 0f - vector2.z); if (prop.m_cornerAngle != 0f || prop.m_position.x != 0f) { float num7 = endAngle - startAngle; if (num7 > (float)Math.PI) { num7 -= (float)Math.PI * 2f; } if (num7 < -(float)Math.PI) { num7 += (float)Math.PI * 2f; } float num8 = startAngle + num7 * num5; num7 = num8 - num6; if (num7 > (float)Math.PI) { num7 -= (float)Math.PI * 2f; } if (num7 < -(float)Math.PI) { num7 += (float)Math.PI * 2f; } num6 += num7 * prop.m_cornerAngle; if (num7 != 0f && prop.m_position.x != 0f) { float num9 = Mathf.Tan(num7); vector.x += vector2.x * num9 * prop.m_position.x; vector.z += vector2.z * num9 * prop.m_position.x; } } Vector4 objectIndex3 = (!(num5 > 0.5f)) ? objectIndex1 : objectIndex2; num6 += prop.m_angle * ((float)Math.PI / 180f); InstanceID id = default(InstanceID); id.NetSegment = segmentID; #if UseTask Patcher.Dispatcher.Add(() => PropInstance.RenderInstance(cameraInfo, variation, id, vector, scale, num6, color, objectIndex3, active: true)); #else PropInstance.RenderInstance(cameraInfo, variation, id, vector, scale, num6, color, objectIndex3, active: true); #endif } } } if ((laneInfo.m_laneType & (NetInfo.LaneType.Vehicle | NetInfo.LaneType.Parking | NetInfo.LaneType.CargoVehicle | NetInfo.LaneType.TransportVehicle)) == 0 && ((laneInfo.m_laneType & NetInfo.LaneType.Pedestrian) == 0 || netInfo.m_vehicleTypes != 0)) { return(false); } bool flag3 = (laneInfo.m_vehicleType & ~VehicleInfo.VehicleType.Bicycle) == 0 || laneInfo.m_verticalOffset >= 0.5f; Randomizer r2 = new Randomizer(laneID); int num10 = Mathf.RoundToInt(__instance.m_length * 0.07f); for (int k = 0; k < num10; k++) { PropInfo randomPropInfo = Singleton <PropManager> .instance.GetRandomPropInfo(ref r2, ItemClass.Service.Road); randomPropInfo = randomPropInfo.GetVariation(ref r2); float num11 = randomPropInfo.m_minScale + (float)r2.Int32(10000u) * (randomPropInfo.m_maxScale - randomPropInfo.m_minScale) * 0.0001f; Color color2 = randomPropInfo.GetColor(ref r2); float num12 = (float)r2.Int32(1000u) * 0.001f; float angle = (float)r2.Int32(1000u) * 0.006283186f; if (!randomPropInfo.m_isDecal) { if (flag3) { continue; } if (netInfo.m_netAI.IsOverground()) { float num13 = netInfo.m_halfWidth - Mathf.Abs(laneInfo.m_position); float num14 = Mathf.Max(randomPropInfo.m_generatedInfo.m_size.x, randomPropInfo.m_generatedInfo.m_size.z) * num11 * 0.5f - 0.5f; if (num13 < num14) { continue; } } } Vector3 position = __instance.m_bezier.Position(num12); Vector4 objectIndex4 = (!(num12 > 0.5f)) ? objectIndex1 : objectIndex2; InstanceID id2 = default(InstanceID); id2.NetSegment = segmentID; if (!randomPropInfo.m_requireHeightMap) { #if UseTask Patcher.Dispatcher.Add(() => PropInstance.RenderInstance(cameraInfo, randomPropInfo, id2, position, num11, angle, color2, objectIndex4, active: true)); #else PropInstance.RenderInstance(cameraInfo, randomPropInfo, id2, position, num11, angle, color2, objectIndex4, active: true); #endif } } return(false); }
public static bool RenderInstancePrefix(NetLane __instance, RenderManager.CameraInfo cameraInfo, ushort segmentID, uint laneID, NetInfo.Lane laneInfo, NetNode.Flags startFlags, NetNode.Flags endFlags, Color startColor, Color endColor, float startAngle, float endAngle, bool invert, int layerMask, Vector4 objectIndex1, Vector4 objectIndex2, ref RenderManager.Instance data, ref int propIndex) { NetLaneProps laneProps = laneInfo.m_laneProps; if (!(laneProps != null) || laneProps.m_props == null) { return(false); } bool flag = (laneInfo.m_finalDirection & NetInfo.Direction.Both) == NetInfo.Direction.Backward || (laneInfo.m_finalDirection & NetInfo.Direction.AvoidBoth) == NetInfo.Direction.AvoidForward; bool flag2 = flag != invert; if (flag) { NetNode.Flags flags = startFlags; startFlags = endFlags; endFlags = flags; } Texture _HeightMap = null; Vector4 _HeightMapping = Vector4.zero; Vector4 _SurfaceMapping = Vector4.zero; Texture _HeightMap2 = null; Vector4 _HeightMapping2 = Vector4.zero; Vector4 _SurfaceMapping2 = Vector4.zero; int num = laneProps.m_props.Length; for (int i = 0; i < num; i++) { NetLaneProps.Prop prop = laneProps.m_props[i]; if (__instance.m_length < prop.m_minLength) { continue; } int num2 = 2; if (prop.m_repeatDistance > 1f) { num2 *= Mathf.Max(1, Mathf.RoundToInt(__instance.m_length / prop.m_repeatDistance)); } int num3 = propIndex; if (propIndex != -1) { propIndex = num3 + (num2 + 1 >> 1); } if (!prop.CheckFlags((NetLane.Flags)__instance.m_flags, startFlags, endFlags)) { continue; } float num4 = prop.m_segmentOffset * 0.5f; if (__instance.m_length != 0f) { num4 = Mathf.Clamp(num4 + prop.m_position.z / __instance.m_length, -0.5f, 0.5f); } if (flag2) { num4 = 0f - num4; } PropInfo finalProp = prop.m_finalProp; if (finalProp != null && (layerMask & (1 << finalProp.m_prefabDataLayer)) != 0) { Color color = (prop.m_colorMode != NetLaneProps.ColorMode.EndState) ? startColor : endColor; Randomizer r = new Randomizer((int)laneID + i); for (int j = 1; j <= num2; j += 2) { if (r.Int32(100u) >= prop.m_probability) { continue; } float num5 = num4 + (float)j / (float)num2; PropInfo variation = finalProp.GetVariation(ref r); float scale = variation.m_minScale + (float)r.Int32(10000u) * (variation.m_maxScale - variation.m_minScale) * 0.0001f; if (prop.m_colorMode == NetLaneProps.ColorMode.Default) { color = variation.GetColor(ref r); } Vector3 vector = __instance.m_bezier.Position(num5); if (propIndex != -1) { vector.y = (float)(int)data.m_extraData.GetUShort(num3++) * 0.015625f; } vector.y += prop.m_position.y; if (!cameraInfo.CheckRenderDistance(vector, variation.m_maxRenderDistance)) { continue; } Vector3 vector2 = __instance.m_bezier.Tangent(num5); if (!(vector2 != Vector3.zero)) { continue; } if (flag2) { vector2 = -vector2; } vector2.y = 0f; if (prop.m_position.x != 0f) { vector2 = Vector3.Normalize(vector2); vector.x += vector2.z * prop.m_position.x; vector.z -= vector2.x * prop.m_position.x; } float num6 = Mathf.Atan2(vector2.x, 0f - vector2.z); if (prop.m_cornerAngle != 0f || prop.m_position.x != 0f) { float num7 = endAngle - startAngle; if (num7 > (float)Math.PI) { num7 -= (float)Math.PI * 2f; } if (num7 < -(float)Math.PI) { num7 += (float)Math.PI * 2f; } float num8 = startAngle + num7 * num5; num7 = num8 - num6; if (num7 > (float)Math.PI) { num7 -= (float)Math.PI * 2f; } if (num7 < -(float)Math.PI) { num7 += (float)Math.PI * 2f; } num6 += num7 * prop.m_cornerAngle; if (num7 != 0f && prop.m_position.x != 0f) { float num9 = Mathf.Tan(num7); vector.x += vector2.x * num9 * prop.m_position.x; vector.z += vector2.z * num9 * prop.m_position.x; } } Vector4 objectIndex3 = (!(num5 > 0.5f)) ? objectIndex1 : objectIndex2; num6 += prop.m_angle * ((float)Math.PI / 180f); InstanceID id = default(InstanceID); id.NetSegment = segmentID; if (variation.m_requireWaterMap) { if (_HeightMap == null) { Singleton <TerrainManager> .instance.GetHeightMapping(Singleton <NetManager> .instance.m_segments.m_buffer[segmentID].m_middlePosition, out _HeightMap, out _HeightMapping, out _SurfaceMapping); } if (_HeightMap2 == null) { Singleton <TerrainManager> .instance.GetWaterMapping(Singleton <NetManager> .instance.m_segments.m_buffer[segmentID].m_middlePosition, out _HeightMap2, out _HeightMapping2, out _SurfaceMapping2); } #if UseTask Patcher.Dispatcher.Add(() => PropInstance.RenderInstance(cameraInfo, variation, id, vector, scale, num6, color, objectIndex3, active: true, _HeightMap, _HeightMapping, _SurfaceMapping, _HeightMap2, _HeightMapping2, _SurfaceMapping2)); #else PropInstance.RenderInstance(cameraInfo, variation, id, vector, scale, num6, color, objectIndex3, active: true, _HeightMap, _HeightMapping, _SurfaceMapping, _HeightMap2, _HeightMapping2, _SurfaceMapping2); #endif } else if (!variation.m_requireHeightMap) { #if UseTask Patcher.Dispatcher.Add(() => PropInstance.RenderInstance(cameraInfo, variation, id, vector, scale, num6, color, objectIndex3, active: true)); #else PropInstance.RenderInstance(cameraInfo, variation, id, vector, scale, num6, color, objectIndex3, active: true); #endif } } } TreeInfo finalTree = prop.m_finalTree; if (!(finalTree != null) || (layerMask & (1 << finalTree.m_prefabDataLayer)) == 0) { continue; } Randomizer r2 = new Randomizer((int)laneID + i); for (int k = 1; k <= num2; k += 2) { if (r2.Int32(100u) >= prop.m_probability) { continue; } float t = num4 + (float)k / (float)num2; TreeInfo variation2 = finalTree.GetVariation(ref r2); float scale2 = variation2.m_minScale + (float)r2.Int32(10000u) * (variation2.m_maxScale - variation2.m_minScale) * 0.0001f; float brightness = variation2.m_minBrightness + (float)r2.Int32(10000u) * (variation2.m_maxBrightness - variation2.m_minBrightness) * 0.0001f; Vector3 position = __instance.m_bezier.Position(t); if (propIndex != -1) { position.y = (float)(int)data.m_extraData.GetUShort(num3++) * 0.015625f; } position.y += prop.m_position.y; if (prop.m_position.x != 0f) { Vector3 vector3 = __instance.m_bezier.Tangent(t); if (flag2) { vector3 = -vector3; } vector3.y = 0f; vector3 = Vector3.Normalize(vector3); position.x += vector3.z * prop.m_position.x; position.z -= vector3.x * prop.m_position.x; } #if UseTask Patcher.Dispatcher.Add(() => TreeInstance.RenderInstance(cameraInfo, variation2, position, scale2, brightness, RenderManager.DefaultColorLocation)); #else TreeInstance.RenderInstance(cameraInfo, variation2, position, scale2, brightness, RenderManager.DefaultColorLocation); #endif } } return(false); }
public static void CopyToGame(object source, object target) { Debug.Log("Invoke copytogame"); Debug.Log($"source:{source}, target:{target}"); if (source == null || target == null) { return; } FieldInfo[] fields = source.GetType().GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); foreach (FieldInfo fieldInfo in fields) { if (fieldInfo.GetValue(source) == null) { Debug.Log($"Field {fieldInfo.Name} is null, skipping import"); continue; } FieldInfo gameFieldInfo = target.GetType().GetField(fieldInfo.Name, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); Debug.Log(gameFieldInfo); Debug.Log(fieldInfo); if (gameFieldInfo.FieldType.IsArray) { Array savedObjects = (Array)fieldInfo.GetValue(source); int len = savedObjects.Length; Type elementType = gameFieldInfo.FieldType.GetElementType(); gameFieldInfo.SetValue(target, Array.CreateInstance(elementType, 0)); for (int i = 0; i < len; i++) { AssetEditorRoadUtils.AddArrayElement(target, gameFieldInfo); Array gameObjects = (Array)gameFieldInfo.GetValue(target); CopyToGame(savedObjects.GetValue(i), gameObjects.GetValue(i)); } } else if (gameFieldInfo.FieldType == typeof(NetLaneProps)) { CSNetInfo.Prop[] savedObjects = (CSNetInfo.Prop[])fieldInfo.GetValue(source); int len = savedObjects.Length; NetLaneProps gameObjects = new NetLaneProps { m_props = new NetLaneProps.Prop[len] }; for (int i = 0; i < len; i++) { gameObjects.m_props[i] = new NetLaneProps.Prop(); CopyToGame(savedObjects[i], gameObjects.m_props[i]); } gameFieldInfo.SetValue(target, gameObjects); } else if (gameFieldInfo.FieldType == typeof(Vector3)) { float[] vals = (float[])fieldInfo.GetValue(source); Vector3 vec = new Vector3(vals[0], vals[1], vals[2]); gameFieldInfo.SetValue(target, vec); } else if (gameFieldInfo.FieldType.IsEnum) { object val = Enum.ToObject(gameFieldInfo.FieldType, fieldInfo.GetValue(source)); gameFieldInfo.SetValue(target, val); } else if (gameFieldInfo.FieldType.IsSubclassOf(typeof(PrefabInfo))) { string prefabName = (string)fieldInfo.GetValue(source); if (prefabName.Equals("")) { gameFieldInfo.SetValue(target, null); } else { if (gameFieldInfo.FieldType == typeof(PropInfo)) { PropInfo prefab = PrefabCollection <PropInfo> .FindLoaded(prefabName); gameFieldInfo.SetValue(target, prefab); } else if (gameFieldInfo.FieldType == typeof(BuildingInfo)) { BuildingInfo prefab = PrefabCollection <BuildingInfo> .FindLoaded(prefabName); gameFieldInfo.SetValue(target, prefab); } else if (gameFieldInfo.FieldType == typeof(TreeInfo)) { TreeInfo prefab = PrefabCollection <TreeInfo> .FindLoaded(prefabName); gameFieldInfo.SetValue(target, prefab); } } } else { gameFieldInfo.SetValue(target, fieldInfo.GetValue(source)); } } }
public void PopulateGroupData( ushort segmentID, uint laneID, NetInfo.Lane laneInfo, bool destroyed, NetNode.Flags startFlags, NetNode.Flags endFlags, float startAngle, float endAngle, bool invert, bool terrainHeight, int layer, ref int vertexIndex, ref int triangleIndex, Vector3 groupPosition, RenderGroup.MeshData data, ref Vector3 min, ref Vector3 max, ref float maxRenderDistance, ref float maxInstanceDistance, ref bool hasProps) { NetLaneProps laneProps = laneInfo.m_laneProps; if (laneProps?.m_props == null) { return; } bool backward = (laneInfo.m_finalDirection & NetInfo.Direction.Both) == NetInfo.Direction.Backward || (laneInfo.m_finalDirection & NetInfo.Direction.AvoidBoth) == NetInfo.Direction.AvoidForward; bool reverse = backward != invert; if (backward) //swap { NetNode.Flags flags = startFlags; startFlags = endFlags; endFlags = flags; } int nProps = laneProps.m_props.Length; for (int i = 0; i < nProps; i++) { NetLaneProps.Prop prop = laneProps.m_props[i]; if (!prop.CheckFlags(m_flags, startFlags, endFlags) || m_length < prop.m_minLength) { continue; } int repeatCountTimes2 = 2; if (prop.m_repeatDistance > 1f) { repeatCountTimes2 *= Mathf.Max(1, Mathf.RoundToInt(m_length / prop.m_repeatDistance)); } float halfSegmentOffset = prop.m_segmentOffset * 0.5f; if (m_length != 0f) { halfSegmentOffset = Mathf.Clamp(halfSegmentOffset + prop.m_position.z / m_length, -0.5f, 0.5f); } if (reverse) { halfSegmentOffset = 0f - halfSegmentOffset; } PropInfo finalProp = prop.m_finalProp; if ((object)finalProp != null) { hasProps = true; if (finalProp.m_prefabDataLayer == layer || finalProp.m_effectLayer == layer) { Color color = Color.white; Randomizer r = new Randomizer((int)laneID + i); for (int j = 1; j <= repeatCountTimes2; j += 2) { if (r.Int32(100u) >= prop.m_probability) { continue; } float t = halfSegmentOffset + (float)j / (float)repeatCountTimes2; PropInfo variation = finalProp.GetVariation(ref r); float scale = variation.m_minScale + (float)r.Int32(10000u) * (variation.m_maxScale - variation.m_minScale) * 0.0001f; if (prop.m_colorMode == NetLaneProps.ColorMode.Default) { color = variation.GetColor(ref r); } if (!variation.m_isDecal && destroyed) { continue; } Vector3 pos = m_bezier.Position(t); Vector3 tan = m_bezier.Tangent(t); if (!(tan != Vector3.zero)) { continue; } if (reverse) { tan = -tan; } tan.y = 0f; if (prop.m_position.x != 0f) { tan = Vector3.Normalize(tan); pos.x += tan.z * prop.m_position.x; pos.z -= tan.x * prop.m_position.x; } float normalAngle = Mathf.Atan2(tan.x, 0f - tan.z); if (prop.m_cornerAngle != 0f || prop.m_position.x != 0f) { float angleDiff = endAngle - startAngle; if (angleDiff > Mathf.PI) { angleDiff -= Mathf.PI * 2f; } if (angleDiff < -Mathf.PI) { angleDiff += Mathf.PI * 2f; } var angle2 = startAngle + angleDiff * t - normalAngle; if (angle2 > Mathf.PI) { angle2 -= Mathf.PI * 2f; } if (angle2 < -Mathf.PI) { angle2 += Mathf.PI * 2f; } normalAngle += angle2 * prop.m_cornerAngle; if (angle2 != 0f && prop.m_position.x != 0f) { float d = Mathf.Tan(angle2); pos.x += tan.x * d * prop.m_position.x; pos.z += tan.z * d * prop.m_position.x; } } if (terrainHeight) { if (variation.m_requireWaterMap) { pos.y = Singleton <TerrainManager> .instance.SampleRawHeightSmoothWithWater(pos, timeLerp : false, 0f); } else { pos.y = Singleton <TerrainManager> .instance.SampleDetailHeight(pos); } } pos.y += prop.m_position.y; InstanceID id = default(InstanceID); id.NetSegment = segmentID; PropInstance.PopulateGroupData(angle: normalAngle + prop.m_angle * (Mathf.PI / 180f), info: variation, layer: layer, id: id, position: pos, scale: scale, color: color, vertexIndex: ref vertexIndex, triangleIndex: ref triangleIndex, groupPosition: groupPosition, data: data, min: ref min, max: ref max, maxRenderDistance: ref maxRenderDistance, maxInstanceDistance: ref maxInstanceDistance); } } } if (destroyed) { continue; } TreeInfo finalTree = prop.m_finalTree; if ((object)finalTree == null) { continue; } hasProps = true; if (finalTree.m_prefabDataLayer != layer) { continue; } Randomizer r2 = new Randomizer((int)laneID + i); for (int k = 1; k <= repeatCountTimes2; k += 2) { if (r2.Int32(100u) >= prop.m_probability) { continue; } float t = halfSegmentOffset + (float)k / (float)repeatCountTimes2; TreeInfo variation2 = finalTree.GetVariation(ref r2); float scale2 = variation2.m_minScale + (float)r2.Int32(10000u) * (variation2.m_maxScale - variation2.m_minScale) * 0.0001f; float brightness = variation2.m_minBrightness + (float)r2.Int32(10000u) * (variation2.m_maxBrightness - variation2.m_minBrightness) * 0.0001f; Vector3 vector3 = m_bezier.Position(t); if (prop.m_position.x != 0f) { Vector3 vector4 = m_bezier.Tangent(t); if (reverse) { vector4 = -vector4; } vector4.y = 0f; vector4 = Vector3.Normalize(vector4); vector3.x += vector4.z * prop.m_position.x; vector3.z -= vector4.x * prop.m_position.x; } if (terrainHeight) { vector3.y = Singleton <TerrainManager> .instance.SampleDetailHeight(vector3); } vector3.y += prop.m_position.y; TreeInstance.PopulateGroupData(variation2, vector3, scale2, brightness, RenderManager.DefaultColorLocation, ref vertexIndex, ref triangleIndex, groupPosition, data, ref min, ref max, ref maxRenderDistance, ref maxInstanceDistance); } } }
public void RenderInstance( RenderManager.CameraInfo cameraInfo, ushort segmentID, uint laneID, NetInfo.Lane laneInfo, NetNode.Flags startFlags, NetNode.Flags endFlags, Color startColor, Color endColor, float startAngle, float endAngle, bool invert, int layerMask, Vector4 objectIndex1, Vector4 objectIndex2, ref RenderManager.Instance data, ref int propIndex) { NetLaneProps laneProps = laneInfo.m_laneProps; if (laneProps != null && laneProps.m_props != null) { bool backward = (byte)(laneInfo.m_finalDirection & NetInfo.Direction.Both) == 2 || (byte)(laneInfo.m_finalDirection & NetInfo.Direction.AvoidBoth) == 11; bool reverse = backward != invert; if (backward) //swap { NetNode.Flags flags = startFlags; startFlags = endFlags; endFlags = flags; } Texture texture = null; Vector4 zero = Vector4.zero; Vector4 zero2 = Vector4.zero; Texture texture2 = null; Vector4 zero3 = Vector4.zero; Vector4 zero4 = Vector4.zero; int nProps = laneProps.m_props.Length; for (int i = 0; i < nProps; i++) { NetLaneProps.Prop prop = laneProps.m_props[i]; if (this.m_length >= prop.m_minLength) { int repeatCountTimes2 = 2; if (prop.m_repeatDistance > 1f) { repeatCountTimes2 *= Mathf.Max(1, Mathf.RoundToInt(this.m_length / prop.m_repeatDistance)); } int currentPropIndex = propIndex; if (propIndex != -1) { propIndex = currentPropIndex + (repeatCountTimes2 + 1) >> 1; // div 2 } if (prop.CheckFlags(this.m_flags, startFlags, endFlags)) { float halfSegmentOffset = prop.m_segmentOffset * 0.5f; if (this.m_length != 0f) { halfSegmentOffset = Mathf.Clamp(halfSegmentOffset + prop.m_position.z / this.m_length, -0.5f, 0.5f); } if (reverse) { halfSegmentOffset = -halfSegmentOffset; } PropInfo finalProp = prop.m_finalProp; if (finalProp != null && (layerMask & 1 << finalProp.m_prefabDataLayer) != 0) { Color color = (prop.m_colorMode != NetLaneProps.ColorMode.EndState) ? startColor : endColor; Randomizer randomizer = new Randomizer((int)(laneID + (uint)i)); for (int j = 1; j <= repeatCountTimes2; j += 2) { if (randomizer.Int32(100u) < prop.m_probability) { float t = halfSegmentOffset + (float)j / (float)repeatCountTimes2; PropInfo variation = finalProp.GetVariation(ref randomizer); float scale = variation.m_minScale + (float)randomizer.Int32(10000u) * (variation.m_maxScale - variation.m_minScale) * 0.0001f; if (prop.m_colorMode == NetLaneProps.ColorMode.Default) { color = variation.GetColor(ref randomizer); } Vector3 pos = this.m_bezier.Position(t); if (propIndex != -1) { pos.y = (float)data.m_extraData.GetUShort(currentPropIndex++) * 0.015625f; } pos.y += prop.m_position.y; if (cameraInfo.CheckRenderDistance(pos, variation.m_maxRenderDistance)) { Vector3 tan = this.m_bezier.Tangent(t); if (tan != Vector3.zero) { if (reverse) { tan = -tan; } Vector3 normalXZ = new Vector3 { x = tan.z, z = -tan.x }; if (prop.m_position.x != 0f) { tan.Normalize(); normalXZ.Normalize(); pos += normalXZ * prop.m_position.x; } float normalAngle = Mathf.Atan2(normalXZ.z, normalXZ.x); if (prop.m_cornerAngle != 0f || prop.m_position.x != 0f) { float angleDiff = endAngle - startAngle; if (angleDiff > Mathf.PI) { angleDiff -= 2 * Mathf.PI; } if (angleDiff < -Mathf.PI) { angleDiff += 2 * Mathf.PI; } float currentAngle = startAngle + angleDiff * t; float angle2 = currentAngle - normalAngle; if (angle2 > Mathf.PI) { angle2 -= 2 * Mathf.PI; } if (angle2 < -Mathf.PI) { angle2 += 2 * Mathf.PI; } normalAngle += angle2 * prop.m_cornerAngle; if (angle2 != 0f && prop.m_position.x != 0f) { float d = Mathf.Tan(angle2); pos.x += tan.x * d * prop.m_position.x; pos.z += tan.z * d * prop.m_position.x; } } Vector4 objectIndex3 = (t <= 0.5f) ? objectIndex1 : objectIndex2; normalAngle += prop.m_angle * 0.0174532924f; InstanceID id = default(InstanceID); id.NetSegment = segmentID; if (variation.m_requireWaterMap) { if (texture == null) { Singleton <TerrainManager> .instance.GetHeightMapping(Singleton <NetManager> .instance.m_segments.m_buffer[(int)segmentID].m_middlePosition, out texture, out zero, out zero2); } if (texture2 == null) { Singleton <TerrainManager> .instance.GetWaterMapping(Singleton <NetManager> .instance.m_segments.m_buffer[(int)segmentID].m_middlePosition, out texture2, out zero3, out zero4); } PropInstance.RenderInstance(cameraInfo, variation, id, pos, scale, normalAngle, color, objectIndex3, true, texture, zero, zero2, texture2, zero3, zero4); } else if (!variation.m_requireHeightMap) { PropInstance.RenderInstance(cameraInfo, variation, id, pos, scale, normalAngle, color, objectIndex3, true); } } } } } } TreeInfo finalTree = prop.m_finalTree; if (finalTree != null && (layerMask & 1 << finalTree.m_prefabDataLayer) != 0) { Randomizer randomizer2 = new Randomizer((int)(laneID + (uint)i)); for (int k = 1; k <= repeatCountTimes2; k += 2) { if (randomizer2.Int32(100u) < prop.m_probability) { float t = halfSegmentOffset + (float)k / (float)repeatCountTimes2; TreeInfo variation2 = finalTree.GetVariation(ref randomizer2); float scale2 = variation2.m_minScale + (float)randomizer2.Int32(10000u) * (variation2.m_maxScale - variation2.m_minScale) * 0.0001f; float brightness = variation2.m_minBrightness + (float)randomizer2.Int32(10000u) * (variation2.m_maxBrightness - variation2.m_minBrightness) * 0.0001f; Vector3 position = this.m_bezier.Position(t); if (propIndex != -1) { position.y = (float)data.m_extraData.GetUShort(currentPropIndex++) * 0.015625f; } position.y += prop.m_position.y; if (prop.m_position.x != 0f) { Vector3 vector3 = this.m_bezier.Tangent(t); if (reverse) { vector3 = -vector3; } vector3.y = 0f; vector3 = Vector3.Normalize(vector3); position.x += vector3.z * prop.m_position.x; position.z -= vector3.x * prop.m_position.x; } global::TreeInstance.RenderInstance(cameraInfo, variation2, position, scale2, brightness, RenderManager.DefaultColorLocation); } } } } } } } }
public static void CopyFromGame(object source, object target) { Debug.Log("Invoke copyfromgame"); Debug.Log($"source:{source}, target:{target}"); if (source == null || target == null) { return; } FieldInfo[] fields = target.GetType().GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); foreach (FieldInfo fieldInfo in fields) { FieldInfo gameFieldInfo = source.GetType().GetField(fieldInfo.Name, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); Debug.Log(gameFieldInfo); Debug.Log(fieldInfo); if (gameFieldInfo.FieldType == typeof(NetInfo.Lane[])) { NetInfo.Lane[] gameObjects = (NetInfo.Lane[])gameFieldInfo.GetValue(source); int len = gameObjects.Length; CSNetInfo.Lane[] savedObjects = new CSNetInfo.Lane[len]; for (int i = 0; i < len; i++) { savedObjects[i] = new CSNetInfo.Lane(); CopyFromGame(gameObjects[i], savedObjects[i]); } fieldInfo.SetValue(target, savedObjects); } else if (gameFieldInfo.FieldType == typeof(NetInfo.Segment[])) { NetInfo.Segment[] gameObjects = (NetInfo.Segment[])gameFieldInfo.GetValue(source); int len = gameObjects.Length; CSNetInfo.Segment[] savedObjects = new CSNetInfo.Segment[len]; for (int i = 0; i < len; i++) { savedObjects[i] = new CSNetInfo.Segment(); CopyFromGame(gameObjects[i], savedObjects[i]); } fieldInfo.SetValue(target, savedObjects); } else if (gameFieldInfo.FieldType == typeof(NetInfo.Node[])) { NetInfo.Node[] gameObjects = (NetInfo.Node[])gameFieldInfo.GetValue(source); int len = gameObjects.Length; CSNetInfo.Node[] savedObjects = new CSNetInfo.Node[len]; for (int i = 0; i < len; i++) { savedObjects[i] = new CSNetInfo.Node(); CopyFromGame(gameObjects[i], savedObjects[i]); } fieldInfo.SetValue(target, savedObjects); } else if (gameFieldInfo.FieldType == typeof(NetLaneProps)) { NetLaneProps gameObjects = (NetLaneProps)gameFieldInfo.GetValue(source); int len = gameObjects.m_props.Length; CSNetInfo.Prop[] savedObjects = new CSNetInfo.Prop[len]; for (int i = 0; i < len; i++) { savedObjects[i] = new CSNetInfo.Prop(); CopyFromGame(gameObjects.m_props[i], savedObjects[i]); } fieldInfo.SetValue(target, savedObjects); } else if (gameFieldInfo.FieldType == typeof(Vector3)) { Vector3 vec = (Vector3)gameFieldInfo.GetValue(source); float[] vals = { vec[0], vec[1], vec[2] }; fieldInfo.SetValue(target, vals); } else if (gameFieldInfo.FieldType.IsEnum) { object val = Enum.ToObject(fieldInfo.FieldType, gameFieldInfo.GetValue(source)); fieldInfo.SetValue(target, val); } else if (gameFieldInfo.FieldType.IsSubclassOf(typeof(PrefabInfo))) { PrefabInfo prefab = (PrefabInfo)gameFieldInfo.GetValue(source); if (prefab == null) { fieldInfo.SetValue(target, ""); } else { fieldInfo.SetValue(target, prefab.name); } } else { fieldInfo.SetValue(target, gameFieldInfo.GetValue(source)); } } }
void RemoveSkippedFromNets(IEnumerator action) { try { NetInfo[] prefabs = netPrefabsField.GetValue(action) as NetInfo[]; if (prefabs == null) { netPrefabsField.SetValue(action, new NetInfo[0]); return; } List <NetLaneProps.Prop> keepThese = new List <NetLaneProps.Prop>(16); //StreamWriter wp = new StreamWriter(Path.Combine(Util.GetSavePath(), "Net-props.txt"), true); foreach (NetInfo info in prefabs) { //wp.WriteLine(info.name); if (info.m_lanes == null) { continue; } for (int i = 0; i < info.m_lanes.Length; i++) { NetLaneProps laneProps = info.m_lanes[i].m_laneProps; if (laneProps == null || laneProps.m_props == null) { continue; } //wp.WriteLine(" --"); bool skippedSome = false; for (int j = 0; j < laneProps.m_props.Length; j++) { NetLaneProps.Prop prop = laneProps.m_props[j]; if (prop == null) { continue; } //if (prop.m_prop != null) // wp.WriteLine(" " + prop.m_prop.name); if (prop.m_prop == null) { keepThese.Add(prop); } else if (Skip(prop.m_prop)) { //Util.DebugPrint(prop.m_prop.name, "-> RemoveSkippedFromNets at", Profiling.Millis, "/", info.name); prop.m_prop = prop.m_finalProp = null; skippedSome = true; } else { keepThese.Add(prop); } } if (skippedSome) { laneProps.m_props = keepThese.ToArray(); } keepThese.Clear(); } } //wp.Close(); } catch (Exception e) { UnityEngine.Debug.LogException(e); } }