예제 #1
0
    public void InvalidateUselessButtons()
    {
        List <Colour> foundColours = new List <Colour> ();

        for (int i = 0; i < research.Count; i++)
        {
            Research u = research[i];
            if (u.func != "UnlockModule")
            {
                continue;
            }

            bool       found     = false;
            GameObject reqModule = unlockableModules[int.Parse(u.meta)];
            for (int j = 0; j < PurchaseMenu.assemblies.Length; j++)
            {
                //Debug.Log (PurchaseMenu.assemblies[i].assemblyName);

                for (int a = 0; a < PurchaseMenu.assemblies[j].parts.Count; a++)
                {
                    Assembly.Part part = PurchaseMenu.assemblies[j].parts[a];
                    if (PurchaseMenu.cur.GetModulePrefab(part.type) == reqModule)
                    {
                        found = true;
                    }
                }
            }

            if (!found)
            {
                IntermediateButton(u);
            }
        }

        // F**k it, Imma use foreach now.
        foreach (Assembly ass in PurchaseMenu.assemblies)
        {
            foreach (Assembly.Part part in ass.parts)
            {
                Module m = PurchaseMenu.cur.GetModulePrefab(part.type).GetComponent <Module> ();

                if (!foundColours.Contains(m.colour))
                {
                    foundColours.Add(m.colour);
                }
            }
        }

        for (int i = 0; i < research.Count; i++)
        {
            if (!foundColours.Contains(research[i].colour))
            {
                IntermediateButton(research[i]);
            }
        }
    }
예제 #2
0
    public static void GetSpriteData(Assembly assembly, out Texture2D[] sprites, out Vector3[] positions)
    {
        List <Texture2D> spr = new List <Texture2D> ();
        List <Vector3>   pos = new List <Vector3> ();

        for (int i = 0; i < assembly.parts.Count; i++)
        {
            Assembly.Part part = assembly.parts[i];
            spr.Add(PurchaseMenu.cur.GetModulePrefab(part.type)
                    .transform.Find("Sprite").GetComponent <SpriteRenderer>().sprite.texture);

            pos.Add(new Vector3(part.x, part.y));
        }

        sprites   = spr.ToArray();
        positions = pos.ToArray();
    }
예제 #3
0
    public GameObject LoadAssembly(Assembly assembly, bool directToWorld = false)
    {
        GameObject modulePrefab = null;
        GameObject rootModule   = null;
        Module     module       = null;
        int        totalCost    = 0;

        // Instantiate, give position and indicies.
        for (int i = 0; i < assembly.parts.Count; i++)
        {
            Assembly.Part part = assembly.parts[i];

            modulePrefab = PurchaseMenu.cur.GetModulePrefab(part.type);
            if (modulePrefab)
            {
                moduleObjects.Add((GameObject)Instantiate(modulePrefab, Vector3.zero, Quaternion.identity));
                //moduleObjects[moduleObjects.Count - 1].SetActive (false);
                moduleObjects[moduleObjects.Count - 1].transform.parent = transform;
                module         = moduleObjects[moduleObjects.Count - 1].GetComponent <Module>();
                module.enabled = false;
                totalCost     += module.moduleCost;
            }
            else
            {
                Debug.LogWarning("Tried to load a non-existing.");
                return(null);
            }

            if (modulePrefab)
            {
                if (part.isRoot)
                {
                    rootModule         = module.gameObject;
                    module.moduleIndex = 1;

                    module.assemblyName = assembly.assemblyName;
                    module.assemblyDesc = assembly.assemblyDesc;
                    module.assembly     = assembly;

                    HoverContextElement el = module.gameObject.AddComponent <HoverContextElement> ();
                    el.isWorldElement = true;
                }

                module.moduleIndex = part.index;
                module.parentIndex = part.parentIndex;

                module.transform.localPosition = new Vector3(part.x, part.y);
                module.transform.eulerAngles   = new Vector3(0, 0, part.angle);

                //rootModule.GetComponent<Module> ().modules.Add (module);
            }
        }

        // Set parents
        foreach (GameObject obj in moduleObjects)
        {
            Module m = obj.GetComponent <Module>();
            if (m.parentIndex != 0)
            {
                m.transform.parent   = FindModuleFromIndex(m.parentIndex).transform;
                m.transform.position = new Vector3(m.transform.position.x,
                                                   m.transform.position.y,
                                                   m.transform.parent.position.z - 1);
            }
            rootModule.GetComponent <Module> ().modules.Add(m);
        }

        // Activate gameObject, but disable module components
        if (!directToWorld)
        {
            PlayerInput.cur.SelectPurchaseable(rootModule, true);
            PlayerInput.cur.SetPurchaseableFromSceneObject(PlayerInput.cur.placementParent.GetChild(0).gameObject);
            PlayerInput.cur.placementParent.GetChild(0).transform.eulerAngles -= new Vector3(0, 0, 90);
            PlayerInput.cur.currentCost = totalCost;
        }
        else
        {
            foreach (GameObject obj in moduleObjects)
            {
                obj.GetComponent <Module> ().enabled = true;
            }
        }

        return(rootModule);
    }
예제 #4
0
    public static void ConvertLegacyAssemblyFiles()
    {
        string[] files = Directory.GetFiles(Game.MODULE_ASSEMBLY_SAVE_DIRECTORY, "*" + Module.MODULE_FILE_EXTENSION);

        for (int i = 0; i < files.Length; i++)
        {
            string[] contents = GetContents(files[i]);

            if (!contents[0].Contains("PROJECT VIRUS MODULE ASSEMBLY FILE, EDIT WITH CAUTION"))
            {
                continue;
            }

            Assembly newAssembly = new Assembly();

            Assembly.Part part = null;

            for (int j = 0; j < contents.Length; j++)
            {
                if (contents[j].Substring(0, 5) == "name:")
                {
                    newAssembly.assemblyName = contents[j].Substring(5);
                }

                if (contents[j].Substring(0, 5) == "type:")
                {
                    part      = new Assembly.Part();
                    part.type = contents[j].Substring(5);
                }

                if (part != null)
                {
                    if (contents[j] == "\troot")
                    {
                        part.isRoot = true;
                        part.index  = 1;
                    }

                    if (contents[j].Substring(0, 5) == "\tindx")
                    {
                        part.index = int.Parse(contents[j].Substring(6));
                    }

                    if (contents[j].Substring(0, 5) == "\tpidx")
                    {
                        part.parentIndex = int.Parse(contents[j].Substring(6));
                    }

                    if (contents[j].Substring(0, 5) == "\tposx")
                    {
                        part.x = float.Parse(contents[j].Substring(6));
                        part.y = float.Parse(contents[j + 1].Substring(6));
                    }

                    if (contents[j].Substring(0, 5) == "\trotz")
                    {
                        part.angle = float.Parse(contents[j].Substring(6));
                        newAssembly.parts.Add(part);
                    }
                }
            }

            Assembly.SaveToFile(newAssembly.assemblyName + " (NEW)", newAssembly);
        }
    }