Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.Linq;
- using System.Xml.Linq;
- using Guedez.Database;
- using Unity.Entities;
- using UnityEngine;
- using static EntityProcessor;
- [LoaderType("equip")]
- public class EquipmentProcessor : Processor {
- public EquipmentProcessor(bool isContainer) : base(isContainer) {
- }
- public struct BlendMod {
- public string name;
- public int value;
- }
- public class EquipmentDefinition {
- //public enum ItemClothSlots {
- // Hair, Head, Neck, Torso_INNER, Torso_MID, Torso_OUTER, Arms, Legs, Feet, Hand_Left, Hand_Right, Hand_Any, Gloves, Belt
- //}
- //public enum EquipperType {
- // DEFAULT, ADAM, GIRLS_HUMANOID, GIRLS_HALF
- //}
- public GameObject prefab;
- public bool selfBoned;
- public string attachBone;
- public BlendMod[] blends;
- public string[] types;
- public string[] slots = new string[0];
- public long entity;
- public ItemBehaviour[] behaviours = new ItemBehaviour[0];
- }
- private static readonly Dictionary<long, EquipmentDefinition> equips = new Dictionary<long, EquipmentDefinition>();
- internal static string[] types;
- internal static string[] slots;
- private static HashSet<string> _types;
- private static HashSet<string> _slots;
- public override void OnStartDatabaseLoad() {
- equips.Clear();
- _types = new HashSet<string>();
- _slots = new HashSet<string>();
- }
- public override void OnEndDatabaseLoad() {
- types = _types.ToArray();
- slots = _slots.ToArray();
- }
- public override object ProcessType(XElement element, List<object> parents) {
- DatabaseEntity entity = DatabaseLoader.GetFirst<DatabaseEntity>(parents);
- if (entity == null) {
- Debug.LogWarning("No entity to add Item to");
- return null;
- }
- EquipmentDefinition item;
- if (!equips.TryGetValue(entity.identifier, out item)) {
- item = new EquipmentDefinition();
- }
- item.prefab = DatabaseLoader.LoadResource<GameObject>(element.Element("prefab"));
- if (item.prefab == null) {
- return null;
- }
- equips[entity.identifier] = item;
- item.selfBoned = element.Element("selfBoned") != null;
- item.attachBone = DatabaseLoader.GetElementValueOrDefault(element.Element("attachBone"));
- item.entity = entity.identifier;
- item.slots = DatabaseLoader.GetElementValueAsList<string>(element.Elements("slot"));
- foreach (string s in item.slots) {
- _slots.Add(s.ToLower());
- }
- item.types = DatabaseLoader.GetElementValueAsList<string>(element.Elements("type"));
- item.blends = DatabaseLoader.GetElementValueAsList<BlendMod>(element.Elements("blend"));
- foreach (string t in item.types) {
- _types.Add(t.ToLower());
- }
- item.behaviours = loadBehaviours(element.Elements("behaviour"));
- //public GameObject prefab;
- //public bool selfBoned;
- //public string attachBone;
- //public string type;
- //public string[] slots = new string[0];
- //public long entity;
- //public ItemBehaviour[] behaviours = new ItemBehaviour[0];
- //< prefab > Items / Equipment / Seeds / Carrot Seed / Carrot Seed Bag</ prefab >
- //< !--< selfBoned /> -->
- //< attachBone > hand_R </ attachBone >
- //< type > ALL </ type >
- //< slots >
- // < slot > MainHand </ slot >
- //</ slots >
- //< behaviour > Items / Equipment / Seeds / Carrot Seed / Carrot Seed Bag Behaiour </ behaviour >
- return item;
- }
- private ItemBehaviour[] loadBehaviours(IEnumerable<XElement> enumerable) {
- //
- List<ItemBehaviour> behavs = new List<ItemBehaviour>();
- foreach (XElement els in enumerable) {
- behavs.Add(loadBehaviour(els));
- }
- return behavs.ToArray();
- }
- private ItemBehaviour loadBehaviour(XElement els) {
- XElement path = els.Element("path");
- if (path != null) {
- ItemBehaviour itb = GameObject.Instantiate(DatabaseLoader.LoadResource<ItemBehaviour>(path));
- itb.loadProps(els);
- return itb;
- } else {
- return DatabaseLoader.LoadResource<ItemBehaviour>(els);
- }
- }
- public IEnumerable<KeyValuePair<long, EquipmentDefinition>> GetEquipmentsAndIndex() {
- return equips;
- }
- public IEnumerable<EquipmentDefinition> GetEquipments() {
- return equips.Values;
- }
- public EquipmentDefinition getEquipmentDef(long reference) {
- EquipmentDefinition ret;
- if (equips.TryGetValue(reference, out ret)) {
- return ret;
- }
- return null;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment