Inheritance: ScriptableObject
Esempio n. 1
0
        private IEnumerator TryConsumeItem(ConsumableData consumableData)
        {
            if (consumableData == null)
            {
                Debug.LogError($"사용하려고 하는 {nameof(ConsumableData)}가 null입니다");
                yield break;
            }

            // 아이템 사용이 의미 있는지 검사
            if (IsEffectable(consumableData) == false)
            {
                // TODO: 사용할 수 없는 아이템 사운드 재생, UI 텍스트 안내
                Debug.Log($"Not effectable");
                yield break;
            }

            // 아이템 사용 시전
            IsConsuming = true;
            ItemConsumeProgress consumeProgress = UIManager.Instance.itemConsumeProgress;

            consumeProgress.InitializeProgress(consumableData);

            //애니메이션 실행
            myAnimator.SetFloat(consumeSpeed, (2f / consumableData.TimeToUse) * (2f / 3f));
            myAnimator.SetTrigger(isConsume);

            float startTime = Time.time;
            float endTime   = startTime + consumableData.TimeToUse;
            float progress  = 0f;

            while (Time.time <= endTime)
            {
                progress = Mathf.InverseLerp(startTime, endTime, Time.time);
                consumeProgress.UpdateProgress(progress, endTime - Time.time);
                yield return(new WaitForSeconds(0.05f));
            }

            consumeProgress.Clear();
            IsConsuming = false;

            // 아이템 사용
            ConsumeItem(consumableData);
            myAnimator.ResetTrigger(isConsume);

            tryConsumeItemCoroutine = null;
        }
Esempio n. 2
0
        void Init(int templateId)
        {
            ItemData itemData = null;

            DataManager.ItemDict.TryGetValue(templateId, out itemData);
            if (itemData.itemType != ItemType.Consumable)
            {
                return;
            }

            ConsumableData data = (ConsumableData)itemData;
            {
                TemplateId     = data.id;
                Count          = 1;
                MaxCount       = data.maxCount;
                ConsumableType = data.consumableType;
                Stackable      = (data.maxCount > 1);
            }
        }
Esempio n. 3
0
    private void OnGUI()
    {
        //Display the window title at the top
        GUILayout.BeginHorizontal();
        GUILayout.Label("Consumable Effects Wizard", EditorStyles.boldLabel);
        GUILayout.EndHorizontal();

        //In the main body of the window, allow the option to change all of the consumables effect values
        ConsumableEffectName = EditorGUILayout.TextField("Consumable Effect Name", ConsumableEffectName);
        HealthValueEffect    = EditorGUILayout.IntField("Health Value Change", HealthValueEffect);
        StaminaValueEffect   = EditorGUILayout.IntField("Stamina Value Change", StaminaValueEffect);
        ManaValueEffect      = EditorGUILayout.IntField("Mana Value Change", ManaValueEffect);

        //Finally give a button to finalize the process and create the new ConsumableData asset file
        if (GUILayout.Button("Complete"))
        {
            //Make sure that a name has been entered, and check to make sure all the values are no all zero
            bool NameValid   = ConsumableEffectName != "";
            bool ValuesValid = HealthValueEffect != 0 || StaminaValueEffect != 0 || ManaValueEffect != 0;

            //Only finalize the asset creation if the values entered seem to be valid
            if (NameValid && ValuesValid)
            {
                //Create the new ConsumableData object and assign all of the entered values to it
                ConsumableData NewConsumableData = ScriptableObject.CreateInstance <ConsumableData>();
                NewConsumableData.EffectName             = StringEditor.RemoveSpaces(ConsumableEffectName);
                NewConsumableData.HealthValueAdjustment  = HealthValueEffect;
                NewConsumableData.StaminaValueAdjustment = StaminaValueEffect;
                NewConsumableData.ManaValueAdjustment    = ManaValueEffect;

                //Save this as a new asset file in the project files
                string AssetName = "Assets/Consumables/" + NewConsumableData.EffectName + ".asset";
                AssetDatabase.CreateAsset(NewConsumableData, AssetName);
                AssetDatabase.SaveAssets();

                //Reset all the editor window values
                ConsumableEffectName = "";
                HealthValueEffect    = 0;
                StaminaValueEffect   = 0;
                ManaValueEffect      = 0;
            }
        }
    }
Esempio n. 4
0
        private bool IsEffectable(ConsumableData consumableData)
        {
            switch (consumableData)
            {
            case HealingKitData healingKitData:
                float restorableHealth = MaximumHealth - CurrentHealth;
                float restorableShield = MaximumShield - CurrentShield;
                if (restorableHealth > 0 && healingKitData.HealthRestoreAmount > 0 ||
                    restorableShield > 0 && healingKitData.ShieldRestoreAmount > 0)
                {
                    return(true);
                }
                break;

            default:
                Debug.LogError($"관리되지 않고 있는 {nameof(ConsumableData)}입니다, {consumableData.GetType().Name}");
                break;
            }

            return(false);
        }
Esempio n. 5
0
    public static void Init()
    {
        if (string.IsNullOrEmpty(path))
        {
            path = Path.Combine(Application.dataPath, "Items.json");
        }
        if (initialized || !File.Exists(path))
        {
            return;
        }
        JObject parsedJson = JObject.Parse(File.ReadAllText(path));
        JArray  array      = parsedJson["Items"] as JArray;

        data = new ItemData[array.Count];

        foreach (DropRate rate in System.Enum.GetValues(typeof(DropRate)))
        {
            dropTable.Add(rate, new List <ItemData>());
        }

        int count = 0;

        foreach (var val in array)
        {
            switch ((ItemType)val[Keys.KEY_ITEMTYPE].Value <int>())
            {
            case ItemType.Consumable:
                data[count] = new ConsumableData(val);
                break;

            case ItemType.Equipable:
                data[count] = new EquipmentData(val);
                break;
            }
            Debug.Log(data[count]);
            dropTable[data[count].DropRate].Add(data[count]);
            count++;
        }
        initialized = true;
    }
Esempio n. 6
0
        private void ConsumeItem(ConsumableData consumableData)
        {
            if (consumableData == null)
            {
                Debug.LogError($"사용하려고 하는 {nameof(ConsumableData)}가 null입니다");
                return;
            }

            // 아이템 사용이 의미 있는지 검사
            if (IsEffectable(consumableData) == false)
            {
                // TODO: 사용할 수 없는 아이템 사운드 재생, UI 텍스트 안내
                Debug.LogWarning($"Not effectable");
                return;
            }

            // ItemContainer에 사용하려는 아이템이 있는지 검사
            int targetSlot = ItemContainer.FindMatchItemSlotFromLast(consumableData.ItemName);

            if (targetSlot == -1)
            {
                Debug.LogWarning($"사용하려고 하는 아이템이 {nameof(ItemContainer)}에 없습니다, {nameof(consumableData.ItemName)}: {consumableData.ItemName}");
                return;
            }
            ItemContainer.SubtrackItemAtSlot(targetSlot);

            // 사용 효과 적용
            switch (consumableData)
            {
            case HealingKitData healingKit:
                CurrentHealth += healingKit.HealthRestoreAmount;
                CurrentShield += healingKit.ShieldRestoreAmount;
                break;

            default:
                Debug.LogWarning($"관리되지 않고 있는 {nameof(ConsumableData)}입니다, {consumableData.GetType().Name}");
                return;
            }
        }
Esempio n. 7
0
    void OnGUI()
    {
        //Show the window title at the top
        GUILayout.BeginHorizontal();
        GUILayout.Label("Master Item List Editor", EditorStyles.boldLabel);
        GUILayout.EndHorizontal();
        GUILayout.Space(10);

        //Combines all the lists together into 1 giant master item list with every single thing detailed within, exports it out into a text file storing all that data
        if (GUILayout.Button("Export Master List", GUILayout.ExpandWidth(false)))
        {
            //Create a brand new master list which will contain every item from every list we have
            List <ItemData> MasterItemList = new List <ItemData>();

            //Fill the new MasterItemList so it contains all the other lists combined
            foreach (ItemData Item in ConsumableItemList.ItemList)
            {
                MasterItemList.Add(Item);
            }
            foreach (ItemData Item in EquipmentItemList.ItemList)
            {
                MasterItemList.Add(Item);
            }
            foreach (ItemData Item in AbilityItemList.ItemList)
            {
                MasterItemList.Add(Item);
            }

            //Loop through the entire list, assigning a new ItemNumber value to each item as we go through
            for (int i = 0; i < MasterItemList.Count; i++)
            {
                MasterItemList[i].ItemNumber = (i + 1);
            }

            //Create a list of strings, each string being 1 line in the text file we are going to export
            List <string> FileLines = new List <string>();

            //Each line in the texture file details an item that exists inside the game
            foreach (ItemData Item in MasterItemList)
            {
                FileLines.Add(Item.Name + ":" + Item.DisplayName + ":" + Item.Type + ":" + Item.Slot + ":" + Item.ItemNumber);
            }

            //Cast the List of strings into a regular array, then write it all into a new text file
            string[] Lines    = FileLines.ToArray();
            string   FileName = "C:/mmo-client/Assets/Exports/MasterItemList.txt";
            System.IO.File.WriteAllLines(FileName, Lines);
        }

        //Loads in a previous master item list from a local text file


        ////Loads in a previous master item list from a local text file
        //if(GUILayout.Button("Import Master List", GUILayout.ExpandWidth(false)))
        //{
        //    //string[] FileLines = System.IO.File.ReadAllLines("C:/mmo-client/Assets/Exports/MasterItemList.txt");

        //    //foreach(string Line in FileLines)
        //    //{
        //    //    string[] LineSplit = Line.Split(':');
        //    //}
        //}

        //Consumable Item List Management
        GUILayout.Label("Consumable Items");
        if (ConsumableItemList == null)
        {
            if (GUILayout.Button("Create New Consumable ItemDataList", GUILayout.ExpandWidth(false)))
            {
                ConsumableItemList = CreateNewList("Assets/Items/ConsumableItemDataList.asset", "ConsumableItemListPath");
            }
        }
        else
        {
            if (GUILayout.Button("Open Consumable List", GUILayout.ExpandWidth(false)))
            {
                string AbsolutePath = EditorUtility.OpenFilePanel("Select Consumable Item List", "", "");
                if (AbsolutePath.StartsWith(Application.dataPath))
                {
                    string RelativePath = AbsolutePath.Substring(Application.dataPath.Length - "Assets".Length);
                    ConsumableItemList = AssetDatabase.LoadAssetAtPath(RelativePath, typeof(ItemDataList)) as ItemDataList;
                    if (ConsumableItemList == null)
                    {
                        ConsumableItemList.ItemList = new List <ItemData>();
                    }
                    if (ConsumableItemList)
                    {
                        EditorPrefs.SetString("ConsumableItemListPath", RelativePath);
                    }
                }
            }

            ExistingConsumableItem = EditorGUILayout.ObjectField("Existing Consumable Item Insert", ExistingConsumableItem, typeof(ItemData), false) as ItemData;
            if (GUILayout.Button("Add", GUILayout.ExpandWidth(false)))
            {
                ConsumableItemList.ItemList.Add(ExistingConsumableItem);
                ExistingConsumableItem = null;
            }

            //Place buttons to move back and forth while navigating the list of consumable items
            GUILayout.BeginHorizontal();
            if (GUILayout.Button("Prev", GUILayout.ExpandWidth(false)))
            {
                if (ConsumableDataIndex > 1)
                {
                    ConsumableDataIndex--;
                }
            }
            GUILayout.Space(5);
            if (GUILayout.Button("Next", GUILayout.ExpandWidth(false)))
            {
                if (ConsumableDataIndex < ConsumableItemList.ItemList.Count)
                {
                    ConsumableDataIndex++;
                }
            }
            GUILayout.EndHorizontal();

            //Navigate through the items in the consumables list if it has any in it
            if (ConsumableItemList.ItemList.Count > 0)
            {
                GUILayout.BeginHorizontal();
                ConsumableDataIndex = Mathf.Clamp(EditorGUILayout.IntField("Current Consumable ItemData", ConsumableDataIndex, GUILayout.ExpandWidth(false)), 1, ConsumableItemList.ItemList.Count);
                EditorGUILayout.LabelField("of " + ConsumableItemList.ItemList.Count.ToString() + " items", "", GUILayout.ExpandWidth(false));
                GUILayout.EndHorizontal();

                ItemData CurrentConsumableItemData = ConsumableItemList.ItemList[ConsumableDataIndex - 1];
                GUILayout.BeginHorizontal();
                CurrentConsumableItemData.Name        = EditorGUILayout.TextField("Current Consumable Name", CurrentConsumableItemData.Name as string);
                CurrentConsumableItemData.DisplayName = EditorGUILayout.TextField("Current Consumable Display Name", CurrentConsumableItemData.DisplayName as string);
                CurrentConsumableItemData.Description = EditorGUILayout.TextField("Current Consumable Description", CurrentConsumableItemData.Description as string);
                CurrentConsumableItemData.Type        = (ItemType)EditorGUILayout.EnumPopup("Current Consumable Item Type", CurrentConsumableItemData.Type);
                GUILayout.EndHorizontal();
                GUILayout.BeginHorizontal();
                CurrentConsumableItemData.Prefab           = EditorGUILayout.ObjectField("Current Consumable Pickup Prefab", CurrentConsumableItemData.Prefab, typeof(GameObject), false) as GameObject;
                CurrentConsumableItemData.Icon             = EditorGUILayout.ObjectField("Current Consumable Icon", CurrentConsumableItemData.Icon, typeof(Sprite), false) as Sprite;
                CurrentConsumableItemData.ConsumableEffect = EditorGUILayout.ObjectField("Current Consumable Effects", CurrentConsumableItemData.ConsumableEffect, typeof(ConsumableData), false) as ConsumableData;
                GUILayout.EndHorizontal();
            }

            //Allow the creation of brand new consumable items that get stored straight into the consumable item data list with the others
            GUILayout.BeginHorizontal();
            NewConsumableItemName    = EditorGUILayout.TextField("New Consumable Name", NewConsumableItemName as string);
            NewConsumableDisplayName = EditorGUILayout.TextField("New Consumable Display Name", NewConsumableDisplayName as string);
            NewConsumableDescription = EditorGUILayout.TextField("New Consumable Description", NewConsumableDescription as string);
            GUILayout.EndHorizontal();
            GUILayout.BeginHorizontal();
            NewConsumablePickupPrefab = EditorGUILayout.ObjectField("New Consumable Pickup Prefab", NewConsumablePickupPrefab, typeof(GameObject), false) as GameObject;
            NewConsumableIcon         = EditorGUILayout.ObjectField("New Consumable Icon", NewConsumableIcon, typeof(Sprite), false) as Sprite;
            NewConsumableEffects      = EditorGUILayout.ObjectField("New Consumable Effects", NewConsumableEffects, typeof(ConsumableData), false) as ConsumableData;
            GUILayout.EndHorizontal();

            if (GUILayout.Button("Create New Consumable", GUILayout.ExpandWidth(false)))
            {
                //Create the new consumable itemdata object and store all the relevant information inside it
                ItemData NewConsumableItem = ScriptableObject.CreateInstance <ItemData>();
                NewConsumableItem.Name             = NewConsumableItemName;
                NewConsumableItem.DisplayName      = NewConsumableDisplayName;
                NewConsumableItem.Description      = NewConsumableDescription;
                NewConsumableItem.Prefab           = NewConsumablePickupPrefab;
                NewConsumableItem.Icon             = NewConsumableIcon;
                NewConsumableItem.ConsumableEffect = NewConsumableEffects;
                NewConsumableItem.Type             = ItemType.Consumable;

                //Save this as a new asset in the project directory
                string AssetName = "Assets/Items/Consumables/" + NewConsumableItem.Name + ".asset";
                AssetDatabase.CreateAsset(NewConsumableItem, AssetName);
                AssetDatabase.SaveAssets();

                //Place this in the list with the rest of the consumable items
                ConsumableItemList.ItemList.Add(NewConsumableItem);

                //Empty all the input fields
                NewConsumableItemName     = "";
                NewConsumableDisplayName  = "";
                NewConsumableDescription  = "";
                NewConsumablePickupPrefab = null;
                NewConsumableIcon         = null;
                NewConsumableEffects      = null;
            }
        }

        //Equipment Item List Management
        GUILayout.Space(15);
        GUILayout.Label("Equipment Items");
        if (EquipmentItemList == null)
        {
            if (GUILayout.Button("Create New Equipment ItemDataList", GUILayout.ExpandWidth(false)))
            {
                EquipmentItemList = CreateNewList("Assets/Items/EquipmentItemDataList.asset", "EquipmentItemListPath");
            }
        }
        else
        {
            if (GUILayout.Button("Open Equipment List", GUILayout.ExpandWidth(false)))
            {
                string AbsolutePath = EditorUtility.OpenFilePanel("Select Equipment Item List", "", "");
                if (AbsolutePath.StartsWith(Application.dataPath))
                {
                    string RelativePath = AbsolutePath.Substring(Application.dataPath.Length - "Assets".Length);
                    EquipmentItemList = AssetDatabase.LoadAssetAtPath(RelativePath, typeof(ItemDataList)) as ItemDataList;
                    if (EquipmentItemList == null)
                    {
                        EquipmentItemList.ItemList = new List <ItemData>();
                    }
                    if (EquipmentItemList)
                    {
                        EditorPrefs.SetString("EquipmentItemListPath", RelativePath);
                    }
                }
            }

            ExistingEquipmentItem = EditorGUILayout.ObjectField("Existing Equipment Item Insert", ExistingEquipmentItem, typeof(ItemData), false) as ItemData;
            if (GUILayout.Button("Add", GUILayout.ExpandWidth(false)))
            {
                EquipmentItemList.ItemList.Add(ExistingEquipmentItem);
                ExistingEquipmentItem = null;
            }

            GUILayout.BeginHorizontal();
            if (GUILayout.Button("Prev", GUILayout.ExpandWidth(false)))
            {
                if (EquipmentDataIndex > 1)
                {
                    EquipmentDataIndex--;
                }
            }
            GUILayout.Space(5);
            if (GUILayout.Button("Next", GUILayout.ExpandWidth(false)))
            {
                if (EquipmentDataIndex < EquipmentItemList.ItemList.Count)
                {
                    EquipmentDataIndex++;
                }
            }
            GUILayout.EndHorizontal();

            //Navigate through the items in the equipments list if it has any in it
            if (EquipmentItemList.ItemList.Count > 0)
            {
                GUILayout.BeginHorizontal();
                EquipmentDataIndex = Mathf.Clamp(EditorGUILayout.IntField("Current Equipment ItemData", EquipmentDataIndex, GUILayout.ExpandWidth(false)), 1, EquipmentItemList.ItemList.Count);
                EditorGUILayout.LabelField("of " + EquipmentItemList.ItemList.Count.ToString() + " items", "", GUILayout.ExpandWidth(false));
                GUILayout.EndHorizontal();

                ItemData CurrentEquipmentItemData = EquipmentItemList.ItemList[EquipmentDataIndex - 1];
                GUILayout.BeginHorizontal();
                CurrentEquipmentItemData.Name        = EditorGUILayout.TextField("Current Equipment Name", CurrentEquipmentItemData.Name as string);
                CurrentEquipmentItemData.DisplayName = EditorGUILayout.TextField("Current Equipment Display Name", CurrentEquipmentItemData.DisplayName as string);
                CurrentEquipmentItemData.Description = EditorGUILayout.TextField("Current Equipment Description", CurrentEquipmentItemData.Description as string);
                GUILayout.EndHorizontal();
                GUILayout.BeginHorizontal();
                CurrentEquipmentItemData.Type   = (ItemType)EditorGUILayout.EnumPopup("Current Equipment Item Type", CurrentEquipmentItemData.Type);
                CurrentEquipmentItemData.Prefab = EditorGUILayout.ObjectField("Current Consumable Pickup Prefab", CurrentEquipmentItemData.Prefab, typeof(GameObject), false) as GameObject;
                CurrentEquipmentItemData.Icon   = EditorGUILayout.ObjectField("Current Consumable Icon", CurrentEquipmentItemData.Icon, typeof(Sprite), false) as Sprite;
                GUILayout.EndHorizontal();
            }

            //Allow the creation of brand new equipment items that get stored straight into the equipments item data list with the others
            GUILayout.BeginHorizontal();
            NewEquipmentItemName    = EditorGUILayout.TextField("New Equipment Name", NewEquipmentItemName as string);
            NewEquipmentDisplayName = EditorGUILayout.TextField("New Equipment Display Name", NewEquipmentDisplayName as string);
            NewEquipmentDescription = EditorGUILayout.TextField("New Equipment Description", NewEquipmentDescription as string);
            GUILayout.EndHorizontal();
            GUILayout.BeginHorizontal();
            NewEquipmentType         = (ItemType)EditorGUILayout.EnumPopup("New Equipment Item Type", NewEquipmentType);
            NewEquipmentSlot         = (EquipmentSlot)EditorGUILayout.EnumPopup("New Equipment Item Slot", NewEquipmentSlot);
            NewEquipmentPickupPrefab = EditorGUILayout.ObjectField("New Equipment Pickup Prefab", NewEquipmentPickupPrefab, typeof(GameObject), false) as GameObject;
            NewEquipmentIcon         = EditorGUILayout.ObjectField("New Equipment Icon", NewEquipmentIcon, typeof(Sprite), false) as Sprite;
            GUILayout.EndHorizontal();

            if (GUILayout.Button("Create New Equipment", GUILayout.ExpandWidth(false)))
            {
                //Create the new equipment ItemData object and store all the relevant information inside it
                ItemData NewEquipmentItem = ScriptableObject.CreateInstance <ItemData>();
                NewEquipmentItem.Name        = NewEquipmentItemName;
                NewEquipmentItem.DisplayName = NewEquipmentDisplayName;
                NewEquipmentItem.Description = NewEquipmentDescription;
                NewEquipmentItem.Type        = NewEquipmentType;
                NewEquipmentItem.Prefab      = NewEquipmentPickupPrefab;
                NewEquipmentItem.Icon        = NewEquipmentIcon;
                NewEquipmentItem.Slot        = NewEquipmentSlot;

                //Save this as a new asset in the project
                string AssetName = "Assets/Items/Equipments/" + NewEquipmentItem.Name + ".asset";
                AssetDatabase.CreateAsset(NewEquipmentItem, AssetName);
                AssetDatabase.SaveAssets();

                EquipmentItemList.ItemList.Add(NewEquipmentItem);

                //Empty all the input fields
                NewEquipmentItemName     = "";
                NewEquipmentDisplayName  = "";
                NewEquipmentDescription  = "";
                NewEquipmentSlot         = EquipmentSlot.NULL;
                NewEquipmentType         = ItemType.NULL;
                NewEquipmentPickupPrefab = null;
                NewEquipmentIcon         = null;
            }
        }

        //Ability Item List Management
        GUILayout.Space(15);
        GUILayout.Label("Ability Items");
        if (AbilityItemList == null)
        {
            if (GUILayout.Button("Create New Ability ItemDataList", GUILayout.ExpandWidth(false)))
            {
                AbilityItemList = CreateNewList("Assets/Items/AbilityItemDataList.asset", "AbilityItemListPath");
            }
        }
        else
        {
            if (GUILayout.Button("Open Ability List", GUILayout.ExpandWidth(false)))
            {
                string AbsolutePath = EditorUtility.OpenFilePanel("Select Ability Item List", "", "");
                if (AbsolutePath.StartsWith(Application.dataPath))
                {
                    string RelativePath = AbsolutePath.Substring(Application.dataPath.Length - "Assets".Length);
                    AbilityItemList = AssetDatabase.LoadAssetAtPath(RelativePath, typeof(ItemDataList)) as ItemDataList;
                    if (AbilityItemList == null)
                    {
                        AbilityItemList.ItemList = new List <ItemData>();
                    }
                    if (AbilityItemList)
                    {
                        EditorPrefs.SetString("AbilityItemListPath", RelativePath);
                    }
                }
            }

            ExistingAbilityItem = EditorGUILayout.ObjectField("Existing Ability Item Insert", ExistingAbilityItem, typeof(ItemData), false) as ItemData;
            if (GUILayout.Button("Add", GUILayout.ExpandWidth(false)))
            {
                AbilityItemList.ItemList.Add(ExistingAbilityItem);
                ExistingAbilityItem = null;
            }

            GUILayout.BeginHorizontal();
            if (GUILayout.Button("Prev", GUILayout.ExpandWidth(false)))
            {
                if (AbilityDataIndex > 1)
                {
                    AbilityDataIndex--;
                }
            }
            GUILayout.Space(5);
            if (GUILayout.Button("Next", GUILayout.ExpandWidth(false)))
            {
                if (AbilityDataIndex < AbilityItemList.ItemList.Count)
                {
                    AbilityDataIndex++;
                }
            }
            GUILayout.EndHorizontal();

            //Navigate through the items in the abilitys list if it has any in it
            if (AbilityItemList.ItemList.Count > 0)
            {
                GUILayout.BeginHorizontal();
                AbilityDataIndex = Mathf.Clamp(EditorGUILayout.IntField("Current Ability ItemData", AbilityDataIndex, GUILayout.ExpandWidth(false)), 1, AbilityItemList.ItemList.Count);
                EditorGUILayout.LabelField("of " + AbilityItemList.ItemList.Count.ToString() + " items", "", GUILayout.ExpandWidth(false));
                GUILayout.EndHorizontal();

                ItemData CurrentAbilityItemData = AbilityItemList.ItemList[AbilityDataIndex - 1];
                GUILayout.BeginHorizontal();
                CurrentAbilityItemData.Name        = EditorGUILayout.TextField("Current Ability Name", CurrentAbilityItemData.Name as string);
                CurrentAbilityItemData.DisplayName = EditorGUILayout.TextField("Current Ability Display Name", CurrentAbilityItemData.DisplayName as string);
                CurrentAbilityItemData.Description = EditorGUILayout.TextField("Current Ability Description", CurrentAbilityItemData.Description as string);
                GUILayout.EndHorizontal();
                GUILayout.BeginHorizontal();
                CurrentAbilityItemData.Type   = (ItemType)EditorGUILayout.EnumPopup("Current Ability Item Type", CurrentAbilityItemData.Type);
                CurrentAbilityItemData.Prefab = EditorGUILayout.ObjectField("Current Ability Pickup Prefab", CurrentAbilityItemData.Prefab, typeof(GameObject), false) as GameObject;
                CurrentAbilityItemData.Icon   = EditorGUILayout.ObjectField("Current Ability Icon", CurrentAbilityItemData.Icon, typeof(Sprite), false) as Sprite;
                GUILayout.EndHorizontal();
            }

            //Allow the creation of brand new equipment items that get stored straight into the equipments item data list with the others
            GUILayout.BeginHorizontal();
            NewAbilityItemName    = EditorGUILayout.TextField("New Ability Name", NewAbilityItemName as string);
            NewAbilityDisplayName = EditorGUILayout.TextField("New Ability Display Name", NewAbilityDisplayName as string);
            NewAbilityDescription = EditorGUILayout.TextField("New Ability Description", NewAbilityDescription as string);
            GUILayout.EndHorizontal();
            GUILayout.BeginHorizontal();
            NewAbilityPickupPrefab = EditorGUILayout.ObjectField("New Ability Pickup Prefab", NewAbilityPickupPrefab, typeof(GameObject), false) as GameObject;
            NewAbilityIcon         = EditorGUILayout.ObjectField("New Ability Icon", NewAbilityIcon, typeof(Sprite), false) as Sprite;
            GUILayout.EndHorizontal();

            if (GUILayout.Button("Create New Ability", GUILayout.ExpandWidth(false)))
            {
                //Create the new equipment ItemData object and store all the relevant information inside it
                ItemData NewAbilityItem = ScriptableObject.CreateInstance <ItemData>();
                NewAbilityItem.Name        = NewAbilityItemName;
                NewAbilityItem.DisplayName = NewAbilityDisplayName;
                NewAbilityItem.Description = NewAbilityDescription;
                NewAbilityItem.Prefab      = NewAbilityPickupPrefab;
                NewAbilityItem.Icon        = NewAbilityIcon;
                NewAbilityItem.Type        = ItemType.AbilityGem;

                //Save this as a new asset in the project
                string AssetName = "Assets/Items/Abilities/" + NewAbilityItem.Name + ".asset";
                AssetDatabase.CreateAsset(NewAbilityItem, AssetName);
                AssetDatabase.SaveAssets();

                AbilityItemList.ItemList.Add(NewAbilityItem);

                //Empty all the input fields
                NewAbilityItemName     = "";
                NewAbilityDisplayName  = "";
                NewAbilityDescription  = "";
                NewAbilityPickupPrefab = null;
                NewAbilityIcon         = null;
            }
        }
    }
Esempio n. 8
0
        void OnGUI()
        {
            GUIStyle boxStyle = new GUIStyle("box");

            var width  = position.size.x - boxStyle.border.horizontal;
            var height = position.size.y - boxStyle.border.vertical;

            var innerBoxWidth  = width - (boxStyle.padding.horizontal + boxStyle.border.horizontal);
            var innerBoxHeight = height - (boxStyle.padding.vertical + boxStyle.border.vertical);

            EditorGUILayout.BeginVertical(boxStyle, GUILayout.Width(width), GUILayout.Height(height));

            // 设置路径, 以及存取数据 add by TangJian 2017/11/15 16:22:45
            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField(consumableDataFile);
            if (MyGUI.Button("读取"))
            {
                loadConsumableData();
            }
            if (MyGUI.Button("保存"))
            {
                saveConsumableData();
            }
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField(prefabPath);
            if (MyGUI.Button("制作预制体"))
            {
                saveConsumableData();
            }
            EditorGUILayout.EndHorizontal();

            // 编辑区域 add by TangJian 2017/11/15 16:28:19
            EditorGUILayout.BeginHorizontal();

            // // 列表框 add by TangJian 2017/11/15 16:27:46
            EditorGUILayout.BeginVertical(boxStyle, GUILayout.Width(innerBoxWidth / 2), GUILayout.ExpandHeight(true));
            listScrollViewPos = EditorGUILayout.BeginScrollView(listScrollViewPos);

            for (int i = consumableDataList.Count - 1; i >= 0; i--)
            {
                var item = consumableDataList[i];
                EditorGUILayout.BeginHorizontal();

                if (MyGUI.Button("删除", GUILayout.Width(50)))
                {
                    consumableDataList.RemoveAt(i);
                }

                if (MyGUI.Button(item.id))
                {
                    currConsumableData = item;
                }

                if (MyGUI.Button("复制", GUILayout.Width(50)))
                {
                    var consumableData = Tools.Json2Obj <ConsumableData>(Tools.Obj2Json(item, true));
                    consumableDataList.Add(consumableData);
                }

                EditorGUILayout.EndHorizontal();
            }

            if (MyGUI.Button("+"))
            {
                consumableDataList.Add(new ConsumableData());
            }

            EditorGUILayout.EndScrollView();
            EditorGUILayout.EndVertical();


            // 编辑框 add by TangJian 2017/11/15 16:28:46
            EditorGUILayout.BeginVertical(boxStyle, GUILayout.Width(innerBoxWidth / 2), GUILayout.ExpandHeight(true));
            editScrollViewPos = EditorGUILayout.BeginScrollView(editScrollViewPos);
            if (currConsumableData != null)
            {
                MyGUI.ItemDataField(currConsumableData);
            }
            EditorGUILayout.EndScrollView();
            EditorGUILayout.EndVertical();


            EditorGUILayout.EndHorizontal();

            EditorGUILayout.EndVertical();
        }
Esempio n. 9
0
    /// <summary>
    /// Handle JSON data
    /// </summary>
    /// <param name="text">JSON data as string</param>
    public void HandleJsonResponse(string text)
    {
        Debug.Log("HandleJsonResponse()");

        // set status
        dataRequestStatus = DataRequestStatus.receiving;

        // parse JSON array
        JArray a = JArray.Parse(text);

        // update count
        receivedTotal     = a.Count;
        dataRequestStatus = DataRequestStatus.handling;

        DebugManager.Instance.UpdateDisplay("DataManager.GetNewData() dataRequestStatus = " + dataRequestStatus);

        // loop through array and add each
        foreach (JObject item in a)
        {
            // base class properties
            string _username   = item.GetValue("username").ToString();
            string _avatarPath = item.GetValue("avatarPath").ToString();

            int _level                    = (int)item.GetValue("level");
            int _clicks                   = (int)item.GetValue("clicks");
            int _score                    = (int)item.GetValue("score");
            int _time                     = (int)item.GetValue("time");
            int _capturedTotal            = (int)item.GetValue("capturedTotal");
            int _missedTotal              = (int)item.GetValue("missedTotal");
            int _pageActionScrollDistance = (int)item.GetValue("pageActionScrollDistance");
            int _trackersBlocked          = (int)item.GetValue("trackersBlocked");
            int _trackersSeen             = (int)item.GetValue("trackersSeen");

            string _eventType    = item.GetValue("eventType").ToString();
            string _createdAtStr = item.GetValue("createdAt").ToString();
            string _monsters     = item.GetValue("monsters").ToString();
            string _trackers     = item.GetValue("trackers").ToString();

            // parse string to ISO 8601 format
            DateTime _createdAt = DateTime.Parse(_createdAtStr, null, System.Globalization.DateTimeStyles.RoundtripKind);



            // LIVE MODE ONLY - SKIP DUPLICATES

            if (selectedMode == ModeType.remoteLive)
            {
                // get any duplicate dates in buffer based on both conditions
                var bufferMatches  = Timeline.Instance.buffer.FindAll(found => found.createdAt == _createdAt);
                var historyMatches = Timeline.Instance.history.FindAll(found => found.createdAt == _createdAt);

                // skip this iteration
                if (bufferMatches.Count > 0 || historyMatches.Count > 0)
                {
                    Debug.Log("DUPLICATE createdAt = " + _createdAt + " AND eventType = " + _eventType);
                    receivedDuplicates++;
                    continue;
                }
            }



            // IF NOT A DUPLICATE THEN PROCEED

            receivedNew++;

            // parse eventData
            JObject d = JObject.Parse(item.GetValue("eventData").ToString());

            // object to hold data
            FeedData output;

            if (_eventType == "attack")
            {
                output = new AttackData {
                    _name     = (string)d ["name"],
                    _type     = (string)d ["level"],
                    _selected = (bool)d ["selected"]
                };
            }
            else if (_eventType == "badge")
            {
                output = new BadgeData {
                    _name  = (string)d ["name"],
                    _level = (int)d ["level"]
                };
            }
            else if (_eventType == "consumable")
            {
                output = new ConsumableData {
                    _name  = (string)d ["name"],
                    _slug  = (string)d ["slug"],
                    _stat  = (string)d ["stat"],
                    _type  = (string)d ["type"],
                    _value = (int)d ["value"]
                };
            }
            else if (_eventType == "disguise")
            {
                output = new DisguiseData {
                    _name = (string)d ["name"],
                    _type = (string)d ["type"]
                };
            }
            else if (_eventType == "monster")
            {
                output = new MonsterData {
                    _mid      = (int)d ["mid"],
                    _level    = (int)d ["level"],
                    _captured = (int)d ["captured"],
                };
            }
            else if (_eventType == "tracker")
            {
                output = new TrackerData {
                    _tracker  = (string)d ["tracker"],
                    _captured = (int)d ["captured"],
                };
            }
            else     // if (_eventType == "stream")
            {
                output = new StreamData {
                    _score  = (int)d ["score"],
                    _clicks = (int)d ["clicks"],
                    _likes  = (int)d ["likes"],
                };
            }

            output.username   = _username;
            output.avatarPath = _avatarPath;

            output.level                    = _level;
            output.clicks                   = _clicks;
            output.score                    = _score;
            output.time                     = _time;
            output.capturedTotal            = _capturedTotal;
            output.missedTotal              = _missedTotal;
            output.pageActionScrollDistance = _pageActionScrollDistance;
            output.trackersBlocked          = _trackersBlocked;
            output.trackersSeen             = _trackersSeen;
            output.clicks                   = _clicks;

            output.eventType = _eventType;
            output.createdAt = _createdAt;
            output.monsters  = _monsters;
            output.trackers  = _trackers;



            // add to feeds - now adding to buffer in Timeline
            //feeds.Add (output);



            // if live mode == true

            // then attempt to add to buffer
            Timeline.Instance.buffer.Add(output);


            //Debug.Log ("Added " + _username + " event " + _eventType + " at " + _createdAt);
        }



        // set status
        dataRequestStatus = DataRequestStatus.finished;

        // trigger data updated event
        EventManager.TriggerEvent("DataRequestFinished");
    }
Esempio n. 10
0
 public Consumable(ConsumableData itemData) : base(itemData)
 {
     IsConsumable      = itemData.IsConsumable;
     OnConsumedEffects = itemData.OnConsumedEffects;
 }
Esempio n. 11
0
 public ConsumableCardArgs(ResourceCardData data1, ConsumableData data2)
 {
     baseData       = data1;
     consumableData = data2;
 }
Esempio n. 12
0
    /// <summary>
    /// 解析JSON数据文件
    /// 物品数据都放入了容器中listItemData
    /// </summary>
    void parseItemsJson()
    {
        listItemData = new List <ItemData>();
        //第一种数据读取方式
        //Application.streamingAssetsPath
        string path = Application.streamingAssetsPath + "/Item.txt";
        string json = "";//保存文本内容

        //StreamReader sr = new StreamReader(path);
        //json = sr.ReadToEnd();
        //sr.Close();
        //第二种数据读取方式
        TextAsset s = Resources.Load("ItemData/Item") as TextAsset;

        json = s.text;
        //Debug.Log(json);

        JsonData data = JsonMapper.ToObject(json);//把字符串文本解析成对象

        int i = 0;

        for (i = 0; i <= data.Count - 1; i++)
        {
            ItemConfig gp = JsonMapper.ToObject <ItemConfig>(data[i]["ItemConfig"].ToJson());

            ItemData kg = null;
            switch (gp.Type)
            {
            case ItemType.Consumable:    //消耗品
                int HP = int.Parse(data[i]["HP"].ToString());
                int MP = int.Parse(data[i]["MP"].ToString());
                kg = new ConsumableData(HP, MP, gp);
                break;

            case ItemType.Equipment:    //装备
                int       strength      = int.Parse(data[i]["strength"].ToString());
                int       intellect     = int.Parse(data[i]["intellect"].ToString());
                int       agility       = int.Parse(data[i]["agility"].ToString());
                int       stamina       = int.Parse(data[i]["stamina"].ToString());
                EquipType equitmentType = (EquipType)System.Enum.Parse(typeof(EquipType), data[i]["equipType"].ToString());
                kg = new EquipData(strength, intellect, agility, stamina, equitmentType, gp);

                break;

            case ItemType.Meterial:    //材料

                break;

            case ItemType.Weapon:    //武器
                int        damage     = int.Parse(data[i]["damage"].ToString());
                WeaponType weaponType = (WeaponType)System.Enum.Parse(typeof(WeaponType), data[i]["weaponType"].ToString());
                kg = new WeaponData(damage, weaponType, gp);

                break;

            default:
                break;
            }

            listItemData.Add(kg);//放入容器中
        }
    }