예제 #1
0
        public void SerializeSingleGlobalStateConditionTest()
        {
            var serializedGlobalStateCondition = JsonUtility.ToJson(globalStateCondition);

            Debug.Log(serializedGlobalStateCondition);
            var restoredGlobalStateCondition = JsonUtility.FromJson <GlobalStateCondition>(serializedGlobalStateCondition);

            Assert.NotNull(restoredGlobalStateCondition);
            Assert.AreEqual(globalStateCondition.GetType(), restoredGlobalStateCondition.GetType());
            Assert.AreEqual(globalStateCondition.getType(), restoredGlobalStateCondition.getType());
            Assert.AreEqual(globalStateCondition.getState(), restoredGlobalStateCondition.getState());
        }
예제 #2
0
        private static XmlElement createConditionElement(XmlDocument doc, Condition condition)
        {
            XmlElement conditionElement = null;

            if (condition.getType() == Condition.FLAG_CONDITION)
            {
                // Create the tag
                if (condition.getState() == FlagCondition.FLAG_ACTIVE)
                {
                    conditionElement = doc.CreateElement("active");
                }
                else if (condition.getState() == FlagCondition.FLAG_INACTIVE)
                {
                    conditionElement = doc.CreateElement("inactive");
                }

                // Set the target flag and append it
                conditionElement.SetAttribute("flag", condition.getId());
            }
            else if (condition.getType() == Condition.VAR_CONDITION)
            {
                VarCondition varCondition = (VarCondition)condition;
                // Create the tag
                if (varCondition.getState() == VarCondition.VAR_EQUALS)
                {
                    conditionElement = doc.CreateElement("equals");
                }
                else if (varCondition.getState() == VarCondition.VAR_NOT_EQUALS)
                {
                    conditionElement = doc.CreateElement("not-equals");
                }
                else if (condition.getState() == VarCondition.VAR_GREATER_EQUALS_THAN)
                {
                    conditionElement = doc.CreateElement("greater-equals-than");
                }
                else if (condition.getState() == VarCondition.VAR_GREATER_THAN)
                {
                    conditionElement = doc.CreateElement("greater-than");
                }
                else if (condition.getState() == VarCondition.VAR_LESS_EQUALS_THAN)
                {
                    conditionElement = doc.CreateElement("less-equals-than");
                }
                else if (condition.getState() == VarCondition.VAR_LESS_THAN)
                {
                    conditionElement = doc.CreateElement("less-than");
                }

                // Set the target flag and append it
                conditionElement.SetAttribute("var", varCondition.getId());
                conditionElement.SetAttribute("value", varCondition.getValue().ToString());
            }
            else if (condition.getType() == Condition.GLOBAL_STATE_CONDITION)
            {
                GlobalStateCondition globalStateCondition = (GlobalStateCondition)condition;
                // Create the tag
                conditionElement = doc.CreateElement("global-state-ref");

                // Set the target flag and append it
                conditionElement.SetAttribute("id", globalStateCondition.getId());

                conditionElement.SetAttribute("value",
                                              globalStateCondition.getState() == GlobalStateCondition.GS_SATISFIED ? "true" : "false");
            }

            return(conditionElement);
        }