Beispiel #1
0
        public void LoadDataFromXmlCustom(XmlNode xmlRoot)
        {
            if (xmlRoot.ChildNodes.Count != 1)
            {
                Log.Error("Misconfigured ShaderParameter: " + xmlRoot.OuterXml, false);
                return;
            }
            this.name = xmlRoot.Name;
            string valstr = xmlRoot.FirstChild.Value;

            if (!valstr.NullOrEmpty() && valstr[0] == '(')
            {
                this.value = ParseHelper.FromStringVector4Adaptive(valstr);
                this.type  = ShaderParameter.Type.Vector;
            }
            else if (!valstr.NullOrEmpty() && valstr[0] == '/')
            {
                LongEventHandler.ExecuteWhenFinished(delegate
                {
                    this.valueTex = ContentFinder <Texture2D> .Get(valstr.TrimStart(new char[]
                    {
                        '/'
                    }), true);
                });
                this.type = ShaderParameter.Type.Texture;
            }
            else
            {
                this.value = Vector4.one * (float)ParseHelper.FromString(valstr, typeof(float));
                this.type  = ShaderParameter.Type.Float;
            }
        }
Beispiel #2
0
 public void Apply(Material mat)
 {
     ShaderParameter.Type type = this.type;
     if (type != ShaderParameter.Type.Float)
     {
         if (type != ShaderParameter.Type.Vector)
         {
             if (type == ShaderParameter.Type.Texture)
             {
                 if (this.valueTex == null)
                 {
                     Log.ErrorOnce(string.Format("Texture for {0} is not yet loaded; file may be invalid, or main thread may not have loaded it yet", this.name), 27929440, false);
                 }
                 mat.SetTexture(this.name, this.valueTex);
             }
         }
         else
         {
             mat.SetVector(this.name, this.value);
         }
     }
     else
     {
         mat.SetFloat(this.name, this.value.x);
     }
 }