Exemple #1
0
    //TODO change this to use assent bundles at some point
    /// <summary>
    /// load the text Assent CardAttr
    /// </summary>
    /// <param name="cardName"></param>
    /// <param name="cardAttr"></param>
    /// <returns></returns>
    public static bool LoadBasicCardAttributesFromJsonInResorceFolder(string cardName, out BasicCardAttributes cardAttr)
    {
        cardAttr = default(BasicCardAttributes);
        TextAsset cardAttrJson = PrefabResorceLoader.Instance.loadTextAsset(cardName + "/CardAttr");         //Note: resorce.load does not need file extension
        bool      loaded       = false;

        if (cardAttrJson != null)
        {
            loaded = SaveAndLoadJson.loadStructFromString(out cardAttr, cardAttrJson.text);
        }
        if (!loaded)
        {
            if (Application.isEditor)
            {
                //TODO create CardPramSetter
                Debug.Log("Card attributes not set" + cardName + "\n"
                          + "create using editor using CardPramSetter");
            }
            else
            {
                Debug.LogError("something has gone wrong, there are no card Attributes in " + cardName);
            }
        }
        return(loaded);
    }
    void OnGUI()
    {
        card         = (MonoScript)EditorGUILayout.ObjectField("card script", card, typeof(MonoScript), false);
        cardFilePath = GUILayout.TextField(cardFilePath);
        if (!cardFilePath.EndsWith("/"))
        {
            cardFilePath += "/";
        }

        if (GUILayout.Button("set prefab location based on cardClass"))
        {
            cardFilePath = card.GetClass().Name + "/";
            //default names
            cardAttrabutes.cardIconPath        = cardFilePath + "icon";
            cardAttrabutes.cardArtPath         = cardFilePath + "card art";
            cardAttrabutes.cardDescriptionPath = cardFilePath + "description";
            cardAttrabutes.cardName            = card.GetClass().Name;
        }

        //load existing card attributes

        TextAsset tempChangeCheck = existingCardAttr;

        existingCardAttr = (TextAsset)EditorGUILayout.ObjectField("CardAttr", existingCardAttr, typeof(TextAsset), false);
        if (GUILayout.Button("update Existing CardAttr") || tempChangeCheck != existingCardAttr)
        {
            if (existingCardAttr != null)
            {
                SaveAndLoadJson.loadStructFromString(out cardAttrabutes, existingCardAttr.text);
                string[] filePath = AssetDatabase.GetAssetPath(existingCardAttr).Split(new char[] { '/' });
                int      index    = 0;
                while (index < filePath.Length)
                {
                    if (filePath[index++] == "Resources")
                    {
                        break;
                    }
                }
                cardFilePath = "";
                for (int i = index; i < filePath.Length - 1; i++)
                {
                    cardFilePath += filePath[i] + "/";
                }
            }

            //default names
            cardAttrabutes.cardIconPath        = cardFilePath + "icon";
            cardAttrabutes.cardArtPath         = cardFilePath + "card art";
            cardAttrabutes.cardDescriptionPath = cardFilePath + "description";
        }

        cardAttrabutes.cardName                  = EditorGUILayout.TextField("card displayed name", cardAttrabutes.cardName);
        cardAttrabutes.cardResorceCost           = EditorGUILayout.FloatField("cost", cardAttrabutes.cardResorceCost);
        cardAttrabutes.cardReloadTime_seconds    = EditorGUILayout.FloatField("slot reload time", cardAttrabutes.cardReloadTime_seconds);
        cardAttrabutes.removeOnDraw              = EditorGUILayout.Toggle("removedOnDraw", cardAttrabutes.removeOnDraw);
        cardAttrabutes.probabilityOfDraw         = EditorGUILayout.FloatField("draw probability", cardAttrabutes.probabilityOfDraw);
        cardAttrabutes.numberOfCardAllowedInDeck = EditorGUILayout.IntField("Numb Allowed In Deck", cardAttrabutes.numberOfCardAllowedInDeck);
        cardAttrabutes.cardElements              = (DamageTypes)EditorGUILayout.EnumMaskPopup("setCardElements", cardAttrabutes.cardElements);
        cardAttrabutes.cardType                  = (CardLocation)EditorGUILayout.EnumMaskPopup("setCardType(s)", cardAttrabutes.cardType);


        GUILayout.Label("icon,card art, and card description (.txt)\nmust be added to the created folder");

        GUIStyle colorset = new GUIStyle(GUI.skin.button);

        if (timeLeftOnScreen_sec > 0)
        {
            colorset.normal.textColor = new Color(0f, 0.4f, 0f);
            timeLeftOnScreen_sec     -= Time.deltaTime;
        }
        else
        {
            colorset.normal.textColor = Color.black;
        }

        if (GUILayout.Button("create card information", colorset) && cardFilePath != "/")
        {
            if (!Directory.Exists(SaveAndLoadJson.getResourcePath(cardFilePath)))
            {
                Directory.CreateDirectory(SaveAndLoadJson.getResourcePath(cardFilePath));
            }

            //string printer = "";
            //SaveAndLoadJson.saveStructToString(cardAttrabutes,out printer);
            if (SaveAndLoadJson.saveStruct(SaveAndLoadJson.getResourcePath(cardFilePath + "CardAttr"), cardAttrabutes))
            {
                timeLeftOnScreen_sec = timeOnScreenMax_sec;
            }
            AssetDatabase.Refresh();
        }
    }