Пример #1
0
    void ConstructCombinationMapDatabase()
    {
        Dictionary <int, FBClassObject> listAllItems = FBGameData.instance.getClassData("CombinationMap").objects;

        foreach (KeyValuePair <int, FBClassObject> item in listAllItems)
        {
            FBClassObject  itemData = item.Value;
            CombinationMap newMap   = new CombinationMap();
            newMap.ItemId01    = itemData.getFieldValue("itemId01").intValue;
            newMap.ItemId02    = itemData.getFieldValue("itemId02").intValue;
            newMap.ItemIdFinal = itemData.getFieldValue("itemidFinal").intValue;
            newMap.Duration    = itemData.getFieldValue("duration").floatValue;
            //newItem.Prefabs = FBPoolManager.instance.getPoolObject(newItem.prefabName);

            combinationDatabase.Add(newMap);
        }
    }
Пример #2
0
 /// <summary>
 /// returns a string to display on ui
 /// </summary>
 /// /// <param name="id2name">convert class object id to name if possible</param>
 /// <returns>string</returns>
 public string getDisplayString(bool id2name = false)
 {
     if (dataType >= FBDataType.Class1)
     {
         if (id2name)
         {
             // try to return object name instead of id
             FBClassData   classData   = FBGameData.instance.getClassData((int)dataType);
             FBClassObject classObject = classData.getObject(intValue);
             if (classObject == null)
             {
                 return(intValue.ToString());
             }
             FBValue val = classObject.getFieldValue("Name");
             if (val != null)
             {
                 return(val.stringValue);
             }
             val = classObject.getFieldValue("name");
             if (val != null)
             {
                 return(val.stringValue);
             }
         }
         return(intValue.ToString());
     }
     if (dataType == FBDataType.Int)
     {
         return(intValue.ToString());
     }
     if (dataType == FBDataType.Float)
     {
         return(floatValue.ToString());
     }
     return(stringValue);
 }
Пример #3
0
    void ConstructItemDatabase()
    {
        Dictionary <int, FBClassObject> listAllItems = FBGameData.instance.getClassData("GroupGameItems").objects;

        foreach (KeyValuePair <int, FBClassObject> item in listAllItems)
        {
            FBClassObject itemData = item.Value;
            Item          newItem  = new Item();
            newItem.Id            = (int)itemData.getFieldValue("itemId").intValue;
            newItem.Title         = itemData.getFieldValue("title").stringValue;
            newItem.Power         = (int)itemData.getFieldValue("power").floatValue;
            newItem.Description   = itemData.getFieldValue("description").stringValue;
            newItem.iconName      = itemData.getFieldValue("iconName").stringValue;
            newItem.prefabName    = itemData.getFieldValue("prefabName").stringValue;
            newItem.Sprite        = Resources.Load <Sprite>("Prefabs/UI/Sprites/Items/" + newItem.iconName);
            newItem.Stackable     = itemData.getFieldValue("stackable").intValue;
            newItem.ReceiveItemId = itemData.getFieldValue("receiveItemId").intValue;
            //newItem.Prefabs = FBPoolManager.instance.getPoolObject(newItem.prefabName);

            itemDatabase.Add(newItem);
        }
    }
Пример #4
0
    /// <summary>
    /// returns a list of objects which match the condition
    /// </summary>
    /// <param name="fieldNames">field names</param>
    /// <param name="values">field values</param>
    /// <returns>list of objects which match the condition</returns>
    public List <FBClassObject> getObjects(string[] fieldNames, FBValue[] values)
    {
        List <FBClassObject> list = new List <FBClassObject>();

        foreach (KeyValuePair <int, FBClassObject> p in objects)
        {
            FBClassObject obj   = p.Value;
            bool          equal = true;
            for (int i = 0; i < fieldNames.Length; i++)
            {
                if (!obj.getFieldValue(fieldNames[i]).equals(values[i]))
                {
                    equal = false;
                    break;
                }
            }
            if (equal)
            {
                list.Add(p.Value);
            }
        }
        return(list);
    }
Пример #5
0
    /// <summary>
    /// fills data from an FBClassObject
    /// </summary>
    /// <param name="data">source data</param>
    /// <returns>true on success, false on failure</returns>
    public bool fillData(FBClassObject data)
    {
        this.data = data;

        if (string.IsNullOrEmpty(fieldName))
        {
            return(false);            // not a field
        }
        FBValue val = data.getFieldValue(fieldName);

        if (val == null)
        {
            return(false);            // not this field
        }
        if (text)
        {
            text.text = val.getDisplayString(true);
        }

        if (image && val.dataType == FBDataType.Image)
        {
            string imageName = FBGameData.instance.pathToDatabaseResources + val.stringValue;
            imageName    = imageName.Substring(0, imageName.LastIndexOf("."));
            image.sprite = Resources.Load <Sprite>(imageName);
        }

        if (isModel3D)
        {
            // TODO: clean up and optimize
            // clean up
            transform.destroyChildren();

            // since we are going to modify the model, we must clone a pooled object instead of directly using it
            GameObject poolObject = FBPoolManager.instance.getPoolObject(val.stringValue);
            model3D = GameObject.Instantiate <GameObject>(poolObject, transform);
            FBPoolManager.instance.returnObjectToPool(poolObject);
            model3D.transform.localPosition = Vector3.zero;
            //model3D.transform.localRotation = Quaternion.identity;
            //model3D.transform.localScale = Vector3.one;
            model3D.transform.localRotation = Quaternion.Euler(model3D.transform.localRotation.eulerAngles.x, model3D.transform.localRotation.eulerAngles.y - 90, model3D.transform.localRotation.eulerAngles.z);

            // cannot activate 3d model here
            // script components will run and mess up
            Invoke("activateModel3D", 0.1f);             // model3D.SetActive(true);

            // only keep ui components
            string[]    componentsToKeep = new string[] { "Transform", "MeshRenderer", "MeshFilter" };
            Component[] components       = model3D.GetComponentsInChildren <Component>(true);
            for (int i = 0; i < components.Length; i++)
            {
                string typeName = components[i].GetType().Name;
                bool   remove   = true;
                for (int j = 0; j < componentsToKeep.Length; j++)
                {
                    if (typeName == componentsToKeep[j])
                    {
                        remove = false;
                        break;
                    }
                }
                if (remove)
                {
                    GameObject.Destroy(components[i] as UnityEngine.Object);
                }
            }

            model3DSize = 0;
        }

        return(true);
    }