当前位置: 首页>>代码示例>>C#>>正文


C# Vehicle.SetTargetPos方法代码示例

本文整理汇总了C#中Vehicle.SetTargetPos方法的典型用法代码示例。如果您正苦于以下问题:C# Vehicle.SetTargetPos方法的具体用法?C# Vehicle.SetTargetPos怎么用?C# Vehicle.SetTargetPos使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Vehicle的用法示例。


在下文中一共展示了Vehicle.SetTargetPos方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: UpdatePathTargetPositions

 public static void UpdatePathTargetPositions(VehicleAI vehicleAI, ushort vehicleID, ref Vehicle vehicleData, Vector3 refPos, ref int index, int max, float minSqrDistanceA, float minSqrDistanceB)
 {
     PathManager instance = Singleton<PathManager>.instance;
     NetManager instance2 = Singleton<NetManager>.instance;
     Vector4 vector = vehicleData.m_targetPos0;
     vector.w = 1000f;
     float num = minSqrDistanceA;
     uint num2 = vehicleData.m_path;
     byte b = vehicleData.m_pathPositionIndex;
     byte b2 = vehicleData.m_lastPathOffset;
     if (b == 255)
     {
         b = 0;
         if (index <= 0)
         {
             vehicleData.m_pathPositionIndex = 0;
         }
         if (!Singleton<PathManager>.instance.m_pathUnits.m_buffer[(int)((UIntPtr)num2)].CalculatePathPositionOffset(b >> 1, vector, out b2))
         {
             (vehicleAI as IVehicle).InvalidPath(vehicleID, ref vehicleData, vehicleID, ref vehicleData);
             return;
         }
     }
     PathUnit.Position position;
     if (!instance.m_pathUnits.m_buffer[(int)((UIntPtr)num2)].GetPosition(b >> 1, out position))
     {
         (vehicleAI as IVehicle).InvalidPath(vehicleID, ref vehicleData, vehicleID, ref vehicleData);
         return;
     }
     NetInfo info = instance2.m_segments.m_buffer[(int)position.m_segment].Info;
     if (info.m_lanes.Length <= (int)position.m_lane)
     {
         (vehicleAI as IVehicle).InvalidPath(vehicleID, ref vehicleData, vehicleID, ref vehicleData);
         return;
     }
     uint num3 = PathManager.GetLaneID(position);
     NetInfo.Lane lane = info.m_lanes[(int)position.m_lane];
     Bezier3 bezier;
     while (true)
     {
         if ((b & 1) == 0)
         {
             if (lane.m_laneType != NetInfo.LaneType.CargoVehicle)
             {
                 bool flag = true;
                 while (b2 != position.m_offset)
                 {
                     if (flag)
                     {
                         flag = false;
                     }
                     else
                     {
                         float num4 = Mathf.Sqrt(num) - Vector3.Distance(vector, refPos);
                         int num5;
                         if (num4 < 0f)
                         {
                             num5 = 4;
                         }
                         else
                         {
                             num5 = 4 + Mathf.Max(0, Mathf.CeilToInt(num4 * 256f / (instance2.m_lanes.m_buffer[(int)((UIntPtr)num3)].m_length + 1f)));
                         }
                         if (b2 > position.m_offset)
                         {
                             b2 = (byte)Mathf.Max((int)b2 - num5, (int)position.m_offset);
                         }
                         else
                         {
                             if (b2 < position.m_offset)
                             {
                                 b2 = (byte)Mathf.Min((int)b2 + num5, (int)position.m_offset);
                             }
                         }
                     }
                     Vector3 a;
                     Vector3 vector2;
                     float b3;
                     (vehicleAI as IVehicle).CalculateSegmentPosition(vehicleID, ref vehicleData, position, num3, b2, out a, out vector2, out b3);
                     b3 = RestrictSpeed(b3, num3, vehicleData.Info);
                     vector.Set(a.x, a.y, a.z, Mathf.Min(vector.w, b3));
                     float sqrMagnitude = (a - refPos).sqrMagnitude;
                     if (sqrMagnitude >= num)
                     {
                         if (index <= 0)
                         {
                             vehicleData.m_lastPathOffset = b2;
                         }
                         vehicleData.SetTargetPos(index++, vector);
                         num = minSqrDistanceB;
                         refPos = vector;
                         vector.w = 1000f;
                         if (index == max)
                         {
                             return;
                         }
                     }
                 }
             }
             b += 1;
//.........这里部分代码省略.........
开发者ID:bagukiri,项目名称:csl-traffic,代码行数:101,代码来源:CustomVehicleAI.cs

示例2: SimulationStep

 public static void SimulationStep(CarAI carAI, ushort vehicleID, ref Vehicle vehicleData, ref Vehicle.Frame frameData, ushort leaderID, ref Vehicle leaderData, int lodPhysics)
 {
     uint currentFrameIndex = Singleton<SimulationManager>.instance.m_currentFrameIndex;
     frameData.m_position += frameData.m_velocity * 0.5f;
     frameData.m_swayPosition += frameData.m_swayVelocity * 0.5f;
     float acceleration = carAI.m_info.m_acceleration;
     float braking = carAI.m_info.m_braking;
     float magnitude = frameData.m_velocity.magnitude;
     Vector3 vector = vehicleData.m_targetPos0 - (Vector4)frameData.m_position;
     float sqrMagnitude = vector.sqrMagnitude;
     float num = (magnitude + acceleration) * (0.5f + 0.5f * (magnitude + acceleration) / braking) + carAI.m_info.m_generatedInfo.m_size.z * 0.5f;
     float num2 = Mathf.Max(magnitude + acceleration, 5f);
     if (lodPhysics >= 2 && (ulong)(currentFrameIndex >> 4 & 3u) == (ulong)((long)(vehicleID & 3)))
     {
         num2 *= 2f;
     }
     float num3 = Mathf.Max((num - num2) / 3f, 1f);
     float num4 = num2 * num2;
     float num5 = num3 * num3;
     int i = 0;
     bool flag = false;
     if ((sqrMagnitude < num4 || vehicleData.m_targetPos3.w < 0.01f) && (leaderData.m_flags & (Vehicle.Flags.WaitingPath | Vehicle.Flags.Stopped)) == Vehicle.Flags.None)
     {
         if (leaderData.m_path != 0u)
         {
             CustomVehicleAI.UpdatePathTargetPositions(carAI, vehicleID, ref vehicleData, frameData.m_position, ref i, 4, num4, num5);
             if ((leaderData.m_flags & Vehicle.Flags.Spawned) == Vehicle.Flags.None)
             {
                 frameData = vehicleData.m_frame0;
                 return;
             }
         }
         if ((leaderData.m_flags & Vehicle.Flags.WaitingPath) == Vehicle.Flags.None)
         {
             while (i < 4)
             {
                 float minSqrDistance;
                 Vector3 refPos;
                 if (i == 0)
                 {
                     minSqrDistance = num4;
                     refPos = frameData.m_position;
                     flag = true;
                 }
                 else
                 {
                     minSqrDistance = num5;
                     refPos = vehicleData.GetTargetPos(i - 1);
                 }
                 int num6 = i;
                 carAI.UpdateBuildingTargetPositions(vehicleID, ref vehicleData, refPos, leaderID, ref leaderData, ref i, minSqrDistance);
                 if (i == num6)
                 {
                     break;
                 }
             }
             if (i != 0)
             {
                 Vector4 targetPos = vehicleData.GetTargetPos(i - 1);
                 while (i < 4)
                 {
                     vehicleData.SetTargetPos(i++, targetPos);
                 }
             }
         }
         vector = vehicleData.m_targetPos0 - (Vector4)frameData.m_position;
         sqrMagnitude = vector.sqrMagnitude;
     }
     if (leaderData.m_path != 0u && (leaderData.m_flags & Vehicle.Flags.WaitingPath) == Vehicle.Flags.None)
     {
         NetManager instance = Singleton<NetManager>.instance;
         byte b = leaderData.m_pathPositionIndex;
         byte lastPathOffset = leaderData.m_lastPathOffset;
         if (b == 255)
         {
             b = 0;
         }
         float num7 = 1f + leaderData.CalculateTotalLength(leaderID);
         PathManager instance2 = Singleton<PathManager>.instance;
         PathUnit.Position pathPos;
         if (instance2.m_pathUnits.m_buffer[(int)((UIntPtr)leaderData.m_path)].GetPosition(b >> 1, out pathPos))
         {
             instance.m_segments.m_buffer[(int)pathPos.m_segment].AddTraffic(Mathf.RoundToInt(num7 * 2.5f));
             bool flag2 = false;
             if ((b & 1) == 0 || lastPathOffset == 0)
             {
                 uint laneID = PathManager.GetLaneID(pathPos);
                 if (laneID != 0u)
                 {
                     Vector3 b2 = instance.m_lanes.m_buffer[(int)((UIntPtr)laneID)].CalculatePosition((float)pathPos.m_offset * 0.003921569f);
                     float num8 = 0.5f * magnitude * magnitude / carAI.m_info.m_braking + carAI.m_info.m_generatedInfo.m_size.z * 0.5f;
                     if (Vector3.Distance(frameData.m_position, b2) >= num8 - 1f)
                     {
                         instance.m_lanes.m_buffer[(int)((UIntPtr)laneID)].ReserveSpace(num7);
                         flag2 = true;
                     }
                 }
             }
             if (!flag2 && instance2.m_pathUnits.m_buffer[(int)((UIntPtr)leaderData.m_path)].GetNextPosition(b >> 1, out pathPos))
             {
//.........这里部分代码省略.........
开发者ID:moverperfect,项目名称:csl-traffic,代码行数:101,代码来源:CustomCarAI.cs

示例3: SimulationStep

        public override void SimulationStep(ushort vehicleID, ref Vehicle vehicleData, ref Vehicle.Frame frameData, ushort leaderID, ref Vehicle leaderData, int lodPhysics)
        {
            uint currentFrameIndex = Singleton<SimulationManager>.instance.m_currentFrameIndex;
            frameData.m_position += frameData.m_velocity * 0.5f;
            frameData.m_swayPosition += frameData.m_swayVelocity * 0.5f;
            float acceleration = this.m_info.m_acceleration;
            float braking = this.m_info.m_braking;
            float magnitude = frameData.m_velocity.magnitude;
            Vector3 vector = (Vector3)vehicleData.m_targetPos0 - frameData.m_position;
            float sqrMagnitude = vector.sqrMagnitude;
            float num = (magnitude + acceleration) * (0.5f + 0.5f * (magnitude + acceleration) / braking) + this.m_info.m_generatedInfo.m_size.z * 0.5f;
            float num2 = Mathf.Max(magnitude + acceleration, 5f);
            if (lodPhysics >= 2 && (ulong)(currentFrameIndex >> 4 & 3u) == (ulong)((long)(vehicleID & 3)))
            {
                num2 *= 2f;
            }
            float num3 = Mathf.Max((num - num2) / 3f, 1f);
            float num4 = num2 * num2;
            float num5 = num3 * num3;
            int i = 0;
            bool flag = false;
            if ((sqrMagnitude < num4 || vehicleData.m_targetPos3.w < 0.01f) && (leaderData.m_flags & (Vehicle.Flags.WaitingPath | Vehicle.Flags.Stopped)) == Vehicle.Flags.None)
            {
                if (leaderData.m_path != 0u)
                {
                    base.UpdatePathTargetPositions(vehicleID, ref vehicleData, frameData.m_position, ref i, 4, num4, num5);
                    if ((leaderData.m_flags & Vehicle.Flags.Spawned) == Vehicle.Flags.None)
                    {
                        frameData = vehicleData.m_frame0;
                        return;
                    }
                }
                if ((leaderData.m_flags & Vehicle.Flags.WaitingPath) == Vehicle.Flags.None)
                {
                    while (i < 4)
                    {
                        float minSqrDistance;
                        Vector3 refPos;
                        if (i == 0)
                        {
                            minSqrDistance = num4;
                            refPos = frameData.m_position;
                            flag = true;
                        }
                        else
                        {
                            minSqrDistance = num5;
                            refPos = vehicleData.GetTargetPos(i - 1);
                        }
                        int num6 = i;
                        this.UpdateBuildingTargetPositions(vehicleID, ref vehicleData, refPos, leaderID, ref leaderData, ref i, minSqrDistance);
                        if (i == num6)
                        {
                            break;
                        }
                    }
                    if (i != 0)
                    {
                        Vector4 targetPos = vehicleData.GetTargetPos(i - 1);
                        while (i < 4)
                        {
                            vehicleData.SetTargetPos(i++, targetPos);
                        }
                    }
                }
                vector = (Vector3)vehicleData.m_targetPos0 - frameData.m_position;
                sqrMagnitude = vector.sqrMagnitude;
            }
            if (leaderData.m_path != 0u && (leaderData.m_flags & Vehicle.Flags.WaitingPath) == Vehicle.Flags.None)
            {
                NetManager instance = Singleton<NetManager>.instance;
                byte b = leaderData.m_pathPositionIndex;
                byte lastPathOffset = leaderData.m_lastPathOffset;
                if (b == 255)
                {
                    b = 0;
                }
                float num7 = 1f + leaderData.CalculateTotalLength(leaderID);
                PathManager instance2 = Singleton<PathManager>.instance;
                PathUnit.Position pathPos;
                if (instance2.m_pathUnits.m_buffer[(int)((UIntPtr)leaderData.m_path)].GetPosition(b >> 1, out pathPos))
                {
                    instance.m_segments.m_buffer[(int)pathPos.m_segment].AddTraffic(Mathf.RoundToInt(num7 * 2.5f));
                    bool flag2 = false;
                    if ((b & 1) == 0 || lastPathOffset == 0)
                    {
                        uint laneID = PathManager.GetLaneID(pathPos);
                        if (laneID != 0u)
                        {
                            Vector3 b2 = instance.m_lanes.m_buffer[(int)((UIntPtr)laneID)].CalculatePosition((float)pathPos.m_offset * 0.003921569f);
                            float num8 = 0.5f * magnitude * magnitude / this.m_info.m_braking + this.m_info.m_generatedInfo.m_size.z * 0.5f;
                            if (Vector3.Distance(frameData.m_position, b2) >= num8 - 1f)
                            {
                                instance.m_lanes.m_buffer[(int)((UIntPtr)laneID)].ReserveSpace(num7);
                                flag2 = true;
                            }
                        }
                    }
                    if (!flag2 && instance2.m_pathUnits.m_buffer[(int)((UIntPtr)leaderData.m_path)].GetNextPosition(b >> 1, out pathPos))
                    {
//.........这里部分代码省略.........
开发者ID:fadster,项目名称:TrafficManager_ImprovedAI,代码行数:101,代码来源:CustomCarAI.cs


注:本文中的Vehicle.SetTargetPos方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。