예제 #1
0
 // Apply event
 void IParserEventSubscriber.Apply(ConfigNode node)
 {
     if (CustomMaterial || !Mod.material)
     {
         return;
     }
     if (Mod.material.shader == new NormalDiffuse().shader)
     {
         CustomMaterial = new NormalDiffuseLoader(Mod.material);
     }
     else if (Mod.material.shader == new NormalBumped().shader)
     {
         CustomMaterial = new NormalBumpedLoader(Mod.material);
     }
     else if (Mod.material.shader == new NormalDiffuseDetail().shader)
     {
         CustomMaterial = new NormalDiffuseDetailLoader(Mod.material);
     }
     else if (Mod.material.shader == new DiffuseWrapLoader().shader)
     {
         CustomMaterial = new DiffuseWrapLoader(Mod.material);
     }
     else if (Mod.material.shader == new AlphaTestDiffuse().shader)
     {
         CustomMaterial = new AlphaTestDiffuseLoader(Mod.material);
     }
     else if (Mod.material.shader == new AerialTransCutout().shader)
     {
         CustomMaterial = new AerialTransCutoutLoader(Mod.material);
     }
 }
예제 #2
0
            // Runtime constructor
            public LandClassScatterLoader(PQSLandControl.LandClassScatter value)
            {
                Value = value;

                if (CustomMaterial)
                {
                    if (NormalDiffuse.UsesSameShader(CustomMaterial))
                    {
                        CustomMaterial = new NormalDiffuseLoader(CustomMaterial);
                    }
                    else if (NormalBumped.UsesSameShader(CustomMaterial))
                    {
                        CustomMaterial = new NormalBumpedLoader(CustomMaterial);
                    }
                    else if (NormalDiffuseDetail.UsesSameShader(CustomMaterial))
                    {
                        CustomMaterial = new NormalDiffuseDetailLoader(CustomMaterial);
                    }
                    else if (DiffuseWrap.UsesSameShader(CustomMaterial))
                    {
                        CustomMaterial = new DiffuseWrapLoader(CustomMaterial);
                    }
                    else if (AlphaTestDiffuse.UsesSameShader(CustomMaterial))
                    {
                        CustomMaterial = new AlphaTestDiffuseLoader(CustomMaterial);
                    }
                    else if (AerialTransCutout.UsesSameShader(CustomMaterial))
                    {
                        CustomMaterial = new AerialTransCutoutLoader(CustomMaterial);
                    }
                    else if (Standard.UsesSameShader(CustomMaterial))
                    {
                        CustomMaterial = new StandardLoader(CustomMaterial);
                    }
                }

                // Get the Scatter-Parent
                GameObject scatterParent = typeof(PQSLandControl.LandClassScatter)
                                           .GetFields(BindingFlags.Instance | BindingFlags.NonPublic)
                                           .FirstOrDefault(f => f.FieldType == typeof(GameObject))?.GetValue(Value) as GameObject;

                // If the GameObject is null, create one
                if (scatterParent == null)
                {
                    scatterParent = new GameObject("Scatter");
                    scatterParent.transform.parent = Utility.Deactivator;
                }

                // Add the scatter module
                Scatter         = scatterParent.AddOrGetComponent <ModularScatter>();
                Scatter.scatter = Value;

                // Create the Component callback
                Components = new CallbackList <ComponentLoader <ModularScatter> >(e =>
                {
                    Scatter.Components = Components.Select(c => c.Value).ToList();
                });

                // Load existing Modules
                foreach (IComponent <ModularScatter> component in Scatter.Components)
                {
                    Type componentType       = component.GetType();
                    Type componentLoaderType = typeof(ComponentLoader <>).MakeGenericType(Value.GetType(), componentType);
                    foreach (Type loaderType in Parser.ModTypes)
                    {
                        if (!componentLoaderType.IsAssignableFrom(loaderType))
                        {
                            continue;
                        }

                        // We found our loader type
                        ComponentLoader <ModularScatter> loader = (ComponentLoader <ModularScatter>)Activator.CreateInstance(loaderType);
                        loader.Create(component);
                        Components.Add(loader);
                    }
                }
            }