Exemple #1
0
        private TankPreset GetPresetFromName(string presetName)
        {
            TankPreset result = null;

            Singleton.Manager <ManSpawn> .inst.TankPresets.TryGetValue(presetName.ToLower(), out result);

            return(result);
        }
Exemple #2
0
        public void SpawnSylverEnemy(string presetName)
        {
            TankPreset presetFromName = this.GetPresetFromName(presetName);

            if (presetFromName != null)
            {
                Singleton.Manager <ManSpawn> .inst.TestSpawnTank(presetFromName.m_TechData, ManSpawn.NewEnemyTeam, false);

                return;
            }
            Console.WriteLine("ManSpawn.TestSpawnFriendlyTech - no preset found with name " + presetName);
        }
                static void Postfix(PopulationTable __instance)         // Called after
                {
                    foreach (var thing in __instance.m_FolderTechs)     //a system operator that does a thing for each of the specified things in the parenthesis
                    {
                        Debug.Log(thing.m_FolderName);                  // what the foreach does
                    }
                    if (Directory.Exists(XMLPath))                      //tests to see if the XMLpath directory exists
                    {
                        //does magical loading stuff below
                        var directory = new DirectoryInfo(XMLPath);                                                                      // Create a new DirectoryInfo based off of XML path that can be used for later purposes
                        var files     = directory.GetFiles();                                                                            // Get all the files from directory and return an array
                                                                                                                                         //A simpler way is to one-line it, such as `foreach(var file in new DirectoryInfo(XMLPath).GetAllFiles())`

                        foreach (FileInfo file in files)                                                                                 // Iterate through the array; Use every object in the array one after the other until all are used
                        {
                            var tech = ExundXMLHandler.LoadXMLAsTech(file.FullName, Vector3.down * 1000f, Quaternion.Euler(0f, 0f, 0f)); //makes a new variable called "tech" derived from the TerraTech "Tank" class and gives it the value deserialized from the xml info,henmovest

                            var tankPreset = TankPreset.CreateInstance();
                            tankPreset.SaveTank(tech, false, false);

                            __instance.m_FolderTechs[0].m_Presets.Add(tankPreset);

                            tech.visible.RemoveFromGame();

                            try
                            {
                                UnityEngine.GameObject.DestroyImmediate(tech.gameObject);
                            }
                            catch
                            {
                                Debug.Log("Could not remove XML GameObject!");
                            }
                        }
                    }
                    else
                    {
                        Debug.Log("XML folder does not exist! " + XMLPath);
                    }
                }
        private void DoWindow(int id)
        {
            scrollPos = GUILayout.BeginScrollView(scrollPos);
            foreach (var image in Directory.GetFiles(Path.GetFullPath(ColorBlockMod.TechArtFolder), "*.png"))
            {
                if (GUILayout.Button(Path.GetFileNameWithoutExtension(image), new GUIStyle(GUI.skin.button)
                {
                    richText = true, alignment = TextAnchor.MiddleLeft
                }))
                {
                    path = image;
                }
            }
            GUILayout.EndScrollView();
            GUILayout.TextField(path);

            useModBlock = GUILayout.Toggle(useModBlock, "Use mod block");
            if (!useModBlock)
            {
                useFlesh = GUILayout.Toggle(useFlesh, "Use flesh blocks");
            }
            if (GUILayout.Button("Load"))
            {
                try
                {
                    Texture2D image = new Texture2D(0, 0);
                    image.LoadImage(File.ReadAllBytes(path));

                    if (image.width <= 64 && image.height <= 64)
                    {
                        blocks = new List <Temp>();
                        Vector3    position = Singleton.playerTank.trans.position;
                        Quaternion rotation = Singleton.playerTank.trans.rotation;

                        TankBlock root = Singleton.Manager <ManSpawn> .inst.SpawnBlock(BlockTypes.GSOCockpit_111, Vector3.zero, rotation);

                        root.trans.localPosition = Vector3.zero;

                        var spawnParams = new ManSpawn.TankSpawnParams()
                        {
                            forceSpawn = true,
                            grounded   = true,
                            position   = position,
                            rotation   = rotation,
                            placement  = ManSpawn.TankSpawnParams.Placement.PlacedAtPosition,
                            techData   = new TechData()
                            {
                                Name           = Path.GetFileNameWithoutExtension(path),
                                m_CreationData = new TechData.CreationData(),
                                m_BlockSpecs   = new List <TankPreset.BlockSpec>()
                            }
                        };

                        spawnParams.techData.m_BlockSpecs.Add(TankPreset.GetBlockSpec(root, false));

                        for (int x = 0; x < image.width; x++)
                        {
                            for (int y = 0; y < image.height; y++)
                            {
                                if (x == 0 && y == 0)
                                {
                                    continue;
                                }
                                var c    = image.GetPixel(x, y);
                                var type = (BlockTypes)7000;
                                if (!useModBlock)
                                {
                                    var sw = float.MaxValue;
                                    var cc = Color.white;
                                    foreach (var color in color_blocks.Keys.ToList())
                                    {
                                        if (!useFlesh && color_blocks[color].ToString().Contains("Flesh"))
                                        {
                                            continue;
                                        }
                                        var w = (float)Math.Sqrt(Math.Pow(c.r - color.r, 2) + Math.Pow(c.g - color.g, 2) + Math.Pow(c.b - color.b, 2));
                                        if (w < sw)
                                        {
                                            sw = w;
                                            cc = color;
                                        }
                                    }
                                    type = color_blocks[cc];
                                }

                                TankBlock b = Singleton.Manager <ManSpawn> .inst.SpawnBlock(type, new Vector3(x, y, 0), rotation);

                                b.trans.localPosition = new Vector3(x, y, 0);
                                if (useModBlock)
                                {
                                    b.GetComponent <ModuleColor>().Color = c;
                                }
                                spawnParams.techData.m_BlockSpecs.Add(TankPreset.GetBlockSpec(b, false));
                                b.RemoveFromNetworkedGame();
                            }
                        }
                        tech = ManSpawn.inst.SpawnUnmanagedTank(spawnParams);
                        Tank playerTank = Singleton.playerTank;
                        Singleton.Manager <ManTechs> .inst.SetPlayerTank(null, true);

                        playerTank.RemoveFromNetworkedGame();

                        Singleton.Manager <ManTechs> .inst.SetPlayerTank(tech, true);
                    }
                }
                catch (Exception e) { Console.WriteLine(e); }
                visible = false;
            }
            if (GUILayout.Button("Cancel"))
            {
                visible = false;
            }
            GUI.DragWindow();
        }