private static LightInfo LoadLight(XElement singleLight) { try { LightInfo light = new LightInfo(); Color cOut; float fOut; Vector3 v3Out; v3Out = Util.ConvertStringToVector3(singleLight.Element("Position").Value.ToString()); light.position = v3Out; v3Out = Util.ConvertStringToVector3(singleLight.Element("EulerAngles").Value.ToString()); light.eulerAngles = v3Out; cOut = Util.ConvertStringToColor32(singleLight.Element("Color").Value.ToString()); light.color = cOut; light.type = (LightType)Enum.Parse(typeof(LightType), singleLight.Element("Type").Value.ToString()); float.TryParse(singleLight.Element("Intensity").Value.ToString(), out fOut); light.intensity = fOut; float.TryParse(singleLight.Element("Range").Value.ToString(), out fOut); light.range = fOut; float.TryParse(singleLight.Element("SpotAngle").Value.ToString(), out fOut); light.spotAngle = fOut; light.enabled = true; return(light); } catch (Exception e) { Debug.LogError(e); } return(null); }
public static void LoadDef(XElement allEffects, Type effectDefType, Type enabled_effect) { try { FieldInfo effectField = Util.GetFieldsSpecifyType(effectDefType, enabled_effect)[0]; var effect = effectField.GetValue(null); XElement def = allEffects.Elements().Where(e => e.Name.ToString() == effectDefType.Name).FirstOrDefault(); PropertyInfo enabledProperty; if (typeof(Bloom) == enabled_effect) { enabledProperty = effectDefType.GetProperty("enabledInPane"); } else { enabledProperty = enabled_effect.GetProperty("enabled"); } if (def == null) { // Effect was not enabled in the preset. Disable it. if (typeof(Bloom) == enabled_effect) { enabledProperty.SetValue(null, false, null); // MethodInfo mi = effectDefType.GetMethod("Reset"); // if (mi != null) // mi.Invoke(null, null); } else { enabledProperty.SetValue(effect, false, null); } } else { if (typeof(BloomDef) == enabled_effect) { enabledProperty.SetValue(null, true, null); } else { enabledProperty.SetValue(effect, true, null); } foreach (XElement propElem in def.Elements()) { try { string propName = propElem.Name.ToString(); FieldInfo field = enabled_effect.GetField(propName); if (field == null) { Debug.LogError("Failed to load field! " + propName); continue; } Type fieldType = field.FieldType; int iTmp; float fTmp; bool bTmp; float.TryParse(propElem.Value, out fTmp); if (field != null) { if (typeof(Bloom) == enabled_effect && field.Name == "bloomIntensity") { if (int.TryParse(propElem.Value, out iTmp)) { GameMain.Instance.CMSystem.BloomValue = iTmp; } } else if (fieldType == typeof(Texture) || fieldType == typeof(Texture2D)) { string fullPath = ConstantValues.BaseConfigDir + @"\" + propElem.Value; if (!File.Exists(fullPath)) { fullPath = ConstantValues.BaseConfigDirSybaris + @"\" + propElem.Value; } if (File.Exists(fullPath)) { byte[] bytes = File.ReadAllBytes(fullPath); Texture2D texture = new Texture2D(4, 4); texture.LoadImage(bytes); // Make sure LUT texture is marked as updated if (effectDefType == typeof(LookupFilterDef)) { PropertyInfo prop = enabled_effect.GetProperty("needsUpdate"); prop.SetValue(effect, true, null); } if (fieldType == typeof(Texture2D)) { field.SetValue(effect, texture); } else { field.SetValue(effect, (Texture)texture); } PropertyInfo textureFilenameProperty = effectDefType.GetProperty(field.Name + "File"); textureFilenameProperty.SetValue(null, fullPath, null); } } else if (fieldType == typeof(int) || fieldType.IsEnum) { if (int.TryParse(propElem.Value, out iTmp)) { field.SetValue(effect, iTmp); } } else if (fieldType == typeof(float)) { if (float.TryParse(propElem.Value, out fTmp)) { field.SetValue(effect, fTmp); } } else if (fieldType == typeof(bool)) { if (bool.TryParse(propElem.Value, out bTmp)) { field.SetValue(effect, bTmp); } } else if (fieldType == typeof(Vector3)) { Vector3 v3 = Util.ConvertStringToVector3(propElem.Value); field.SetValue(effect, v3); } else if (fieldType == typeof(Color) || fieldType == typeof(Color32)) { Color color = Util.ConvertStringToColor32(propElem.Value); field.SetValue(effect, color); } else if (fieldType == typeof(AnimationCurve)) { AnimationCurve curve = Util.ConvertStringToAnimationCurve(propElem.Value); field.SetValue(effect, curve); } else if (fieldType == typeof(Transform)) { Vector3 v3 = Util.ConvertStringToVector3(propElem.Value); // FIXME: Loading maid manager transforms bugs out maid heads. if (enabled_effect == typeof(SunShafts)) { if (field.GetValue(effect) != null) { ((Transform)field.GetValue(effect)).position = v3; } } } } } catch (Exception e) { Debug.LogError("Failed to load field " + propElem.Name.ToString() + ": " + e); } } } // MethodInfo mi = effectDefType.GetMethod("InitMemberByInstance"); // if (mi != null) // mi.Invoke(null, new object[] { effect }); // else // Debug.LogWarning("Couldn't init " + effectDefType + "!!!"); // MethodInfo mi = effectDefType.GetMethod("Reset"); // if (mi != null) // mi.Invoke(null, null); // else // Debug.LogWarning("Couldn't reset " + effectDefType + "!!!"); } catch (Exception e) { Debug.LogError("Load error: " + e.ToString()); } }