Пример #1
0
        void LoadControllers(ConfigNode node)
        {
            ConfigNode[] controllerNodes = node.GetNodes(WaterfallConstants.ControllerNodeName);

            if (allControllers == null || allControllers.Count == 0)
            {
                Utils.Log(String.Format("[ModuleWaterfallFX]: Loading Controllers on moduleID {0}", moduleID), LogType.Modules);
                allControllers = new Dictionary <string, WaterfallController>();
                foreach (ConfigNode controllerDataNode in controllerNodes)
                {
                    string ctrlType = "throttle";
                    if (!controllerDataNode.TryGetValue("linkedTo", ref ctrlType))
                    {
                        Utils.LogWarning(String.Format("[ModuleWaterfallFX]: Controller on moduleID {0} does not define linkedTo, setting throttle as default ", moduleID));
                    }
                    if (ctrlType == "throttle")
                    {
                        ThrottleController tCtrl = new ThrottleController(controllerDataNode);
                        allControllers.Add(tCtrl.name, tCtrl);
                        Utils.Log(String.Format("[ModuleWaterfallFX]: Loaded Throttle Controller on moduleID {0}", moduleID), LogType.Modules);
                    }
                    if (ctrlType == "atmosphere_density")
                    {
                        AtmosphereDensityController aCtrl = new AtmosphereDensityController(controllerDataNode);
                        allControllers.Add(aCtrl.name, aCtrl);
                        Utils.Log(String.Format("[ModuleWaterfallFX]: Loaded Atmosphere Density Controller on moduleID {0}", moduleID), LogType.Modules);
                    }
                    if (ctrlType == "custom")
                    {
                        CustomController cCtrl = new CustomController(controllerDataNode);
                        allControllers.Add(cCtrl.name, cCtrl);
                        Utils.Log(String.Format("[ModuleWaterfallFX]: Loaded Custom Controller on moduleID {0}", moduleID), LogType.Modules);
                    }
                    if (ctrlType == "rcs")
                    {
                        RCSController rcsCtrl = new RCSController(controllerDataNode);
                        allControllers.Add(rcsCtrl.name, rcsCtrl);
                        Utils.Log(String.Format("[ModuleWaterfallFX]: Loaded RCS Controller on moduleID {0}", moduleID), LogType.Modules);
                    }
                    if (ctrlType == "random")
                    {
                        RandomnessController rCtrl = new RandomnessController(controllerDataNode);

                        allControllers.Add(rCtrl.name, rCtrl);

                        Utils.Log(String.Format("[ModuleWaterfallFX]: Loaded Randomness Controller on moduleID {0}", moduleID), LogType.Modules);
                    }
                    if (ctrlType == "light")
                    {
                        LightController lCtrl = new LightController(controllerDataNode);
                        allControllers.Add(lCtrl.name, lCtrl);
                        Utils.Log(String.Format("[ModuleWaterfallFX]: Loaded Light Controller on moduleID {0}", moduleID), LogType.Modules);
                    }
                    if (ctrlType == "engineEvent")
                    {
                        EngineEventController eEvtCtrl = new EngineEventController(controllerDataNode);
                        allControllers.Add(eEvtCtrl.name, eEvtCtrl);
                        Utils.Log(String.Format("[ModuleWaterfallFX]: Loaded Engine Event Controller on moduleID {0}", moduleID), LogType.Modules);
                    }
                    if (ctrlType == "mach")
                    {
                        MachController mCtrl = new MachController(controllerDataNode);
                        allControllers.Add(mCtrl.name, mCtrl);
                        Utils.Log(String.Format("[ModuleWaterfallFX]: Loaded Mach Controller on moduleID {0}", moduleID), LogType.Modules);
                    }
                    if (ctrlType == "gimbal")
                    {
                        GimbalController gCtrl = new GimbalController(controllerDataNode);
                        allControllers.Add(gCtrl.name, gCtrl);
                        Utils.Log(String.Format("[ModuleWaterfallFX]: Loaded Gimbal Controller on moduleID {0}", moduleID), LogType.Modules);
                    }
                    if (ctrlType == "thrust")
                    {
                        ThrustController tcCtrl = new ThrustController(controllerDataNode);
                        allControllers.Add(tcCtrl.name, tcCtrl);
                        Utils.Log(String.Format("[ModuleWaterfallFX]: Loaded Thrust Curve Controller on moduleID {0}", moduleID), LogType.Modules);
                    }
                }
            }
        }
Пример #2
0
        //public virtual void OnBeforeSerialize()
        //{
        //  Utils.Log($"[ModuleWaterfallFX] Serializing");
        //  serializedData = ScriptableObject.CreateInstance<SerializedData>();

        //  ConfigNode newNode = new ConfigNode("Serialized");
        //  foreach (WaterfallEffect fx in allFX)
        //  {
        //    newNode.AddNode(fx.Save());
        //  }


        //  serializedData.SerializedString = newNode.ToString();
        //}

        //public virtual void OnAfterDeserialize()
        //{
        //  Utils.Log($"[ModuleWaterfallFX] Deserializing");

        //  OnLoad(ConfigNode.Parse(serializedData.SerializedString));

        //  Destroy(serializedData);
        //  serializedData = null;
        //}

        /// <summary>
        /// Load alll CONTROLLERS, TEMPLATES and EFFECTS
        /// </summary>
        /// <param name="node"></param>
        ///

        public override void OnLoad(ConfigNode node)
        {
            base.OnLoad(node);

            ConfigNode[] controllerNodes = node.GetNodes(WaterfallConstants.ControllerNodeName);
            ConfigNode[] effectNodes     = node.GetNodes(WaterfallConstants.EffectNodeName);
            ConfigNode[] templateNodes   = node.GetNodes(WaterfallConstants.TemplateNodeName);

            if (initialized)
            {
                Utils.Log($"[ModuleWaterfallFX]: Cleaning up effects", LogType.Modules);
                CleanupEffects();
            }

            if (allControllers == null)
            {
                Utils.Log(String.Format("[ModuleWaterfallFX]: Loading Controllers on moduleID {0}", moduleID), LogType.Modules);
                allControllers = new Dictionary <string, WaterfallController>();
                foreach (ConfigNode controllerDataNode in controllerNodes)
                {
                    string ctrlType = "throttle";
                    if (!controllerDataNode.TryGetValue("linkedTo", ref ctrlType))
                    {
                        Utils.LogWarning(String.Format("[ModuleWaterfallFX]: Controller on moduleID {0} does not define linkedTo, setting throttle as default ", moduleID));
                    }
                    if (ctrlType == "throttle")
                    {
                        ThrottleController tCtrl = new ThrottleController(controllerDataNode);
                        allControllers.Add(tCtrl.name, tCtrl);
                        Utils.Log(String.Format("[ModuleWaterfallFX]: Loaded Throttle Controller on moduleID {0}", moduleID), LogType.Modules);
                    }
                    if (ctrlType == "atmosphere_density")
                    {
                        AtmosphereDensityController aCtrl = new AtmosphereDensityController(controllerDataNode);
                        allControllers.Add(aCtrl.name, aCtrl);
                        Utils.Log(String.Format("[ModuleWaterfallFX]: Loaded Atmosphere Density Controller on moduleID {0}", moduleID), LogType.Modules);
                    }
                    if (ctrlType == "custom")
                    {
                        CustomController cCtrl = new CustomController(controllerDataNode);
                        allControllers.Add(cCtrl.name, cCtrl);
                        Utils.Log(String.Format("[ModuleWaterfallFX]: Loaded Custom Controller on moduleID {0}", moduleID), LogType.Modules);
                    }
                    if (ctrlType == "rcs")
                    {
                        RCSController rcsCtrl = new RCSController(controllerDataNode);
                        allControllers.Add(rcsCtrl.name, rcsCtrl);
                        Utils.Log(String.Format("[ModuleWaterfallFX]: Loaded RCS Controller on moduleID {0}", moduleID), LogType.Modules);
                    }
                    if (ctrlType == "random")
                    {
                        RandomnessController rCtrl = new RandomnessController(controllerDataNode);
                        allControllers.Add(rCtrl.name, rCtrl);
                        Utils.Log(String.Format("[ModuleWaterfallFX]: Loaded Randomness Controller on moduleID {0}", moduleID), LogType.Modules);
                    }
                }
            }

            Utils.Log(String.Format("[ModuleWaterfallFX]: Loading Effects on moduleID {0}", moduleID), LogType.Modules);

            if (allFX == null)
            {
                allFX = new List <WaterfallEffect>();
            }
            else
            {
                if (effectNodes.Length > 0 && allFX.Count > 0 || allFX.Count > 0 && templateNodes.Length > 0)
                {
                    CleanupEffects();
                    allFX.Clear();
                }
            }

            foreach (ConfigNode fxDataNode in effectNodes)
            {
                allFX.Add(new WaterfallEffect(fxDataNode));
            }


            Utils.Log(String.Format("[ModuleWaterfallFX]: Loading Template effects on moduleID {0}", moduleID), LogType.Modules);
            foreach (ConfigNode templateNode in templateNodes)
            {
                string  templateName          = "";
                string  overrideTransformName = "";
                Vector3 scaleOffset           = Vector3.one;
                Vector3 positionOffset        = Vector3.zero;
                Vector3 rotationOffset        = Vector3.zero;


                templateNode.TryGetValue("templateName", ref templateName);
                templateNode.TryGetValue("overrideParentTransform", ref overrideTransformName);
                templateNode.TryParseVector3("scale", ref scaleOffset);
                templateNode.TryParseVector3("rotation", ref rotationOffset);
                templateNode.TryParseVector3("position", ref positionOffset);

                WaterfallEffectTemplate template = WaterfallTemplates.GetTemplate(templateName);

                foreach (WaterfallEffect fx in template.allFX)
                {
                    allFX.Add(new WaterfallEffect(fx, positionOffset, rotationOffset, scaleOffset, overrideTransformName));
                }
                Utils.Log($"[ModuleWaterfallFX]: Loaded effect template {template.templateName}", LogType.Modules);
            }

            Utils.Log($"[ModuleWaterfallFX]: Finished loading {allFX.Count} effects", LogType.Modules);

            if (initialized)
            {
                Utils.Log($"[ModuleWaterfallFX]: Reinitializing", LogType.Modules);
                ReinitializeEffects();
            }
        }