예제 #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 BuildEntityInstance(EntityInstance entityData, GameObject entityPrefab)
        {
            GameObject entityObj = LDtkPrefabFactory.Instantiate(entityPrefab);

            entityObj.name = GetEntityGameObjectName(entityPrefab.name);

            PositionEntity(entityData, entityObj);
            ScaleEntity(entityData, entityObj);
            AddFieldData(entityData, entityObj);
        }
예제 #3
0
        private void BuildEntityInstance(EntityInstance entityData, GameObject entityPrefab)
        {
            GameObject entityObj;

            if (entityPrefab)
            {
                entityObj      = LDtkPrefabFactory.Instantiate(entityPrefab);
                entityObj.name = GetEntityGameObjectName(entityPrefab.name);
            }
            else
            {
                entityObj      = new GameObject();
                entityObj.name = GetEntityGameObjectName(entityData.Identifier);
            }

            PositionEntity(entityData, entityObj);
            ScaleEntity(entityData, entityObj);
            AddFieldData(entityData, entityObj);
        }