예제 #1
0
        private static ModelInfo LoadModel(XElement singleModel)
        {
            try
            {
                ModelInfo  model = new ModelInfo();
                Vector3    v3Out;
                Quaternion qOut;
                int        iOut;

                v3Out          = Util.ConvertStringToVector3(singleModel.Element("Position").Value.ToString());
                model.position = v3Out;

                qOut           = Util.ConvertStringToQuaternion(singleModel.Element("Rotation").Value.ToString());
                model.rotation = qOut;

                v3Out            = Util.ConvertStringToVector3(singleModel.Element("LocalScale").Value.ToString());
                model.localScale = v3Out;

                int.TryParse(singleModel.Element("ModelType").Value.ToString(), out iOut);
                model.modelType = (ModelType)iOut;

                model.menuFileName  = singleModel.Element("MenuFileName").Value.ToString();
                model.modelName     = singleModel.Element("ModelName").Value.ToString();
                model.modelIconName = singleModel.Element("ModelIconName").Value.ToString();

                return(model);
            }
            catch (Exception e)
            {
                Debug.LogError(e);
            }
            return(null);
        }
예제 #2
0
        private static void LoadCamera(XDocument xml)
        {
            try
            {
                XElement cameraElem = xml.Element("Preset").Element("Camera");

                if (cameraElem == null)
                {
                    return;
                }

                GameObject cameraObj = GameMain.Instance.MainCamera.gameObject;
                float      fOut;
                Vector3    v3Out;

                v3Out = Util.ConvertStringToVector3(cameraElem.Element("Position").Value.ToString());
                GameMain.Instance.MainCamera.SetTargetPos(v3Out, true);

                v3Out = Util.ConvertStringToVector3(cameraElem.Element("Rotation").Value.ToString());
                cameraObj.transform.eulerAngles = v3Out;

                float.TryParse(cameraElem.Element("Distance").Value.ToString(), out fOut);
                GameMain.Instance.MainCamera.SetDistance(fOut, true);

                float.TryParse(cameraElem.Element("FieldOfView").Value.ToString(), out fOut);
                cameraObj.GetComponent <Camera>().fieldOfView = fOut;
            }
            catch (Exception e)
            {
                Debug.LogError(e);
            }
        }
예제 #3
0
        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);
        }
예제 #4
0
        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());
            }
        }