static object PerformMemberwiseClone(ref object o) { var ins = new UnityEngine.AI.NavMeshBuildSource(); ins = (UnityEngine.AI.NavMeshBuildSource)o; return(ins); }
static void WriteBackInstance(CSHotFix.Runtime.Enviorment.AppDomain __domain, StackObject *ptr_of_this_method, IList <object> __mStack, ref UnityEngine.AI.NavMeshBuildSource instance_of_this_method) { ptr_of_this_method = ILIntepreter.GetObjectAndResolveReference(ptr_of_this_method); switch (ptr_of_this_method->ObjectType) { case ObjectTypes.Object: { __mStack[ptr_of_this_method->Value] = instance_of_this_method; } break; case ObjectTypes.FieldReference: { var ___obj = __mStack[ptr_of_this_method->Value]; if (___obj is ILTypeInstance) { ((ILTypeInstance)___obj)[ptr_of_this_method->ValueLow] = instance_of_this_method; } else { var t = __domain.GetType(___obj.GetType()) as CLRType; t.SetFieldValue(ptr_of_this_method->ValueLow, ref ___obj, instance_of_this_method); } } break; case ObjectTypes.StaticFieldReference: { var t = __domain.GetType(ptr_of_this_method->Value); if (t is ILType) { ((ILType)t).StaticInstance[ptr_of_this_method->ValueLow] = instance_of_this_method; } else { ((CLRType)t).SetStaticFieldValue(ptr_of_this_method->ValueLow, instance_of_this_method); } } break; case ObjectTypes.ArrayReference: { var instance_of_arrayReference = __mStack[ptr_of_this_method->Value] as UnityEngine.AI.NavMeshBuildSource[]; instance_of_arrayReference[ptr_of_this_method->ValueLow] = instance_of_this_method; } break; } }
public override void ApplyBeforeConnections(Graph graph) { var navMeshGraph = graph as NavMeshGraph; var graphBounds = new Bounds(navMeshGraph.graphCenter, navMeshGraph.size); var graphHeightMin = navMeshGraph.minHeight; var graphHeightMax = navMeshGraph.maxHeight; var cache = PoolDictionary <int, Item> .Spawn(100); var obstacles = PoolDictionary <int, System.Collections.Generic.List <Bounds> > .Spawn(3); foreach (var item in this.items) { cache.Add(item.requiredTile == null ? 0 : item.requiredTile.GetInstanceID(), item); } foreach (var pos in this.bounds.allPositionsWithin) { var worldPosition = this.tilemap.GetCellCenterWorld(pos) - this.tilemap.layoutGrid.cellGap; if (graphBounds.Contains(worldPosition) == false) { continue; } var tile = this.tilemap.GetTile(pos); var id = tile == null ? 0 : tile.GetInstanceID(); if (cache.TryGetValue(id, out var item) == true) { if (obstacles.TryGetValue(item.tag, out var list) == false) { list = new System.Collections.Generic.List <Bounds>(); obstacles[item.tag] = PoolList <Bounds> .Spawn(100); } list.Add(new Bounds(worldPosition, new Vector3(item.customSize == true ? item.size.x : this.tilemap.layoutGrid.cellSize.x, item.customSize == true ? item.size.y : this.tilemap.layoutGrid.cellSize.y, item.height))); if (item.height < graphHeightMin) { graphHeightMin = item.height; } if (item.height > graphHeightMax) { graphHeightMax = item.height; } } } foreach (var kv in obstacles) { var count = kv.Value.Count; BoundsCompressor.CompressBounds(kv.Value, 0.05f); UnityEngine.Debug.Log($"Obstacles bounds compress from {count} to {kv.Value.Count}"); foreach (var obstacle in kv.Value) { var source = new UnityEngine.AI.NavMeshBuildSource { area = kv.Key, shape = UnityEngine.AI.NavMeshBuildSourceShape.Box, transform = Matrix4x4.TRS(obstacle.center, this.tilemap.transform.rotation, this.tilemap.transform.lossyScale) * this.tilemap.orientationMatrix * this.tilemap.GetTransformMatrix(this.tilemap.WorldToCell(obstacle.center)), size = obstacle.size, }; navMeshGraph.AddBuildSource(source); } PoolList <Bounds> .Recycle(kv.Value); } navMeshGraph.SetMinMaxHeight(graphHeightMin, graphHeightMax); PoolDictionary <int, Item> .Recycle(ref cache); PoolDictionary <int, System.Collections.Generic.List <Bounds> > .Recycle(ref obstacles); }