Example #1
0
    protected override void InitializeUi()
    {
        currCatSeled  = DefCatSelected;
        currItemSeled = currCatSeled.DefautItem;


        fixBackShop       = transform.parent.Find("GlobalBackGround/Shop").gameObject;
        moneyNumberPlayer = fixBackShop.transform.Find("MoneyMutation/MoneyNumber").GetComponent <Text> ( );

        moneyNumberPlayer.text = "" + AllPlayerPrefs.GetIntValue(Constants.Coin);

        ItemModif[] checkAllItem = GetComponentsInChildren <ItemModif> (true);
        ItemModif   currItem;

        string getCons = Constants.ItemBought;
        Dictionary <string, ItemModif> getItemConf = new Dictionary <string, ItemModif> ( );

        allTempItem = new List <ItemModif> ( );

        for (int a = 0; a < checkAllItem.Length; a++)
        {
            if (AllPlayerPrefs.GetBoolValue(getCons + checkAllItem [a].CatName + checkAllItem [a].ItemName))
            {
                currItem = checkAllItem [a];

                try{
                    getItemConf.Add(getCons + checkAllItem [a].CatName, currItem);
                }catch { Debug.Log("key same"); }

                currItem.GetComponent <Image> ( ).sprite = currItem.SpriteConfirm;

                if (currItem.UseColor)
                {
                    currItem.GetComponent <Image> ( ).color = currItem.ColorConfirm;
                }
            }
        }

        CheckSelectItem(true);

        allConfirm = getItemConf;
        GlobalManager.GameCont.AllModifItem = getItemConf;
        GlobalManager.GameCont.AllTempsItem = allTempItem;
    }
Example #2
0
    // achete ou confirme un item
    public void BuyItem( )
    {
        string getCons = Constants.ItemBought + currItemSeled.CatName;
        Dictionary <string, ItemModif> getAllBuy = allConfirm;

        if (AllPlayerPrefs.GetBoolValue(getCons + currItemSeled.ItemName))
        {
            AllPlayerPrefs.SetStringValue(getCons + currItemSeled.ItemName, "Confirm");
            ItemModif getThis;

            if (getAllBuy.TryGetValue(getCons, out getThis))
            {
                AllPlayerPrefs.SetStringValue(getCons + getThis.ItemName, "ok");

                if (getThis.UseOtherSprite)
                {
                    getThis.GetComponent <Image> ( ).sprite = currItemSeled.BoughtSpriteUnselected;
                }
                else
                {
                    getThis.GetComponent <Image> ( ).sprite = currItemSeled.SpriteUnselected;
                }

                if (getThis.UseColor)
                {
                    if (getThis.UseOtherColor)
                    {
                        getThis.GetComponent <Image> ( ).color = currItemSeled.BoughtColorUnSelected;
                    }
                    else
                    {
                        getThis.GetComponent <Image> ( ).color = currItemSeled.ColorUnSelected;
                    }
                }

                getAllBuy.Remove(getCons);
            }

            getThis = currItemSeled;
            getThis.GetComponent <Image> ( ).sprite = getThis.SpriteConfirm;

            if (getThis.UseColor)
            {
                getThis.GetComponent <Image> ( ).color = getThis.ColorConfirm;
            }

            getAllBuy.Add(getCons, getThis);
        }
        else
        {
            bool      checkProg = false;
            ItemModif currIT    = currItemSeled;

            if (currCatSeled.Progression)
            {
                if (currIT.UpItem.ItemBought || currIT.DownItem.ItemBought || currIT.LeftItem.ItemBought || currIT.RightItem.ItemBought)
                {
                    checkProg = true;
                }
            }
            else
            {
                checkProg = true;
            }

            if (checkProg && AllPlayerPrefs.GetIntValue(Constants.Coin) > currIT.Price)
            {
                Debug.Log("buy");
                AllPlayerPrefs.SetIntValue(Constants.Coin, -currIT.Price);

                if (currCatSeled.BuyForLife)
                {
                    getAllBuy.Add(getCons, currItemSeled);
                    AllPlayerPrefs.SetStringValue(getCons + currIT.ItemName);
                }
                else
                {
                    allTempItem.Add(currItemSeled);
                }
            }
        }

        moneyNumberPlayer.text = "" + AllPlayerPrefs.GetIntValue(Constants.Coin);
    }
Example #3
0
    public override void OnInspectorGUI()
    {
        EditorGUILayout.LabelField("Inspector Item Info", EditorStyles.boldLabel);
        ItemModif myTarget = (ItemModif)target;

        serializedObject.Update( );
        EditorGUILayout.PropertyField(ItemName);
        EditorGUILayout.PropertyField(Price);

        myTarget.CatName = myTarget.transform.parent.GetComponent <CatShop> ( ).NameCat;

        #region MainButton

        // Si l'item est acheté
        if (AllPlayerPrefs.GetBoolValue(Constants.ItemBought + myTarget.ItemName))
        {
            myTarget.ItemBought = true;
        }
        else
        {
            myTarget.ItemBought = false;
        }
        EditorGUILayout.Space( );

        // verification de l'utilisation de la couleur
        var buttonStyle = new GUIStyle(EditorStyles.miniButtonLeft);
        if (myTarget.UseColor)
        {
            buttonStyle.normal.textColor = Color.green;
        }
        else
        {
            buttonStyle.normal.textColor = Color.red;
        }

        EditorGUILayout.BeginHorizontal();
        // Bouton d'utilisation de la couleur
        if (GUILayout.Button("UseColor", buttonStyle))
        {
            myTarget.UseColor = !myTarget.UseColor;
        }

        // verification de l'utilisation de sprite
        buttonStyle = new GUIStyle(EditorStyles.miniButtonRight);
        if (myTarget.UseSprite)
        {
            buttonStyle.normal.textColor = Color.green;
        }
        else
        {
            buttonStyle.normal.textColor = Color.red;
        }

        // Bouton d'utilisation de sprite
        if (GUILayout.Button("UseSprite", buttonStyle))
        {
            myTarget.UseSprite = !myTarget.UseSprite;
        }
        EditorGUILayout.EndHorizontal( );
        #endregion

        #region Couleur
        // Ajout des différentes couleurs
        if (myTarget.UseColor)
        {
            EditorGUI.indentLevel = 1;

            EditorGUILayout.Space( );
            EditorGUILayout.BeginHorizontal();

            buttonStyle = new GUIStyle(EditorStyles.miniButton);
            if (myTarget.UseOtherColor)
            {
                buttonStyle.normal.textColor = Color.green;
            }
            else
            {
                buttonStyle.normal.textColor = Color.red;
            }

            if (GUILayout.Button("UseOtherColor", buttonStyle))
            {
                myTarget.UseOtherColor = !myTarget.UseOtherColor;
            }

            if (myTarget.UseSprite)
            {
                EditorGUILayout.Space( );

                buttonStyle = new GUIStyle(EditorStyles.miniButton);
                if (myTarget.UseOtherSprite)
                {
                    buttonStyle.normal.textColor = Color.green;
                }
                else
                {
                    buttonStyle.normal.textColor = Color.red;
                }

                if (GUILayout.Button("UseOtherSprite", buttonStyle))
                {
                    myTarget.UseOtherSprite = !myTarget.UseOtherSprite;
                }
            }
            EditorGUILayout.EndHorizontal( );

            EditorGUILayout.Space( );
            EditorGUILayout.LabelField("Color Information", EditorStyles.boldLabel);

            EditorGUILayout.PropertyField(ColorConfirm, Confirm);
            EditorGUILayout.PropertyField(ColorSelected, Select);
            EditorGUILayout.PropertyField(ColorUnSelected, UnSelect);

            if (myTarget.UseOtherColor)
            {
                EditorGUI.indentLevel = 2;

                EditorGUILayout.Space( );

                EditorGUILayout.PropertyField(BoughtColorSelected, BuySelect);
                EditorGUILayout.PropertyField(BoughtColorUnSelected, BuyUnSelect);

                if (myTarget.ItemBought)
                {
                    if (myTarget.Selected)
                    {
                        myTarget.GetComponent <Image> ( ).color = myTarget.BoughtColorSelected;
                    }
                    else
                    {
                        myTarget.GetComponent <Image> ( ).color = myTarget.BoughtColorUnSelected;
                    }
                }
            }
            else
            {
                if (myTarget.Selected)
                {
                    myTarget.GetComponent <Image> ( ).color = myTarget.ColorSelected;
                }
                else
                {
                    myTarget.GetComponent <Image> ( ).color = myTarget.ColorUnSelected;
                }
            }
        }
        #endregion

        #region Sprite
        if (myTarget.SpriteConfirm == null)
        {
            myTarget.SpriteConfirm = myTarget.GetComponent <Image> ( ).sprite;
        }
        if (myTarget.SpriteSelected == null)
        {
            myTarget.SpriteSelected = myTarget.GetComponent <Image> ( ).sprite;
        }
        if (myTarget.SpriteUnselected == null)
        {
            myTarget.SpriteUnselected = myTarget.GetComponent <Image> ( ).sprite;
        }

        if (myTarget.BoughtSpriteSelected == null)
        {
            myTarget.BoughtSpriteSelected = myTarget.GetComponent <Image> ( ).sprite;
        }
        if (myTarget.BoughtSpriteUnselected == null)
        {
            myTarget.BoughtSpriteUnselected = myTarget.GetComponent <Image> ( ).sprite;
        }

        if (myTarget.UseSprite)
        {
            EditorGUI.indentLevel = 1;

            EditorGUILayout.Space( );

            if (!myTarget.UseColor)
            {
                buttonStyle = new GUIStyle(EditorStyles.miniButton);
                if (myTarget.UseOtherSprite)
                {
                    buttonStyle.normal.textColor = Color.green;
                }
                else
                {
                    buttonStyle.normal.textColor = Color.red;
                }

                if (GUILayout.Button("UseOtherSprite", buttonStyle))
                {
                    myTarget.UseOtherSprite = !myTarget.UseOtherSprite;
                }
                EditorGUILayout.Space( );
            }

            EditorGUILayout.LabelField("Sprite Information", EditorStyles.boldLabel);

            EditorGUILayout.PropertyField(SpriteConfirm, Confirm);
            EditorGUILayout.PropertyField(SpriteSelected, Select);
            EditorGUILayout.PropertyField(SpriteUnselected, UnSelect);

            if (myTarget.UseOtherSprite)
            {
                EditorGUI.indentLevel = 2;

                EditorGUILayout.Space( );

                EditorGUILayout.PropertyField(BoughtSpriteSelected, BuySelect);
                EditorGUILayout.PropertyField(BoughtSpriteUnselected, BuyUnSelect);

                if (myTarget.ItemBought)
                {
                    if (myTarget.Selected)
                    {
                        myTarget.GetComponent <Image> ( ).sprite = myTarget.BoughtSpriteSelected;
                    }
                    else
                    {
                        myTarget.GetComponent <Image> ( ).sprite = myTarget.BoughtSpriteUnselected;
                    }
                }
            }
            else
            {
                if (myTarget.Selected)
                {
                    myTarget.GetComponent <Image> ( ).sprite = myTarget.SpriteSelected;
                }
                else
                {
                    myTarget.GetComponent <Image> ( ).sprite = myTarget.SpriteUnselected;
                }
            }

            EditorGUILayout.Space( );
        }
        #endregion

        EditorGUI.indentLevel = 0;

        EditorGUILayout.LabelField("Around Information", EditorStyles.boldLabel);
        EditorGUILayout.PropertyField(RightItem);
        EditorGUILayout.PropertyField(LeftItem);
        EditorGUILayout.PropertyField(UpItem);
        EditorGUILayout.PropertyField(DownItem);

        EditorGUILayout.Space( );
        EditorGUILayout.LabelField("Modification", EditorStyles.boldLabel);

        EditorGUILayout.BeginHorizontal();

        #region Caract
        buttonStyle = new GUIStyle(EditorStyles.miniButton);
        if (myTarget.ModifVie)
        {
            buttonStyle.normal.textColor = Color.green;
        }
        else
        {
            buttonStyle.normal.textColor = Color.red;
        }

        if (GUILayout.Button("ModifVie", buttonStyle))
        {
            myTarget.ModifVie = !myTarget.ModifVie;
        }

        if (myTarget.ModifVie)
        {
            myTarget.NombreVie = EditorGUILayout.IntField("NombreVie", myTarget.NombreVie);

            if (myTarget.NombreVie <= 0)
            {
                myTarget.NombreVie = 1;
            }
        }
        EditorGUILayout.EndHorizontal( );

        buttonStyle = new GUIStyle(EditorStyles.miniButton);
        if (myTarget.ModifSpecial)
        {
            buttonStyle.normal.textColor = Color.green;
        }
        else
        {
            buttonStyle.normal.textColor = Color.red;
        }
        EditorGUILayout.BeginHorizontal();
        #endregion

        #region SpecialAction
        if (GUILayout.Button("ModifSpecial", buttonStyle))
        {
            myTarget.ModifSpecial = !myTarget.ModifSpecial;
        }

        if (myTarget.ModifSpecial)
        {
            EditorGUILayout.PropertyField(SpecAction);
        }
        else
        {
            myTarget.SpecAction = SpecialAction.Nothing;
        }

        EditorGUILayout.EndHorizontal();

        EditorGUI.indentLevel = 1;

        if (myTarget.SpecAction == SpecialAction.SlowMot)
        {
            EditorGUILayout.PropertyField(SlowMotion);
            EditorGUILayout.PropertyField(SpeedSlowMot);
            EditorGUILayout.PropertyField(SpeedDeacSM);
            EditorGUILayout.PropertyField(ReduceSlider);
            EditorGUILayout.PropertyField(RecovSlider);
        }
        #endregion

        serializedObject.ApplyModifiedProperties( );

        EditorGUI.indentLevel = 0;

        if (myTarget.RightItem == null)
        {
            myTarget.RightItem = myTarget.GetComponent <ItemModif> ( );
        }
        if (myTarget.LeftItem == null)
        {
            myTarget.LeftItem = myTarget.GetComponent <ItemModif> ( );
        }
        if (myTarget.UpItem == null)
        {
            myTarget.UpItem = myTarget.GetComponent <ItemModif> ( );
        }
        if (myTarget.DownItem == null)
        {
            myTarget.DownItem = myTarget.GetComponent <ItemModif> ( );
        }

        /*
         * if ( myTarget.UpItem == null )
         * {
         *      myTarget.UpItem = myTarget.GetComponent<ItemModif> ( );
         * }
         * if ( myTarget.DownItem == null )
         * {
         *      myTarget.DownItem = myTarget.GetComponent<ItemModif> ( );
         * }*/
    }