Ejemplo n.º 1
0
    // load the all slot data from cache file.
    private void InitDataFromFile()
    {
        CharacterMenuData serializableData = LoadAllDeckDataFromFile();

        allPlaySlotObjectInAllDeck = new List <List <GameObject> > ();
        allRestSlotObjectInAllDeck = new List <List <GameObject> > ();

        for (int i = 0; i < MaxDeckNumber; i++)
        {
            CharacterDeckData   deckData = serializableData.allDeckData [i];
            CharacterSlotData[] allPlaySlotDataInOneDeck = deckData.allPlaySlotData;
            CharacterSlotData[] allRestSlotDataInOneDeck = deckData.allRestSlotData;

            //Debug.Log (allPlaySlotDataInOneDeck [0].ToString());

            List <GameObject> allPlayObjects = new List <GameObject> ();
            List <GameObject> allRestObjects = new List <GameObject> ();

            for (int j = 0; j < MaxPlaySlotNumber; j++)
            {
                GameObject newSlotObject                    = characterSlotPool.GetObject();
                CharacterSlotDataController ctl             = newSlotObject.GetComponent <CharacterSlotDataController> ();
                CharacterSlotData           newDataInObject = ctl.characterSlotData;
                newDataInObject.isEmpty     = allPlaySlotDataInOneDeck [j].isEmpty;
                newDataInObject.characterId = allPlaySlotDataInOneDeck [j].characterId;
                newDataInObject.lvl         = allPlaySlotDataInOneDeck [j].lvl;
                newDataInObject.exp         = allPlaySlotDataInOneDeck [j].exp;
                newDataInObject.weight      = allPlaySlotDataInOneDeck [j].weight;
                newDataInObject.imagePath   = allPlaySlotDataInOneDeck [j].imagePath;
                allPlayObjects.Add(newSlotObject);
            }

            for (int j = 0; j < allRestSlotDataInOneDeck.Length; j++)
            {
                GameObject newSlotObject                    = characterSlotPool.GetObject();
                CharacterSlotDataController ctl             = newSlotObject.GetComponent <CharacterSlotDataController> ();
                CharacterSlotData           newDataInObject = ctl.characterSlotData;
                newDataInObject.isEmpty     = allRestSlotDataInOneDeck [j].isEmpty;
                newDataInObject.characterId = allRestSlotDataInOneDeck [j].characterId;
                newDataInObject.lvl         = allRestSlotDataInOneDeck [j].lvl;
                newDataInObject.exp         = allRestSlotDataInOneDeck [j].exp;
                newDataInObject.weight      = allRestSlotDataInOneDeck [j].weight;
                newDataInObject.imagePath   = allRestSlotDataInOneDeck [j].imagePath;
                allRestObjects.Add(newSlotObject);
            }

            allPlaySlotObjectInAllDeck.Add(allPlayObjects);
            allRestSlotObjectInAllDeck.Add(allRestObjects);
        }
    }
Ejemplo n.º 2
0
    // create and return an empty slot object
    private GameObject CreateNewEmptySlot()
    {
        GameObject newSlotObject                    = characterSlotPool.GetObject();
        CharacterSlotDataController ctl             = newSlotObject.GetComponent <CharacterSlotDataController> ();
        CharacterSlotData           newDataInObject = ctl.characterSlotData;

        newDataInObject.isEmpty     = true;
        newDataInObject.characterId = -1;
        newDataInObject.lvl         = -1;
        newDataInObject.exp         = -1;
        newDataInObject.weight      = -1;
        newDataInObject.imagePath   = "";
        return(newSlotObject);
    }
Ejemplo n.º 3
0
    // make all slot object to format with serializable data
    private CharacterMenuData AllSlotObjectDataToSerializableData()
    {
        CharacterMenuData result = new CharacterMenuData();

        result.allDeckData = new CharacterDeckData[MaxDeckNumber];
        for (int i = 0; i < MaxDeckNumber; i++)
        {
            List <GameObject> allPlaySlotInOneDeck = allPlaySlotObjectInAllDeck [i];
            List <GameObject> allRestSlotInOneDeck = allRestSlotObjectInAllDeck [i];
            result.allDeckData [i] = new CharacterDeckData();
            result.allDeckData[i].allPlaySlotData = new CharacterSlotData[MaxPlaySlotNumber];
            result.allDeckData[i].allRestSlotData = new CharacterSlotData[allRestSlotInOneDeck.Count];

            for (int j = 0; j < MaxPlaySlotNumber; j++)
            {
                CharacterSlotDataController ctl            = allPlaySlotInOneDeck [j].GetComponent <CharacterSlotDataController> ();
                CharacterSlotData           dataInObject   = ctl.characterSlotData;
                CharacterSlotData           resultSlotData = new CharacterSlotData();
                resultSlotData.isEmpty     = dataInObject.isEmpty;
                resultSlotData.characterId = dataInObject.characterId;
                resultSlotData.lvl         = dataInObject.lvl;
                resultSlotData.exp         = dataInObject.exp;
                resultSlotData.weight      = dataInObject.weight;
                resultSlotData.imagePath   = dataInObject.imagePath;
                result.allDeckData [i].allPlaySlotData [j] = resultSlotData;
            }

            for (int j = 0; j < allRestSlotInOneDeck.Count; j++)
            {
                CharacterSlotDataController ctl            = allRestSlotInOneDeck [j].GetComponent <CharacterSlotDataController> ();
                CharacterSlotData           dataInObject   = ctl.characterSlotData;
                CharacterSlotData           resultSlotData = new CharacterSlotData();
                resultSlotData.isEmpty     = dataInObject.isEmpty;
                resultSlotData.characterId = dataInObject.characterId;
                resultSlotData.lvl         = dataInObject.lvl;
                resultSlotData.exp         = dataInObject.exp;
                resultSlotData.weight      = dataInObject.weight;
                resultSlotData.imagePath   = dataInObject.imagePath;
                result.allDeckData [i].allRestSlotData [j] = resultSlotData;
            }
        }
        return(result);
    }
Ejemplo n.º 4
0
    // display the specific deck data to the character menu scene
    private void DisplayDeck(int deckIndex)
    {
        List <GameObject> playSlotsObject = allPlaySlotObjectInAllDeck [deckIndex];
        List <GameObject> restSlotsObject = allRestSlotObjectInAllDeck [deckIndex];

        for (int i = 0; i < MaxDeckNumber; i++)
        {
            CharacterSlotDataController playSlotCtl = playSlotsObject [i].GetComponent <CharacterSlotDataController> ();
            playSlotCtl.DisplayWithCharacterSlotData();

            playSlotsObject [i].transform.SetParent(playCharacterSlotLayoutPanel.transform);
        }
        for (int i = 0; i < restSlotsObject.Count; i++)
        {
            CharacterSlotDataController restSlotCtl = restSlotsObject [i].GetComponent <CharacterSlotDataController> ();
            restSlotCtl.DisplayWithCharacterSlotData();
            restSlotsObject [i].transform.SetParent(restCharacterSlotLayoutPanel.transform);
        }
        CheckOverWeight();
    }
Ejemplo n.º 5
0
    // record selected play-slot's index , it will unselected other play-slot.
    public void SetSelectedPlaySlotIndex(int newSelectedSlotIndex)
    {
        if (newSelectedSlotIndex == selectedPlaySlotIndex)
        {
            return;
        }
        // record previous selected slot index, if previous index = -1. means no previous selected slot.
        int previousIndex = selectedPlaySlotIndex;

        selectedPlaySlotIndex = newSelectedSlotIndex;

        // if previous selected slot is exist.
        if (previousIndex != -1)
        {
            // unselected previous selected slot.
            GameObject previousSelectedSlotObject       = allPlaySlotObjectInAllDeck [currentDeckIndex] [previousIndex];
            CharacterSlotDataController previousSlotCtl = previousSelectedSlotObject.GetComponent <CharacterSlotDataController> ();
            if (previousSlotCtl.isSelected == true)
            {
                previousSlotCtl.SetUnSelected();
            }
        }

        // is has a slot be selected.
        if (selectedPlaySlotIndex != -1)
        {
            // check slot is selected, if not => select it.
            GameObject selectedSlotObject = allPlaySlotObjectInAllDeck [currentDeckIndex] [selectedPlaySlotIndex];
            CharacterSlotDataController selectedSlotCtl = selectedSlotObject.GetComponent <CharacterSlotDataController> ();
            if (selectedSlotCtl.isSelected == false)
            {
                selectedSlotCtl.SetSelected();
            }
        }

        // if rest and play slot both selected, => switch them.
        if (selectedPlaySlotIndex != -1 && selectedRestSlotIndex != -1)
        {
            SwitchSelectedRestAndPlaySlot();
        }
    }
Ejemplo n.º 6
0
    // caculate all play lost's weight in current deck
    private int CaculateTotalWeight()
    {
        List <GameObject> playList = allPlaySlotObjectInAllDeck [currentDeckIndex];

        int totalWeight = 0;

        for (int i = 0; i < MaxPlaySlotNumber; i++)
        {
            CharacterSlotDataController playSlotObject = playList [i].GetComponent <CharacterSlotDataController> ();
            if (playSlotObject.GetIsEmptyData() == true)
            {
                continue;
            }
            int weight = playSlotObject.GetWeightData();
            if (weight < 0)
            {
                continue;
            }
            totalWeight += weight;
        }

        return(totalWeight);
    }