コード例 #1
0
 public void Init(XElement xml, HandleScript handle)
 {
     transform        = handle.grenade.transform.Find((string)xml.Attribute("path") ?? "HandleTransform");
     originalRotation = transform.localRotation;
     axis             = GrenadesMod.ParseV3((string)xml.Attribute("axis") ?? "1,0,0") ?? Vector3.right;
     factor           = (float?)xml.Attribute("factor") ?? 1f;
 }
コード例 #2
0
ファイル: ExplosionModule.cs プロジェクト: WNP78/Grenades
            public Transformation(XElement xml, ExplosionModule module) : base(xml, module)
            {
                this.transform = module.grenade.transform.Find((string)xml.Attribute("path") ?? "");
                if (this.transform == null)
                {
                    return;
                }

                this.position = GrenadesMod.ParseV3((string)xml.Attribute("position")) ?? transform.localPosition;
                this.rotation = Quaternion.Euler(GrenadesMod.ParseV3((string)xml.Attribute("rotation")) ?? transform.localEulerAngles);
                this.scale    = GrenadesMod.ParseV3((string)xml.Attribute("scale")) ?? transform.localScale;
                this.duration = (float?)xml.Attribute("duration") ?? 0f;

                this.originalPos   = this.transform.localPosition;
                this.originalRot   = this.transform.localRotation;
                this.originalScale = this.transform.localScale;
            }
コード例 #3
0
ファイル: Mod.cs プロジェクト: WNP78/Grenades
        public override void OnApplicationStart()
        {
            Instance = this;
            base.OnApplicationStart();
            ClassInjector.RegisterTypeInIl2Cpp <Grenade>();
            ClassInjector.RegisterTypeInIl2Cpp <PinScript>();
            ClassInjector.RegisterTypeInIl2Cpp <HandleScript>();

            var folder = new DirectoryInfo(Path.Combine(Path.GetDirectoryName(Application.dataPath), "UserData", "Grenades"));

            if (!folder.Exists)
            {
                folder.Create();
            }
            else
            {
                foreach (var file in folder.EnumerateFiles("*.grenade"))
                {
                    try
                    {
                        var bundle = AssetBundle.LoadFromFile(file.FullName);
                        bundle.hideFlags = HideFlags.DontUnloadUnusedAsset;
                        TextAsset text = bundle.LoadAsset <TextAsset>("Grenades.xml");
                        var       xml  = XDocument.Parse(text.text);

                        foreach (var grenadeXml in xml.Root.Elements("Grenade"))
                        {
                            var prefab = bundle.LoadAsset <GameObject>((string)grenadeXml.Attribute("prefab"));
                            prefab.hideFlags = HideFlags.DontUnloadUnusedAsset;
                            Shaders.ReplaceDummyShaders(prefab);
                            var guid = Guid.NewGuid();
                            prefab.name            = guidPrefix + guid.ToString();
                            this.definitions[guid] = grenadeXml;
                            var g = prefab.AddComponent <Grenade>();
                            SpawnMenu.AddItem(prefab,
                                              (string)grenadeXml.Attribute("name") ?? "[Grenade]",
                                              (int?)grenadeXml.Attribute("pool") ?? 4,
                                              (CategoryFilters)Enum.Parse(typeof(CategoryFilters), (string)grenadeXml.Attribute("category") ?? "GADGETS", true));
                        }
                    }
                    catch (Exception e)
                    {
                        Log.LogError($"Failed when loading grenade bundle: {file.Name}\n{e.Message}\n{e.StackTrace}");
                    }
                }
            }

            CustomMapIntegration.Init();
            if (Environment.GetCommandLineArgs().Contains("--grenades.debug"))
            {
                void ExportXml()
                {
                    foreach (var def in Instance.definitions.Values)
                    {
                        var file = Path.Combine(folder.FullName, $"exported_{(string)def.Attribute("name") ?? "noname"}.xml");
                        def.Save(file);
                    }
                }

                var i = Interfaces.AddNewInterface("Grenades Debug", Color.green);
                i.CreateFunctionElement("Output all xml", Color.green, null, null, ExportXml);
            }
        }