示例#1
0
        public static T LoadFromFile(string filePath, out string errorOnLoad)
        {
            var storage = GetInterface <IDataStorage>();

            if (storage == null)
            {
                throw new Exception($"No {nameof(IDataStorage)} defined in the AssetManager bridge.");
            }

            if (!storage.Exists(filePath))
            {
                throw new FileNotFoundException();
            }

            var data = storage.Load(filePath);
            T   asset;

            try
            {
                asset = SERIALIZER.DeserializeFromJson <T>((JsonObject)JsonParser.Parse(data));
            }
            catch (Exception e)
            {
                errorOnLoad = e.Message + "\n" + e.StackTrace;
                return(null);
            }
            asset.m_assetFilepath = filePath;
            errorOnLoad           = asset.OnAssetLoaded();
            return(asset);
        }
示例#2
0
        public static Quaternion GetQuaternion(string Key)
        {
            string k = EncryptionUtility.XOREncrypt(Key);

            if (PlayerPrefs.HasKey(k))
            {
                string json = PlayerPrefs.GetString(k, string.Empty);
                return(Quaternion.Euler(JSONSerializer.DeserializeFromJson <Vector3>(json, true)));
            }
            return(Quaternion.identity);
        }
示例#3
0
        public static Color GetColor(string key)
        {
            string k = EncryptionUtility.XOREncrypt(key);

            if (PlayerPrefs.HasKey(k))
            {
                string json = PlayerPrefs.GetString(k, string.Empty);
                return(JSONSerializer.DeserializeFromJson <Color>(json, true));
            }
            return(Color.clear);
        }
示例#4
0
        public static Vector3 GetVector3(string key)
        {
            string k = EncryptionUtility.XOREncrypt(key);

            if (PlayerPrefs.HasKey(k))
            {
                string json = PlayerPrefs.GetString(k);

                return(JSONSerializer.DeserializeFromJson <Vector3>(json, false));
            }
            return(Vector3.zero);
        }
        public static void CustomClassSerializationTest()
        {
            SerializationServices.AssemblyLoader = assemblyLoader;
            SerializationServices.InstanceFactory = factory;

            var value = new SerializationTestClass();

            var serializer = new JSONSerializer();
            var json = serializer.SerializeToJson(value);
            json.Write(Console.Out, true);
            var other = serializer.DeserializeFromJson<SerializationTestClass>(json);

            Assert.IsNull(other.VolatileField);
        }
        public static IntegratedAuthoringToolAsset FromJson(string json, AssetStorage storage)
        {
            var serializer = new JSONSerializer();
            var aux        = (JsonObject)JsonParser.Parse(json);
            var iat        = serializer.DeserializeFromJson <IntegratedAuthoringToolAsset>(aux);

            foreach (var c in iat.Characters)
            {
                c.LoadAssociatedAssets(storage);
                iat.BindToRegistry(c.DynamicPropertiesRegistry);
            }
            iat.Assets = storage;
            return(iat);
        }
示例#7
0
        public static void CustomClassSerializationTest()
        {
            //TODO: Ask Pedro

            /*SerializationServices.AssemblyLoader = assemblyLoader;
             *          SerializationServices.InstanceFactory = factory;*/

            var value = new SerializationTestClass();

            var serializer = new JSONSerializer();
            var json       = serializer.SerializeToJson(value);

            json.Write(Console.Out, true);
            var other = serializer.DeserializeFromJson <SerializationTestClass>(json);

            Assert.IsNull(other.VolatileField);
        }
示例#8
0
        public static T CreateInstance(AssetStorage storage)
        {
            var config = storage.GetComponentConfiguration(typeof(T).Name);

            if (config == null)
            {
                var res = new T();
                res.storage = storage;
                res.Save();
                return(res);
            }
            else
            {
                var aux = (JsonObject)JsonParser.Parse(config);
                var res = SERIALIZER.DeserializeFromJson <T>(aux);
                res.storage = storage;
                return(res);
            }
        }
示例#9
0
        //This is where the main body of the MCTS Search must be implemented
        private IEnumerable <DynamicPropertyResult> MCTSSearch(IQueryContext context, Name actionVar, Name targetVar)
        {
            //How to clone the KB with our JSON serializer
            var jsonSerializer = new JSONSerializer();
            var memStream      = new MemoryStream();
            var json           = jsonSerializer.SerializeToJson(this.m_kb);
            var kbCloned       = jsonSerializer.DeserializeFromJson <KB>(json);

            //This is just an example of how to always return the action "Pick" with target "Wood1"
            var actionSub = new Substitution(actionVar, new ComplexValue(Name.BuildName("Pick")));
            var targetSub = new Substitution(targetVar, new ComplexValue(Name.BuildName("Wood1")));

            foreach (var subSet in context.Constraints)
            {
                subSet.AddSubstitution(actionSub);
                subSet.AddSubstitution(targetSub);

                yield return(new DynamicPropertyResult(new ComplexValue(Name.BuildName(true), 1.0f), subSet));
            }
        }
示例#10
0
        //This is where the main body of the MCTS Search must be implemented
        private IEnumerable <DynamicPropertyResult> MCTSSearch(IQueryContext context, Name actionVar, Name targetVar)
        {
            //How to clone the KB with our JSON serializer
            var jsonSerializer = new JSONSerializer();
            var memStream      = new MemoryStream();
            var json           = jsonSerializer.SerializeToJson(this.m_kb);
            var kbCloned       = jsonSerializer.DeserializeFromJson <KB>(json);

            //Escrever comentário

            if (this.NextActionInfo.Item1 != "")
            {
                NextAction PriorityAction = new NextAction(NextActionInfo.Item1, kbCloned);

                if (this.NextActionInfo.Item2 <= 1)
                {
                    this.NextActionInfo = new Pair <string, int>("", 0);
                }
                else
                {
                    this.NextActionInfo.Item2 -= 1;
                }

                Pair <string, string> pairOfPriorityAction = PriorityAction.ConstructNextAction();
                this.ToDoActionsList.Add(pairOfPriorityAction);
            }

            if (this.ToDoActionsList.Count == 0)
            {
                PreWorldState preWorldState = new PreWorldState(kbCloned);
                //, this.UnequippableTorches, this.EquippedItems);

                WorldModelDST worldModel = new WorldModelDST(preWorldState);

                foreach (var action in worldModel.AvailableActions)
                {
                    Console.WriteLine(action.Name);
                }
                Console.WriteLine("");

                this.Mcts = new MCTSAlgorithm(worldModel);
                this.Mcts.InitializeMCTSearch();

                ActionDST MacroAction = this.Mcts.Run();
                //this.LastActionInfo = MacroAction.Name;
                this.ToDoActionsList = MacroAction.Decompose(preWorldState);

                this.NextActionInfo       = MacroAction.NextActionInfo();
                this.NextActionInfo.Item1 = preWorldState.CompleteNextActionInfo(this.NextActionInfo.Item1);
            }

            Pair <string, string> CurrentAction = this.ToDoActionsList[0];

            this.ToDoActionsList.Remove(CurrentAction);

            Console.WriteLine("Next Action:");
            Console.WriteLine(CurrentAction.Item1 + " " + CurrentAction.Item2);
            Console.WriteLine("");

            //UpdateEquippedItems(CurrentAction);

            var actionSub = new Substitution(actionVar, new ComplexValue(Name.BuildName(CurrentAction.Item1)));
            var targetSub = new Substitution(targetVar, new ComplexValue(Name.BuildName(CurrentAction.Item2)));

            //var actionSub = new Substitution(actionVar, new ComplexValue(Name.BuildName("Action(WALKTO, -, "+ posxWalter.ToString() +", " + poszWalter.ToString() + ", -)")));
            //var targetSub = new Substitution(targetVar, new ComplexValue(Name.BuildName("-")));

            foreach (var subSet in context.Constraints)
            {
                subSet.AddSubstitution(actionSub);
                subSet.AddSubstitution(targetSub);

                yield return(new DynamicPropertyResult(new ComplexValue(Name.BuildName(true), 1.0f), subSet));
            }
        }
示例#11
0
        public static T Clone <T> (T obj)
        {
            var json = serializer.SerializeToJson(obj);

            return(serializer.DeserializeFromJson <T>(json));
        }