private void AddCharacters(List <UICharacter> characters, PlayerPartyData playerPartyData)
    {
        // will need to add empty slots if there are empty characters
        for (int i = 0; i < characters.Count; i++)
        {
            UICharacter character    = characters[i];
            GameObject  newCharacter = GameObject.Find("CharacterObjectPool").GetComponent <SimpleObjectPool>().GetObject();
            newCharacter.transform.SetParent(contentPanel);

            SampleCharacter sampleCharacter = newCharacter.GetComponent <SampleCharacter>();
            sampleCharacter.Setup(character, this, playerPartyData);
        }
    }
Ejemplo n.º 2
0
    private void AddCharacters(List <UICharacter> characters, MenuPartyData menuPartyData)
    {
        // will need to add empty slots if there are empty characters
        for (int i = 0; i < characters.Count; i++)
        {
            UICharacter character    = characters[i];
            GameObject  newCharacter = characterObjectPool.GetObject();
            newCharacter.transform.SetParent(contentPanel);

            SampleCharacter sampleCharacter = newCharacter.GetComponent <SampleCharacter>();
            Debug.Log(party.name);
            sampleCharacter.Setup(character, this, menuPartyData);
        }
    }
    private void AddCharacters(PlayerCharacterData[] characters)
    {
        // will need to add empty slots if there are empty characters
        for (int i = 0; i < characters.Length; i++)
        {
            int         charId       = characters[i].id;
            UICharacter character    = dataFormat.CreateUICharacter(characters[i], data);
            GameObject  newCharacter = GameObject.Find("CharacterObjectPool").GetComponent <SimpleObjectPool>().GetObject();
            newCharacter.transform.SetParent(GameObject.Find("CharacterContainer").transform);
            newCharacter.GetComponent <Button>().interactable = true;
            newCharacter.GetComponent <Button>().onClick.RemoveAllListeners();
            newCharacter.GetComponent <Button>().onClick.AddListener(delegate { SelectPartyCharacter(charId); });

            SampleCharacter sampleCharacter = newCharacter.GetComponent <SampleCharacter>();
            sampleCharacter.Setup(character, this);
        }
    }
    private void AddCharacters(PlayerCharacterData[] characters)
    {
        // will need to add empty slots if there are empty characters
        for (int i = 0; i < characters.Length; i++)
        {
            int charId = characters[i].id;
            int slot1  = -1;
            int slot2  = -1;
            int slot3  = -1;
            int slot4  = -1;

            if (data.GetPreviousPage() == 3)
            {
                PlayerPartyData party = data.GetPartyToEdit();
                slot1 = party.slotOneCharacterId;
                slot2 = party.slotTwoCharacterId;
                slot3 = party.slotThreeCharacterId;
                slot4 = party.slotFourCharacterId;
                GameObject.Find("Backbutton").GetComponent <Button>().onClick.RemoveAllListeners();
                GameObject.Find("Backbutton").GetComponent <Button>().onClick.AddListener(delegate { new SceneLoader().PartiesMenu(); });
            }
            if (charId != slot1 && charId != slot2 && charId != slot3 && charId != slot4)
            {
                UICharacter character    = dataFormat.CreateUICharacter(characters[i], data);
                GameObject  newCharacter = GameObject.Find("CharacterObjectPool").GetComponent <SimpleObjectPool>().GetObject();
                newCharacter.transform.SetParent(GameObject.Find("CharacterContainer").transform);
                newCharacter.GetComponent <Button>().interactable = true;
                newCharacter.GetComponent <Button>().onClick.RemoveAllListeners();
                if (data.GetPreviousPage() == 3)
                {
                    newCharacter.GetComponent <Button>().onClick.AddListener(delegate { SelectPartyCharacter(charId); });
                }
                else
                {
                    newCharacter.GetComponent <Button>().onClick.AddListener(delegate { EditPartyCharacter(charId); });
                }

                SampleCharacter sampleCharacter = newCharacter.GetComponent <SampleCharacter>();
                sampleCharacter.Setup(character, this);
            }
        }
    }
Ejemplo n.º 5
0
        private static void CreateAndSaveRandomBalancedSubset(string pathSavedFile, FeaturesExtractor featuresExtractor,
                                                              HashSet <string> usedExamples, HashSet <string> usedNodes, int numExtracted)
        {
            Random randomizer         = new Random();
            int    numberOfCharacters = featuresExtractor.GetTotalNumConnections();

            using (StreamWriter writer = new StreamWriter(pathSavedFile, false))
            {
                writer.WriteLine(FEATURES_NAMES);
                int numIteration = 0;

                while (numIteration < numExtracted)
                {
                    Console.WriteLine(String.Format("Processing node {0} of {1}", numIteration + 1, numExtracted));

                    // Choose 1st node
                    SampleCharacter targetCharacter = new SampleCharacter();
                    targetCharacter.Index = randomizer.Next(numberOfCharacters - 1);
                    targetCharacter.ID    = featuresExtractor.GetCharacterIdByIndex(targetCharacter.Index);
                    targetCharacter.ConnectionsAsHashSet = featuresExtractor.GetConnections(targetCharacter.ID);
                    while (targetCharacter.ConnectionsAsHashSet.Count < 1)
                    {
                        targetCharacter.Index = randomizer.Next(numberOfCharacters - 1);
                        targetCharacter.ID    = featuresExtractor.GetCharacterIdByIndex(targetCharacter.Index);
                        targetCharacter.ConnectionsAsHashSet = featuresExtractor.GetConnections(targetCharacter.ID);
                    }
                    targetCharacter.ConnectionsAsList = targetCharacter.ConnectionsAsHashSet.ToList <string>();

                    // Choose a connected node to get a positive example
                    SampleCharacter connectedCharacter = new SampleCharacter();
                    connectedCharacter.Index = randomizer.Next(targetCharacter.ConnectionsAsList.Count - 1);
                    connectedCharacter.ID    = targetCharacter.ConnectionsAsList[connectedCharacter.Index];
                    int i = 0;
                    while (((usedExamples.Contains(String.Format("{0}-{1}", targetCharacter.ID, connectedCharacter.ID))) ||
                            (usedExamples.Contains(String.Format("{1}-{0}", targetCharacter.ID, connectedCharacter.ID)))) &&
                           (i < 10))
                    {
                        connectedCharacter.Index = randomizer.Next(targetCharacter.ConnectionsAsList.Count - 1);
                        connectedCharacter.ID    = targetCharacter.ConnectionsAsList[connectedCharacter.Index];
                        ++i;
                    }
                    // Give up because the chosen node has small number of connections
                    if (i == 10)
                    {
                        continue;
                    }
                    usedExamples.Add(String.Format("{0}-{1}", targetCharacter.ID, connectedCharacter.ID));
                    usedNodes.Add(targetCharacter.ID);

                    // Choose a disconnected node to get a negative example
                    SampleCharacter disconnectedCharacter = new SampleCharacter();
                    // Not the same as the target node
                    while ((disconnectedCharacter.Index = randomizer.Next(numberOfCharacters - 1)) == targetCharacter.Index)
                    {
                    }
                    ;
                    disconnectedCharacter.ID = featuresExtractor.GetCharacterIdByIndex(disconnectedCharacter.Index);
                    // Is disconnected
                    while (targetCharacter.ConnectionsAsHashSet.Contains(disconnectedCharacter.ID))
                    {
                        while ((disconnectedCharacter.Index = randomizer.Next(numberOfCharacters - 1)) == targetCharacter.Index)
                        {
                        }
                        ;
                        disconnectedCharacter.ID = featuresExtractor.GetCharacterIdByIndex(disconnectedCharacter.Index);
                    }
                    // Did not select the same example before
                    while ((usedExamples.Contains(String.Format("{0}-{1}", targetCharacter.ID, disconnectedCharacter.ID))) ||
                           (usedExamples.Contains(String.Format("{1}-{0}", targetCharacter.ID, disconnectedCharacter.ID))))
                    {
                        while ((disconnectedCharacter.Index = randomizer.Next(numberOfCharacters - 1)) == targetCharacter.Index)
                        {
                        }
                        ;
                        disconnectedCharacter.ID = featuresExtractor.GetCharacterIdByIndex(disconnectedCharacter.Index);
                        while (targetCharacter.ConnectionsAsHashSet.Contains(disconnectedCharacter.ID))
                        {
                            while ((disconnectedCharacter.Index = randomizer.Next(numberOfCharacters - 1)) == targetCharacter.Index)
                            {
                            }
                            ;
                            disconnectedCharacter.ID = featuresExtractor.GetCharacterIdByIndex(disconnectedCharacter.Index);
                        }
                    }
                    usedExamples.Add(String.Format("{0}-{1}", targetCharacter.ID, disconnectedCharacter.ID));

                    // Write
                    writer.WriteLine(GetFeaturesString(targetCharacter.ID, connectedCharacter.ID, featuresExtractor, 1));
                    writer.WriteLine(GetFeaturesString(targetCharacter.ID, disconnectedCharacter.ID, featuresExtractor, 0));

                    ++numIteration;
                }
            }
        }