Beispiel #1
0
    /// <summary>
    /// fills data from an FBClassData
    /// </summary>
    /// <param name="data">source data</param>
    /// <param name="dest">destination child object</param>
    /// <returns>true on success, false on failure</returns>
    public bool fillDataList(FBClassData data, GameObject dest = null)
    {
        List <FBClassObject> list = new List <FBClassObject>(data.objects.Count);

        foreach (KeyValuePair <int, FBClassObject> p in data.objects)
        {
            list.Add(p.Value);
        }
        return(fillDataList(list, dest));
    }
Beispiel #2
0
    /// <summary>
    /// sets a field value by its name
    /// </summary>
    /// <param name="fieldName">field name</param>
    /// <param name="value">value</param>
    /// <returns>true on success, false on failure</returns>
    public bool setFieldValue(string fieldName, FBValue value)
    {
        fieldValues[fieldName] = value;

        FBClassData classData = FBGameData.instance.getClassData(classId);

        if (classData != null)
        {
            classData.modified = true;
        }

        return(true);
    }
Beispiel #3
0
    public void ShowTextObject(string textID, GameObject obj)
    {
        FBClassData   TextObject = FBGameData.instance.getClassData("TextUIObject");
        FBClassObject objTmp     = TextObject.getObject("TextID", new FBValue(FBDataType.String, textID));
        string        name       = TextObject.getObject("TextID", new FBValue(FBDataType.String, textID)).getFieldValue("Name").stringValue;
        string        culture    = TextObject.getObject("TextID", new FBValue(FBDataType.String, textID)).getFieldValue("Culture").stringValue;
        string        author     = TextObject.getObject("TextID", new FBValue(FBDataType.String, textID)).getFieldValue("Author").stringValue;
        string        content    = TextObject.getObject("TextID", new FBValue(FBDataType.String, textID)).getFieldValue("Content").stringValue;

        obj.transform.findChildRecursively("Name").GetComponentInChildren <Text>().text    = name;
        obj.transform.findChildRecursively("Culture").GetComponentInChildren <Text>().text = culture;
        obj.transform.findChildRecursively("Author").GetComponentInChildren <Text>().text  = author;
        obj.transform.findChildRecursively("Content").GetComponentInChildren <Text>().text = content;

        obj.transform.findChildRecursively("UIManager").GetComponent <UIElement>().Show(true);
    }
Beispiel #4
0
    /// <summary>
    /// load saved class objects
    /// </summary>
    /// <param name="classId">class id</param>
    /// <param name="json">json string</param>
    /// <returns>true on success, false on failure</returns>
    bool loadSavedClassObjects(int classId, string json)
    {
        FBClassData loadedClassData = JsonConvert.DeserializeObject <FBClassData>(json);

        if (loadedClassData == null)
        {
            return(false);
        }

        FBClassData classData = FBGameData.instance.getClassData(classId);

#if MIX_SAVED_DATA_WITH_CONSTANT_DATA
        foreach (KeyValuePair <int, FBClassObject> p in loadedClassData.objects)
        {
            classData.addObject(p.Value);
        }
#else
        classData.objects = loadedClassData.objects;
#endif

        classData.nextObjectId = loadedClassData.nextObjectId;
        classData.modified     = false;
        return(true);
    }
Beispiel #5
0
    /// <summary>
    /// load all objects of a class
    /// </summary>
    /// <param name="json">json string</param>
    /// <returns>true on success, false on failure</returns>
    bool loadClassObjects(string json)
    {
        JObject           classDataJson    = JsonConvert.DeserializeObject(json) as JObject;
        FBClassData       classData        = getClassData((string)classDataJson["name"]);
        FBClassDefinition classDef         = classData.classDef;
        JArray            classObjectsJson = classDataJson["data"] as JArray;

        for (int i = 0; i < classObjectsJson.Count; i++)
        {
            JObject       classObjectJson = classObjectsJson[i] as JObject;
            int           id          = int.Parse((string)classObjectJson["id"]);
            FBClassObject classObject = new FBClassObject();
            classObject.id      = id;
            classObject.classId = classDef.id;
            foreach (KeyValuePair <string, FBClassField> p in classDef.fieldsByName)
            {
                FBValue val = new FBValue(p.Value.dataType, (string)classObjectJson[p.Value.name]);
                classObject.setFieldValue(p.Value.name, val);
            }
            classData.addObject(classObject);
        }
        classData.modified = false;
        return(true);
    }
Beispiel #6
0
    /// <summary>
    /// loads all class definition
    /// </summary>
    /// <param name="json">json string</param>
    /// <returns>true on success, false on failure</returns>
    bool loadAllClassDefinition(string json)
    {
        JArray classDefinesJson = JsonConvert.DeserializeObject(json) as JArray;

        for (int i = 0; i < classDefinesJson.Count; i++)
        {
            JObject           classDefineJson = classDefinesJson[i] as JObject;
            int               classId         = int.Parse((string)classDefineJson["id"]);
            string            className       = ((string)classDefineJson["name"]);
            JArray            classFields     = classDefineJson["data"] as JArray;
            FBClassDefinition classDefine     = new FBClassDefinition(classId, className);
            for (int j = 0; j < classFields.Count; j++)
            {
                JObject      classFieldJson = classFields[j] as JObject;
                string       fieldName      = ((string)classFieldJson["fieldName"]);
                FBDataType   fieldType      = (FBDataType)((int)classFieldJson["dataType"]);
                FBClassField classField     = new FBClassField(fieldName, fieldType);
                classDefine.setField(classField);
            }
            FBClassData classData = new FBClassData(classDefine);
            addClassData(classData);
        }
        return(true);
    }
Beispiel #7
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);
 }
    public void initInteractiveObjects(string sceneName, GameObject[] rootObjects)
    {
        sceneObject = FBGameData.instance.getClassData("UIObject");
        List <FBClassObject> interactiveObjects = sceneObject.getObjects("SceneName", new FBValue(sceneName));

        if (interactiveObjects.Count <= 0)
        {
            return;
        }

        Dictionary <string, SceneObject> objectDict = new Dictionary <string, SceneObject>();

        for (int i = 0; i < interactiveObjects.Count; i++)
        {
            string objectName = interactiveObjects[i].getFieldValue("ObjectName").stringValue;

            SceneObject scnObj = null;
            objectDict.TryGetValue(objectName, out scnObj);
            if (scnObj == null)
            {
                GameObject interactiveObject = null;
                for (int j = 0; j < rootObjects.Length; j++)
                {
                    Transform transform;
                    if (rootObjects[j].name == objectName)
                    {
                        transform = rootObjects[j].transform;
                    }
                    else
                    {
                        transform = rootObjects[j].transform.findChildRecursively(objectName);
                    }
                    if (transform)
                    {
                        interactiveObject = transform.gameObject;
                        break;
                    }
                }
                if (interactiveObject)
                {
                    scnObj = interactiveObject.addMissingComponent <SceneObject>();

                    GameObject temp    = Resources.Load <GameObject>("Prefabs/TextCanVas");
                    Transform  TextPos = scnObj.transform.findChildRecursively("TextPos");
                    if (TextPos)
                    {
                        GameObject createdObject = Instantiate(temp, TextPos);
                        createdObject.transform.position = TextPos.position;
                    }

                    objectDict[objectName] = scnObj;
                }
            }
            if (scnObj)
            {
                // set trigger and action
                SceneObject.instance.addEvent(interactiveObjects[i].getFieldValue("Trigger1").intValue, interactiveObjects[i].getFieldValue("Trigger2").intValue, interactiveObjects[i].getFieldValue("Trigger3").intValue,
                                              interactiveObjects[i].getFieldValue("Action1").intValue, interactiveObjects[i].getFieldValue("Action2").intValue, interactiveObjects[i].getFieldValue("Action3").intValue,
                                              interactiveObjects[i].getFieldValue("Param1").stringValue, interactiveObjects[i].getFieldValue("Param2").stringValue, interactiveObjects[i].getFieldValue("Param3").stringValue);
            }
        }
    }
Beispiel #9
0
 /// <summary>
 /// add a new class data
 /// </summary>
 /// <param name="classData">class data to add</param>
 /// <returns>true on success, false on failure</returns>
 bool addClassData(FBClassData classData)
 {
     classDataById[classData.classDef.id]     = classData;
     classDataByName[classData.classDef.name] = classData;
     return(true);
 }