Ejemplo n.º 1
0
        public static SimulationSceneDescription Decode(JObject json)
        {
            // Version
            int version = json[CodingKey.Version].ToInt();
            // Camera Control Points
            var controlPoints = json[CodingKey.CameraControlPoints].ToArray(CameraControlPoint.Decode);
            // Drop Height
            var dropHeight = json[CodingKey.DropHeight].ToFloat();
            // Physics Config
            var physicsConfig = ScenePhysicsConfiguration.Decode(json.ObjectForKey(CodingKey.PhysicsConfig));
            // Structures
            var encodedStructures = json[CodingKey.Structures].ToList();
            var structures        = new IStructure[encodedStructures.Count];

            for (int i = 0; i < encodedStructures.Count; i++)
            {
                var structureContainer = encodedStructures[i];
                var encodingID         = structureContainer[CodingKey.EncodingID].ToString();
                if (!registeredStructures.ContainsKey(encodingID))
                {
                    Debug.LogError(string.Format("Structure with encodingID {0} cannot be decoded!", encodingID));
                    continue;
                }
                var decodingFunc     = registeredStructures[encodingID];
                var encodedStructure = structureContainer[CodingKey.StructureData] as JObject;
                structures[i] = decodingFunc(encodedStructure);
            }

            return(new SimulationSceneDescription(version, structures, dropHeight, physicsConfig, controlPoints));
        }
Ejemplo n.º 2
0
 public SimulationSceneDescription(
     int version, IStructure[] structures, float dropHeight,
     ScenePhysicsConfiguration physicsConfiguration,
     CameraControlPoint[] controlPoints
     )
 {
     this.Version              = version;
     this.Structures           = structures;
     this.DropHeight           = dropHeight;
     this.PhysicsConfiguration = physicsConfiguration;
     this.CameraControlPoints  = controlPoints;
 }