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


C# Vessel.BackupVessel方法代码示例

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


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

示例1: OnVesselCreate

        private void OnVesselCreate(Vessel vessel)
        {
            ProtoVessel pv = vessel.BackupVessel();
            List<uint> vesselParts = new List<uint>();
            bool killShip = false;
            bool vesselOk = false;
            foreach (ProtoPartSnapshot pps in pv.protoPartSnapshots)
            {
                if (pps.flightID == 0)
                {
                    loadGuid = vessel.id;
                    //When you spawn a new vessel in all the part ID's are 0 until OnFlightReady.
                    return;
                }
                vesselParts.Add(pps.flightID);
                if (partToVessel.ContainsKey(pps.flightID))
                {
                    killShip = true;
                    foreach (Vessel otherVessel in partToVessel[pps.flightID])
                    {
                        if (otherVessel.id == vessel.id)
                        {
                            vesselOk = true;
                        }
                        //Either of the locks are ours or neither of the locks exist
                        if (LockSystem.fetch.LockIsOurs("control-" + otherVessel.id) || LockSystem.fetch.LockIsOurs("update-" + otherVessel.id) || (!LockSystem.fetch.LockExists("control-" + otherVessel.id) && !LockSystem.fetch.LockExists("update-" + otherVessel.id)))
                        {
                            vesselOk = true;
                        }
                    }
                }
            }
            if (killShip && !vesselOk)
            {
                DarkLog.Debug("PartKiller: Destroying vessel fragment");
                vessel.Die();
            }
            else
            {
                vesselToPart.Add(vessel, vesselParts);
                foreach (uint partID in vesselParts)
                {
                    if (!partToVessel.ContainsKey(partID))
                    {
                        partToVessel.Add(partID, new List<Vessel>());
                    }
                    partToVessel[partID].Add(vessel);
                }
            }

        }
开发者ID:Opice,项目名称:DarkMultiPlayer,代码行数:51,代码来源:PartKiller.cs

示例2: OnVesselWillDestroy

 private void OnVesselWillDestroy(Vessel vessel)
 {
     bool pilotedByAnotherPlayer = LockSystem.fetch.LockExists("control-" + vessel.id) && !LockSystem.fetch.LockIsOurs("control-" + vessel.id);
     bool updatedByAnotherPlayer = LockSystem.fetch.LockExists("update-" + vessel.id) && !LockSystem.fetch.LockIsOurs("update-" + vessel.id);
     bool updatedInTheFuture = VesselWorker.fetch.VesselUpdatedInFuture(vessel.id);
     //Vessel was packed within the last 5 seconds
     if (lastPackTime.ContainsKey(vessel.id) && (UnityEngine.Time.realtimeSinceStartup - lastPackTime[vessel.id]) < 5f)
     {
         lastPackTime.Remove(vessel.id);
         if (vessel.situation == Vessel.Situations.FLYING && (pilotedByAnotherPlayer || updatedByAnotherPlayer || updatedInTheFuture))
         {
             DarkLog.Debug("Hacky load: Saving player vessel getting packed in atmosphere");
             ProtoVessel pv = vessel.BackupVessel();
             ConfigNode savedNode = new ConfigNode();
             pv.Save(savedNode);
             VesselWorker.fetch.LoadVessel(savedNode, vessel.id, true);
         }
     }
     if (lastPackTime.ContainsKey(vessel.id))
     {
         lastPackTime.Remove(vessel.id);
     }
 }
开发者ID:Opice,项目名称:DarkMultiPlayer,代码行数:23,代码来源:HackyInAtmoLoader.cs

示例3: UnhangarCraft

        public static void UnhangarCraft(Vessel vVesselStored, StaticObject soHangar)
        {
            RemoveCorrectCraft(vVesselStored, soHangar);

            // Convert the stored protovessel to a new protovessel.
            // Use BackupVessel because that seems to work and protovessel does not. `\o/`
            ProtoVessel pVessel = vVesselStored.BackupVessel();

            // Get rid of the original hidden vessel - even though it was unloaded KSP still 'sees' the original craft.
            // I do not care why. :|
            vVesselStored.state = Vessel.State.DEAD;

            foreach (Part p in vVesselStored.Parts)
            {
                if (p != null && p.gameObject != null)
                    p.gameObject.DestroyGameObject();
            }

            // Load the new protovessel we made. KSP won't reload (or rather render) a vessel that was unloaded - it will only load a protovessel. :$
            pVessel.Load(FlightDriver.FlightStateCache.flightState);
            // I suspect this is actually a KSP bug since the same crap happens with newly spawned static objects. If you query the active state
            // of the invisible craft, it claims it is active. And no, forcing the renderers doesn't work either.

            // Convert protovessel to vessel
            Vessel vNewVessel = pVessel.vesselRef;

            // Unload then reload the vessel - this seems to be the way to properly re-initialise flightstate etc.
            // Don't do this and you get a craft with a stuck surface velocity reading. It looks like KSP transposes orbital
            // and surface velocity or some other stupid s**t. I don't care.
            // And yes, this time KSP does load an unloaded vessel with no need for protovessel b******t. I don't care why.
            vNewVessel.Unload();
            vNewVessel.Load();
        }
开发者ID:AlphaAsh,项目名称:Kerbal-Konstructs_DEV,代码行数:33,代码来源:HangarGUI.cs

示例4: OnVesselCreate

 public void OnVesselCreate(Vessel createdVessel)
 {
     try
     {
         //DarkLog.Debug("Vessel creation detected: " + createdVessel.id + ", name: " + createdVessel.vesselName);
         ProtoVessel pv = createdVessel.BackupVessel();
         bool killShip = false;
         bool spawnDebris = false;
         string partOwner = null;
         string createdVesselID = pv.vesselID.ToString();
         foreach (ProtoPartSnapshot vesselPart in pv.protoPartSnapshots)
         {
             if (vesselPart != null)
             {
                 if (vesselParts.ContainsKey(vesselPart.flightID.ToString()))
                 {
                     partOwner = vesselParts[vesselPart.flightID.ToString()];
                     if (!killShip && (createdVesselID != partOwner))
                     {
                         if (LockSystem.fetch.LockIsOurs("control-" + partOwner) || LockSystem.fetch.LockIsOurs("update-" + partOwner) || !LockSystem.fetch.LockExists("update-" + partOwner))
                         {
                             //Vessel is ours, update the part owner.
                             spawnDebris = true;
                             vesselParts[vesselPart.flightID.ToString()] = createdVesselID;
                         }
                         else
                         {
                             DarkLog.Debug("Detected debris for a vessel we do not control, removing " + createdVesselID);
                             killShip = true;
                             break;
                         }
                     }
                 }
             }
         }
         if (killShip)
         {
             createdVessel.Die();
         }
         if (spawnDebris)
         {
             //DarkLog.Debug("Spawned debris " + createdVesselID + " from " + partOwner);
         }
     }
     catch (Exception e)
     {
         DarkLog.Debug("Threw in OnVesselCreate: " + e);
     }
 }
开发者ID:martindevans,项目名称:DarkMultiPlayer,代码行数:49,代码来源:VesselWorker.cs

示例5: CheckVesselParts

 private void CheckVesselParts(Vessel checkVessel)
 {
     List<string> allowedParts = ModWorker.fetch.GetAllowedPartsList();
     List<string> bannedParts = new List<string>();
     ProtoVessel checkProto = checkVessel.BackupVessel();
     foreach (ProtoPartSnapshot part in checkProto.protoPartSnapshots)
     {
         if (!allowedParts.Contains(part.partName))
         {
             if (!bannedParts.Contains(part.partName))
             {
                 bannedParts.Add(part.partName);
             }
         }
     }
     if (checkVessel.isActiveVessel)
     {
         bannedPartsString = "";
         foreach (string bannedPart in bannedParts)
         {
             bannedPartsString += bannedPart + "\n";
         }
     }
     DarkLog.Debug("Checked vessel " + checkVessel.id.ToString() + " for banned parts, is ok: " + (bannedParts.Count == 0));
     vesselPartsOk[checkVessel.id] = (bannedParts.Count == 0);
 }
开发者ID:awdAvenger,项目名称:DarkMultiPlayer,代码行数:26,代码来源:VesselWorker.cs

示例6: loadVesselForRendezvous

        private bool loadVesselForRendezvous(ProtoVessel placeVessel, Vessel targetVessel)
        {
            targetVessel.BackupVessel();

            placeVessel.orbitSnapShot = targetVessel.protoVessel.orbitSnapShot;

            placeVessel.orbitSnapShot.epoch = 0.0;

            tempID = rand.Next(1000000000).ToString();
            //rename any vessels present with "AdministativeDockingName"
            foreach (Vessel ve in FlightGlobals.Vessels)
            {
                if (ve.vesselName == tempID)
                {
                    Vessel NameVessel = null;
                    NameVessel = ve;
                    NameVessel.vesselName = "1";
                }
            }

            placeVessel.vesselID = Guid.NewGuid();

            placeVessel.vesselName = tempID;

            foreach (ProtoPartSnapshot p in placeVessel.protoPartSnapshots)
            {
                if (placeVessel.refTransform == p.flightID)
                {
                    p.flightID = (UInt32)rand.Next(1000000000, 2147483647);
                    placeVessel.refTransform = p.flightID;
                }
                else
                {
                    p.flightID = (UInt32)rand.Next(1000000000, 2147483647);
                }

                if (p.protoModuleCrew != null && p.protoModuleCrew.Count() != 0)
                {
                    List<ProtoCrewMember> cl = p.protoModuleCrew;
                    List<ProtoCrewMember> clc = new List<ProtoCrewMember>(cl);

                    foreach (ProtoCrewMember c in clc)
                    {
                        p.RemoveCrew(c);
                        //print("remove");
                    }
                }
            }

            try
            {
                placeVessel.Load(HighLogic.CurrentGame.flightState);
                return true;
            }
            catch
            {
                //abortArrival();
                //return false;
                return true;
            }
        }
开发者ID:PrivateFlip,项目名称:RoutineMissionManager,代码行数:61,代码来源:Routine.cs

示例7: StoredVessel

 public StoredVessel(Vessel vsl, bool compute_hull=false)
 {
     proto_vessel = vsl.BackupVessel();
     metric = new Metric(vsl, compute_hull);
     id     = proto_vessel.vesselID;
     name   = proto_vessel.vesselName;
     crew   = vsl.GetVesselCrew();
     resources = new VesselResources<ProtoVessel, ProtoPartSnapshot, ProtoPartResourceSnapshot>(proto_vessel);
 }
开发者ID:pjslauta,项目名称:hangar,代码行数:9,代码来源:VesselWrappers.cs

示例8: OnVesselWasModified

 private void OnVesselWasModified(Vessel vessel)
 {
     if (!vesselToPart.ContainsKey(vessel))
     {
         //Killed as a fragment.
         return;
     }
     List<uint> addList = new List<uint>();
     List<uint> removeList = new List<uint>(vesselToPart[vessel]);
     ProtoVessel pv = vessel.BackupVessel();
     foreach (ProtoPartSnapshot pps in pv.protoPartSnapshots)
     {
         if (removeList.Contains(pps.flightID))
         {
             removeList.Remove(pps.flightID);
         }
         else
         {
             addList.Add(pps.flightID);
         }
     }
     foreach (uint partID in addList)
     {
         if (!partToVessel.ContainsKey(partID))
         {
             partToVessel.Add(partID, new List<Vessel>());
         }
         partToVessel[partID].Add(vessel);
         vesselToPart[vessel].Add(partID);
     }
     foreach (uint partID in removeList)
     {
         vesselToPart[vessel].Remove(partID);
         partToVessel[partID].Remove(vessel);
         if (partToVessel[partID].Count == 0)
         {
             partToVessel.Remove(partID);
         }
     }
 }
开发者ID:Opice,项目名称:DarkMultiPlayer,代码行数:40,代码来源:PartKiller.cs

示例9: StoredVessel

 public StoredVessel(Vessel vsl)
 {
     vessel = vsl.BackupVessel();
     metric = new Metric(vsl);
     id     = vessel.vesselID;
     CoM    = vsl.findLocalCenterOfMass();
     crew   = vsl.GetVesselCrew();
     resources = new VesselResources<ProtoVessel, ProtoPartSnapshot, ProtoPartResourceSnapshot>(vessel);
     //			fixTripLogger(); //FIXME
 }
开发者ID:kevin-ye,项目名称:hangar,代码行数:10,代码来源:VesselWrappers.cs

示例10: SendVesselUpdateIfNeeded

        public void SendVesselUpdateIfNeeded(Vessel checkVessel)
        {
            //Check vessel parts
            if (ModWorker.fetch.modControl != ModControlMode.DISABLED)
            {
                if (!vesselPartsOk.ContainsKey(checkVessel.id))
                {
                    CheckVesselParts(checkVessel);
                }
                if (!vesselPartsOk[checkVessel.id])
                {
                    //Vessel with bad parts
                    return;
                }
            }

            if (checkVessel.state == Vessel.State.DEAD)
            {
                //Don't send dead vessels
                return;
            }

            if (checkVessel.vesselType == VesselType.Flag && checkVessel.id == Guid.Empty && checkVessel.vesselName != "Flag")
            {
                DarkLog.Debug("Fixing flag GUID for " + checkVessel.vesselName);
                checkVessel.id = Guid.NewGuid();
            }

            //Only send updates for craft we have update locks for. Request the lock if it's not taken.
            if (!LockSystem.fetch.LockExists("update-" + checkVessel.id.ToString()))
            {
                LockSystem.fetch.ThrottledAcquireLock("update-" + checkVessel.id.ToString());
            }

            // Check if it isn't null before fetching it
            if (FlightGlobals.fetch.activeVessel != null)
            {
                //Take the update lock off another player if we have the control lock and it's our vessel
                if (checkVessel.id == FlightGlobals.fetch.activeVessel.id)
                {
                    if (LockSystem.fetch.LockExists("update-" + checkVessel.id.ToString()) && !LockSystem.fetch.LockIsOurs("update-" + checkVessel.id.ToString()) && LockSystem.fetch.LockIsOurs("control-" + checkVessel.id.ToString()))
                    {
                        LockSystem.fetch.ThrottledAcquireLock("update-" + checkVessel.id.ToString());
                        //Wait until we have the update lock
                        return;
                    }
                }
            }

            //Send updates for unpacked vessels that aren't being flown by other players
            bool notRecentlySentProtoUpdate = serverVesselsProtoUpdate.ContainsKey(checkVessel.id) ? ((UnityEngine.Time.realtimeSinceStartup - serverVesselsProtoUpdate[checkVessel.id]) > VESSEL_PROTOVESSEL_UPDATE_INTERVAL) : true;
            bool notRecentlySentPositionUpdate = serverVesselsPositionUpdate.ContainsKey(checkVessel.id) ? ((UnityEngine.Time.realtimeSinceStartup - serverVesselsPositionUpdate[checkVessel.id]) > (1f / (float)DynamicTickWorker.fetch.sendTickRate)) : true;

            //Check that is hasn't been recently sent
            if (notRecentlySentProtoUpdate)
            {
                ProtoVessel checkProto = checkVessel.BackupVessel();
                //TODO: Fix sending of flying vessels.
                if (checkProto != null)
                {
                    if (checkProto.vesselID != Guid.Empty)
                    {
                        //Also check for kerbal state changes
                        foreach (ProtoPartSnapshot part in checkProto.protoPartSnapshots)
                        {
                            foreach (ProtoCrewMember pcm in part.protoModuleCrew.ToArray())
                            {
                                SendKerbalIfDifferent(pcm);
                            }
                        }
                        RegisterServerVessel(checkProto.vesselID);
                        //Mark the update as sent
                        serverVesselsProtoUpdate[checkVessel.id] = UnityEngine.Time.realtimeSinceStartup;
                        //Also delay the position send
                        serverVesselsPositionUpdate[checkVessel.id] = UnityEngine.Time.realtimeSinceStartup;
                        latestUpdateSent[checkVessel.id] = UnityEngine.Time.realtimeSinceStartup;
                        bool isFlyingUpdate = (checkProto.situation == Vessel.Situations.FLYING);
                        NetworkWorker.fetch.SendVesselProtoMessage(checkProto, false, isFlyingUpdate);
                    }
                    else
                    {
                        DarkLog.Debug(checkVessel.vesselName + " does not have a guid!");
                    }
                }
            }
            else if (notRecentlySentPositionUpdate && checkVessel.vesselType != VesselType.Flag)
            {
                //Send a position update - Except for flags. They aren't exactly known for their mobility.
                serverVesselsPositionUpdate[checkVessel.id] = UnityEngine.Time.realtimeSinceStartup;
                latestUpdateSent[checkVessel.id] = UnityEngine.Time.realtimeSinceStartup;
                VesselUpdate update = VesselUpdate.CopyFromVessel(checkVessel);
                if (update != null)
                {
                    NetworkWorker.fetch.SendVesselUpdate(update);
                }
            }
        }
开发者ID:RockyTV,项目名称:DarkMultiPlayer,代码行数:97,代码来源:VesselWorker.cs


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