Beispiel #1
0
        private LDtkComponentLevel CreateLevelGameObject()
        {
            _levelGameObject      = _importer.CustomLevelPrefab ? LDtkPrefabFactory.Instantiate(_importer.CustomLevelPrefab) : new GameObject();
            _levelGameObject.name = _level.Identifier;

            _levelGameObject.transform.position = _level.UnityWorldSpaceCoord(_importer.PixelsPerUnit);

            if (_importer.DeparentInRuntime)
            {
                _levelGameObject.AddComponent <LDtkDetachChildren>();
            }



            LDtkComponentLevel levelComponent = _levelGameObject.AddComponent <LDtkComponentLevel>();

            levelComponent.SetIdentifier(_level.Identifier);
            levelComponent.SetSize((Vector2)_level.UnityPxSize / _importer.PixelsPerUnit);
            levelComponent.SetBgColor(_level.UnityBgColor);

            //interface events
            MonoBehaviour[] behaviors = _levelGameObject.GetComponents <MonoBehaviour>();

            if (!_json.Defs.LevelFields.IsNullOrEmpty())
            {
                LDtkFieldParser.CacheRecentBuilder(null);
                LDtkFieldInjector fieldInjector = new LDtkFieldInjector(_levelGameObject, _level.FieldInstances);
                fieldInjector.InjectEntityFields();
                LDtkInterfaceEvent.TryEvent <ILDtkImportedFields>(behaviors, level => level.OnLDtkImportFields(fieldInjector.FieldsComponent));
            }

            LDtkInterfaceEvent.TryEvent <ILDtkImportedLevel>(behaviors, level => level.OnLDtkImportLevel(_level));

            return(levelComponent);
        }
Beispiel #2
0
        public void BuildEntityLayerInstances()
        {
            if (Importer.DeparentInRuntime)
            {
                LayerGameObject.AddComponent <LDtkDetachChildren>();
            }

            SortingOrder.Next();

            LDtkFieldParser.CacheRecentBuilder(this);

            foreach (EntityInstance entityData in Layer.EntityInstances)
            {
                GameObject entityPrefab = Importer.GetEntity(entityData.Identifier);
                BuildEntityInstance(entityData, entityPrefab);
            }
        }
Beispiel #3
0
        private object GetParsedValue(FieldInstance fieldInstanceType, object value)
        {
            ParseFieldValueAction action = LDtkFieldParser.GetParserMethodForType(fieldInstanceType);

            return(action?.Invoke(value));
        }