コード例 #1
0
 public ResourceLine(Part part, PartResourceDefinition res_def, float rate)
 {
     Resource = res_def;
     Rate     = base_rate = rate;
     if (res_def != null)
     {
         Pump  = new ResourcePump(part, res_def.id);
         URate = rate / res_def.density;
     }
 }
コード例 #2
0
 public override void OnStart(StartState state)
 {
     base.OnStart(state);
     Duration = 0f;
     if (State == AnimatorState.Opened)
     {
         progress = 1f;
     }
     setup_animation();
     set_progress(progress);
     if (EnergyConsumption > 0)
     {
         socket = part.CreateSocket();
     }
     //GUI
     Events["Toggle"].guiName        = OpenEventGUIName;
     Actions["ToggleAction"].guiName = ActionGUIName;
     Fields["StopTime"].guiName      = StopTimeGUIName;
     update_events();
 }
コード例 #3
0
 public override void OnStart(StartState state)
 {
     base.OnStart(state);
     socket = part.CreateSocket();
     //get other converters
     if (AnimatorID != "_none_")
     {
         other_converters.AddRange(from c in part.Modules.OfType <AnimatedConverterBase>()
                                   where c != this && c.AnimatorID == AnimatorID select c);
     }
     //initialize Animator
     animator = part.GetAnimator(AnimatorID);
     //setup GUI fields
     Fields["Temperature"].guiActive       = HeatProduction > 0;
     Fields["CurrentEnergyDemand"].guiName = Title + " Uses";
     Fields["Rate"].guiName              = Title + " Rate";
     Events["StartConversion"].guiName   = StartEventGUIName + " " + Title;
     Events["StopConversion"].guiName    = StopEventGUIName + " " + Title;
     Actions["ToggleConversion"].guiName = ActionGUIName + " " + Title;
     //update state
     update_energy_demand();
     update_events();
     StartCoroutine(slow_update());
 }
コード例 #4
0
 public void InitializePump(Part part, float rate_multiplier)
 {
     Pump  = new ResourcePump(part, Resource.id);
     Rate  = base_rate * rate_multiplier;
     URate = Rate / Resource.density;
 }
コード例 #5
0
        public override void OnStart(StartState state)
        {
            base.OnStart(state);
            hasSensor              = false;
            HasAttractor           = false;
            EnergyConsumptionK     = Utils.ClampL(EnergyConsumptionK, 1e-6f);
            thermalLossesK         = 1 + ThermalLossesRatio;
            damperActive           = DamperEnabled;
            deactivateTimer.Period = AutoDeactivateAfterSeconds;
            if (!string.IsNullOrEmpty(Sensors))
            {
                foreach (var sensorName in Utils.ParseLine(Sensors, Utils.Whitespace))
                {
                    var sensor = part.FindModelComponent <MeshFilter>(sensorName);
                    if (sensor == null)
                    {
                        this.Log($"Unable to find {sensorName} MeshFilter in {part.name}");
                        continue;
                    }
                    addSensor(sensor);
                    hasSensor = true;
                }
                if (hasSensor)
                {
                    socket = part.CreateSocket();
                    if (!string.IsNullOrEmpty(AffectedPartTags))
                    {
                        tags = Utils.ParseLine(AffectedPartTags, Utils.Comma);
                    }
                    if (!string.IsNullOrEmpty(AttractorLocation))
                    {
                        attractor = part.FindModelTransform(AttractorLocation);
                        if (attractor != null)
                        {
                            HasAttractor = true;
                            switch (AttractorMainAxis)
                            {
                            case AttractorAxis.right:
                                attractorAxis = Vector3.right;
                                break;

                            case AttractorAxis.up:
                                attractorAxis = Vector3.up;
                                break;

                            case AttractorAxis.fwd:
                                attractorAxis = Vector3.forward;
                                break;

                            default:
                                attractorAxis = Vector3.forward;
                                break;
                            }
                        }
                    }
                    animator = part.GetAnimator(AnimatorID);
                    if (DamperEnabled)
                    {
                        animator?.Open();
                    }
                    else
                    {
                        animator?.Close();
                    }
                    StartCoroutine(dampPackedVessels());
                }
            }
            if (!hasSensor)
            {
                this.EnableModule(false);
                return;
            }
            // setup visibility of actions, events and various PAW fields
            var damper_controllable    = hasSensor && EnableControls;
            var attractor_controllable = damper_controllable && HasAttractor;

            Fields[nameof(DamperEnabled)].OnValueModified += onDamperToggle;
            Utils.EnableField(Fields[nameof(DamperEnabled)], damper_controllable);
            Utils.EnableField(Fields[nameof(Attenuation)], damper_controllable);
            Utils.EnableField(Fields[nameof(AutoEnable)], damper_controllable);
            Actions[nameof(ToggleAction)].active = damper_controllable;
            Utils.EnableField(Fields[nameof(AttractorEnabled)], attractor_controllable);
            Utils.EnableField(Fields[nameof(InvertAttractor)], attractor_controllable);
            Actions[nameof(ToggleAttractorAction)].active = attractor_controllable;
            setupAttractorPowerControl(attractor_controllable);
            // setup PAW group
            if (GroupPAWFields)
            {
                var group = new BasePAWGroup(
                    $"{GetType().Name}_{GetInstanceID()}",
                    string.IsNullOrEmpty(DamperID)
                        ? "Magnetic Damper"
                        : Utils.ParseCamelCase(DamperID),
                    false);
                group.startCollapsed = !EnableControls;
                foreach (var field in Fields)
                {
                    field.group = group;
                }
            }
        }