Пример #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);
        }
Пример #2
0
        private void AddFieldData(EntityInstance entityData, GameObject entityObj)
        {
            LDtkFieldInjector fieldInjector = new LDtkFieldInjector(entityObj, entityData.FieldInstances);

            fieldInjector.InjectEntityFields();

            //TODO add drawers back. probably make it a scene drawer section of the component drawer of LDtkFields

            /*foreach (InjectorDataPair injectorData in fieldInjector.InjectorData)
             * {
             *  TryAddPointDrawer(injectorData.Data, injectorData.Field, entityData, (int)Layer.GridSize);
             * }*/


            MonoBehaviour[] behaviors = entityObj.GetComponents <MonoBehaviour>();

            PostEntityInterfaceEvent <ILDtkImportEvent>(behaviors, e => e.OnLDtkImport());
            PostEntityInterfaceEvent <ILDtkSettableSortingOrder>(behaviors, e => e.OnLDtkSetSortingOrder(SortingOrder.SortingOrderValue));
            PostEntityInterfaceEvent <ILDtkSettableColor>(behaviors, e => e.OnLDtkSetEntityColor(entityData.Definition.UnityColor));
            PostEntityInterfaceEvent <ILDtkSettableOpacity>(behaviors, e => e.OnLDtkSetOpacity((float)Layer.Opacity));
        }
Пример #3
0
        private void CreateLevelGameObject()
        {
            _levelGameObject = new GameObject(_level.Identifier);
            _levelGameObject.transform.position = _level.UnityWorldSpaceCoord(_importer.PixelsPerUnit);

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

            if (!_json.Defs.LevelFields.IsNullOrEmpty())
            {
                LDtkFieldInjector fieldInjector = new LDtkFieldInjector(_levelGameObject, _level.FieldInstances);
                fieldInjector.InjectEntityFields();
            }

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

            boundsDrawer.SetSize((Vector2)_level.UnityPxSize / _importer.PixelsPerUnit);
            boundsDrawer.SetBgColor(_level.UnityBgColor);
        }