Exemplo n.º 1
0
        public void Load(ConfigNode node)
        {
            allFX    = new List <WaterfallEffect>();
            position = Vector3.one;
            rotation = Vector3.zero;
            scale    = Vector3.zero;


            node.TryGetValue("templateName", ref templateName);
            node.TryGetValue("overrideParentTransform", ref overrideParentTransform);
            node.TryParseVector3("position", ref position);
            node.TryParseVector3("rotation", ref rotation);
            node.TryParseVector3("scale", ref scale);

            template = WaterfallTemplates.GetTemplate(templateName);

            foreach (WaterfallEffect fx in template.allFX)
            {
                allFX.Add(new WaterfallEffect(fx, this));
            }
        }
Exemplo n.º 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();
            }
        }