Entitas.Unity.Serialization.Blueprints.BinaryBlueprint.Deserialize C# (CSharp) Method

Deserialize() public method

public Deserialize ( ) : Blueprint
return Entitas.Serialization.Blueprints.Blueprint
        public Blueprint Deserialize()
        {
            Blueprint blueprint;
            if(blueprintData == null || blueprintData.Length == 0) {
                blueprint = new Blueprint(string.Empty, "New Blueprint", new Entity(0, null, null));
            } else {
                using (var stream = new MemoryStream(blueprintData)) {
                    blueprint = (Blueprint)_serializer.Deserialize(stream);
                }
            }

            name = blueprint.name;
            return blueprint;
        }

Usage Example

        public static bool UpdateBinaryBlueprint(BinaryBlueprint binaryBlueprint, Context[] allContexts, string[] allContextNames)
        {
            var blueprint = binaryBlueprint.Deserialize();
            var needsUpdate = false;

            var contextIndex = Array.IndexOf(allContextNames, blueprint.contextIdentifier);
            if(contextIndex < 0) {
                contextIndex = 0;
                needsUpdate = true;
            }

            var context = allContexts[contextIndex];
            blueprint.contextIdentifier = context.contextInfo.name;

            foreach(var component in blueprint.components) {
                var type = component.fullTypeName.ToType();
                var index = Array.IndexOf(context.contextInfo.componentTypes, type);

                if(index != component.index) {
                    Debug.Log(string.Format(
                        "Blueprint '{0}' has invalid or outdated component index for '{1}'. Index was {2} but should be {3}. This will be fixed now!",
                        blueprint.name, component.fullTypeName, component.index, index));

                    component.index = index;
                    needsUpdate = true;
                }
            }

            if(needsUpdate) {
                Debug.Log("Updating Blueprint '" + blueprint.name + "'");
                binaryBlueprint.Serialize(blueprint);
            }

            return needsUpdate;
        }
All Usage Examples Of Entitas.Unity.Serialization.Blueprints.BinaryBlueprint::Deserialize