public void FlightGeometryUpdate()
 {
     if (deployEvent == null)
     {
         Debug.Log("Update fairing event");
         FieldInfo[] fields = fairing.GetType().GetFields(BindingFlags.NonPublic | BindingFlags.Instance);
         deployEvent          = (KFSMEvent)fields[31].GetValue(fairing);
         deployEvent.OnEvent += delegate { FairingDeployGeometryUpdate(); };
     }
 }
        public void RemovePart(GameEvents.HostTargetAction <Part, Part> RemovedPart)
        {
            if (null == FairingModule)
            {
                return;
            }

            if (RemovedPart.target == part)
            {
                if (FairingModule.xSections.Count > 0)
                {
                    Debug.LogWarning("Deleting Fairing");
                    FairingModule.DeleteFairing();
                }
                MethodInfo MPFMethod = FairingModule.GetType().GetMethod("DumpInterstage", BindingFlags.NonPublic | BindingFlags.Instance);

                if (MPFMethod != null)
                {
                    MPFMethod.Invoke(FairingModule, new object[] { });
                }
            }
        }
Ejemplo n.º 3
0
        private void SetupFlightEvents()
        {
            if (deployEvent == null)
            {
                Debug.Log("Update fairing event");
                FieldInfo[] fields = fairing.GetType().GetFields(BindingFlags.NonPublic | BindingFlags.Instance);
                bool        deployBool = false, breakBool = false;

                deployEvent          = (KFSMEvent)fields[32].GetValue(fairing);
                deployEvent.OnEvent += delegate { FairingDeployGeometryUpdate(); };
                deployBool           = true;

                breakEvent          = (KFSMEvent)fields[33].GetValue(fairing);
                breakEvent.OnEvent += delegate { FairingDeployGeometryUpdate(); };
                breakBool           = true;

                /*for (int i = 0; i < fields.Length; ++i)
                 * {
                 *  FieldInfo field = fields[i];
                 *  if (field.Name.ToLowerInvariant() == "on_deploy")
                 *  {
                 *      deployEvent = (KFSMEvent)field.GetValue(fairing);
                 *      deployEvent.OnEvent += delegate { FairingDeployGeometryUpdate(); };
                 *      deployBool = true;
                 *      Debug.Log("Deploy event field index " + i);
                 *  }
                 *  else if (field.Name.ToLowerInvariant() == "on_breakoff")
                 *  {
                 *      breakEvent = (KFSMEvent)field.GetValue(fairing);
                 *      breakEvent.OnEvent += delegate { FairingDeployGeometryUpdate(); };
                 *      breakBool = true;
                 *      Debug.Log("Break event field index " + i);
                 *  }
                 *  if (deployBool && breakBool)
                 *      break;
                 * }*/
                if (!deployBool)
                {
                    Debug.LogError("FAR could not find Stock Procedural Fairing deploy event");
                }
                if (!breakBool)
                {
                    Debug.LogError("FAR could not find Stock Procedural Fairing break event");
                }
            }
        }
        // Recurse through the master branch and the newly placed symmetric branch, copying over part info.
        void UpdatePartAndChildren(Part SourcePart, Part UpdatePart, SymmetryMethod SymMethod)
        {
            if (null == SourcePart || null == UpdatePart)
            {
                // Null parts were passed to the updater. This should not happen, but just in case...
                return;
            }

            // Fix the bug where staging icons split from each other.
            UpdatePart.originalStage = SourcePart.originalStage;

            // This shouldn't be needed anymore.
            if (0 == UpdatePart.symmetryCounterparts.Count)
            {
                // This part has no mirrored parts. No need to copy the action groups.
                return;
            }

            CheckAndAddCounterpart(SourcePart, UpdatePart);
            PropagateCounterparts(SourcePart);

            // Propagates symmetry method throughout the branch. If it ever hits radial symmetry, the rest of the
            // branch needs to be listed as symmetry to prevent editor breakage with nested mirror symmetry.
            if (SourcePart.symmetryCounterparts.Count > 1)
            {
                SymMethod = SymmetryMethod.Radial;
            }
            //if(SourcePart.symMethod == SymmetryMethod.Radial)
            //{
            //    SymMethod = SymmetryMethod.Radial;
            //}

            // Debug.LogWarning("SymmMethod: " + SymMethod);
            SourcePart.symMethod = SymMethod;
            UpdatePart.symMethod = SymMethod;

            if (SourcePart.Modules.Count != UpdatePart.Modules.Count)
            {
                Debug.LogError("SAFix.onPartAttach(): Part Copy Error. Module Count Mismatch.");
                return;
            }

            // Loop through all the modules. Action groups are stored inside the PartModules
            for (int IndexModules = 0; IndexModules < UpdatePart.Modules.Count; IndexModules++)
            {
                if (SourcePart.Modules[IndexModules].Actions.Count != UpdatePart.Modules[IndexModules].Actions.Count)
                {
                    Debug.LogError("SAFix.UpdatePartAndChildren(): Actions Mismatch in Module. Action copy aborted at Module: "
                                   + SourcePart.Modules[IndexModules].moduleName);
                    return;
                }

                // Loop through all the Actions for this module.
                for (int IndexActions = 0; IndexActions < SourcePart.Modules[IndexModules].Actions.Count; IndexActions++)
                {
                    // Copy the Action's triggers.
                    // Debug.LogWarning("Module/Action " + UpdatePart.Modules[IndexModules].Actions[IndexActions].name);
                    UpdatePart.Modules[IndexModules].Actions[IndexActions].actionGroup =
                        SourcePart.Modules[IndexModules].Actions[IndexActions].actionGroup;
                }

                if ("ModuleProceduralFairing" == SourcePart.Modules[IndexModules].moduleName)
                {
                    Debug.Log("SymmetryActionFix: Fixing Procedural Fairing");

                    ModuleProceduralFairing MPFSource = (ModuleProceduralFairing)SourcePart.Modules[IndexModules];
                    ModuleProceduralFairing MPFUpdate = (ModuleProceduralFairing)UpdatePart.Modules[IndexModules];

                    if (MPFSource.xSections.Count != 0)
                    {
                        MPFUpdate.xSections.AddRange(MPFSource.xSections);

                        MethodInfo MPFMethod = MPFUpdate.GetType().GetMethod("SpawnMeshes", BindingFlags.NonPublic | BindingFlags.Instance);

                        if (MPFMethod != null)
                        {
                            MPFMethod.Invoke(MPFUpdate, new object[] { true });
                        }
                    }
                }
            }

            for (int IndexChild = 0; IndexChild < UpdatePart.children.Count; IndexChild++)
            {
                // Go through all the children parts and copy the actions.
                UpdatePartAndChildren(SourcePart.children[IndexChild], UpdatePart.children[IndexChild], SymMethod);
            }
        } // UpdatePartAndChild