示例#1
0
 public void Serialize(Blueprint blueprint)
 {
     using (var stream = new MemoryStream()) {
         _serializer.Serialize(stream, blueprint);
         blueprintData = stream.ToArray();
     }
 }
        /// Adds all components from the blueprint to the entity.
        /// When 'replaceComponents' is set to true entity.ReplaceComponent() will be used instead of entity.AddComponent().
        public Entity ApplyBlueprint(Blueprint blueprint, bool replaceComponents = false)
        {
            for (int i = 0, componentsLength = blueprint.components.Length; i < componentsLength; i++) {
                var componentBlueprint = blueprint.components[i];
                if (replaceComponents) {
                    ReplaceComponent(componentBlueprint.index, componentBlueprint.CreateComponent(this));
                } else {
                    AddComponent(componentBlueprint.index, componentBlueprint.CreateComponent(this));
                }
            }

            return this;
        }
示例#3
0
        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;
        }
        void Awake()
        {
            _allPools = findAllPools();
            if (_allPools == null) {
                return;
            }

            var binaryBlueprint = ((BinaryBlueprint)target);

            _allPoolNames = _allPools.Select(pool => pool.metaData.poolName).ToArray();

            BinaryBlueprintInspector.UpdateBinaryBlueprint(binaryBlueprint, _allPoolNames);

            _blueprint = binaryBlueprint.Deserialize();

            AssetDatabase.RenameAsset(AssetDatabase.GetAssetPath(target), _blueprint.name);

            _poolIndex = Array.IndexOf(_allPoolNames, _blueprint.poolIdentifier);
            switchToPool();

            _entity.ApplyBlueprint(_blueprint);

            EntityDrawer.Initialize();
        }
示例#5
0
 public void Serialize(Entity entity)
 {
     var blueprint = new Blueprint(entity.contextInfo.name, name, entity);
     Serialize(blueprint);
 }
        void Awake()
        {
            _allContexts = findAllContexts();
            if(_allContexts == null) {
                return;
            }

            var binaryBlueprint = ((BinaryBlueprint)target);

            _allContextNames = _allContexts.Select(context => context.contextInfo.name).ToArray();

            BinaryBlueprintInspector.UpdateBinaryBlueprint(binaryBlueprint, _allContexts, _allContextNames);

            _blueprint = binaryBlueprint.Deserialize();

            AssetDatabase.RenameAsset(AssetDatabase.GetAssetPath(target), _blueprint.name);

            _contextIndex = Array.IndexOf(_allContextNames, _blueprint.contextIdentifier);
            switchToContext();

            _entity.ApplyBlueprint(_blueprint);

            EntityDrawer.Initialize();
        }
 public void Serialize(Entity entity)
 {
     var blueprint = new Blueprint(entity.poolMetaData.poolName, name, entity);
     Serialize(blueprint);
 }