コード例 #1
0
        void OnStartClientInternal()
        {
            GameObject vehicleGo = NetManager.GetNetworkObjectById(m_net_vehicleNetId);

            if (null == vehicleGo)
            {
                // this should only happen when vehicle has been destroyed before client connected, but it's detached parts are still alive
                // load vehicle's model, and attach it's frames to dummy object, and detach a frame from that dummy object



                VehicleDef def = Item.GetDefinitionOrThrow <VehicleDef>(m_net_vehicleModelId);

                int[] colors = VehicleController.DeserializeColors(m_net_vehicleColors);

                var geometryParts = Vehicle.LoadGeometryParts(def);


                VehicleInfo vehicleInfo;
                if (s_dummyObjectsPerVehicle.TryGetValue(m_net_vehicleNetId, out vehicleInfo))
                {
                    // we already created dummy object for this vehicle
                    vehicleInfo.numReferences++;
                }
                else
                {
                    // need to create dummy object for this vehicle, and attach all vehicle's frames to it
                    Transform transformDummy = new GameObject($"{def.GameName}_detached_part_{m_net_frameName}").transform;
                    vehicleInfo        = new VehicleInfo();
                    vehicleInfo.frames = geometryParts.AttachFrames(transformDummy, Importing.Conversion.MaterialFlags.Vehicle);
                    SetColors(vehicleInfo.frames, colors);
                    vehicleInfo.numReferences = 1;
                    s_dummyObjectsPerVehicle.Add(m_net_vehicleNetId, vehicleInfo);
                }

                m_isReferencingFrame = true;

                Frame frame = vehicleInfo.frames.FirstOrDefault(f => f.gameObject.name == m_net_frameName);
                if (null == frame)
                {
                    throw new System.Exception($"Failed to find frame by name {m_net_frameName}");
                }

                // detach frame from dummy object
                Vehicle.DetachFrameFromTransformDuringExplosion(vehicleInfo.frames.transform, frame, m_net_mass, this.gameObject, m_net_vehicleNetId, m_net_vehicleModelId, colors);
            }
            else
            {
                Vehicle vehicle = vehicleGo.GetComponentOrThrow <Vehicle>();
                vehicle.DetachFrameDuringExplosion(m_net_frameName, m_net_mass, this.gameObject);
            }

            var rb = this.GetComponentInChildren <Rigidbody>();

            if (rb != null)
            {
                rb.interpolation = RigidbodyInterpolation.Interpolate;
            }
            this.NetworkRigidBody.Rigidbody = rb;
        }