Пример #1
0
        private SuperLayer ProcessTileLayer(GameObject goParent, XElement xLayer)
        {
            Assert.IsNotNull(xLayer);
            Assert.IsNotNull(goParent);

            // Create the game object that contains the layer and add it to the grid parent
            var layerComponent = goParent.AddSuperLayerGameObject <SuperTileLayer>(new SuperTileLayerLoader(xLayer), SuperImportContext);

            AddSuperCustomProperties(layerComponent.gameObject, xLayer.Element("properties"));
            RendererSorter.BeginTileLayer(layerComponent);

            using (SuperImportContext.BeginIsTriggerOverride(layerComponent.gameObject))
            {
                // Process the data for the layer
                var xData = xLayer.Element("data");
                if (xData != null)
                {
                    ProcessLayerData(layerComponent.gameObject, xData);
                }
            }

            RendererSorter.EndTileLayer(layerComponent);

            return(layerComponent);
        }
        private SuperLayer ProcessObjectLayer(GameObject goParent, XElement xObjectLayer)
        {
            // Have our super object layer loader take care of things
            var loader = new SuperObjectLayerLoader(xObjectLayer);

            loader.AnimationFramerate = SuperImportContext.Settings.AnimationFramerate;
            loader.ColliderFactory    = CreateColliderFactory();
            loader.SuperMap           = m_MapComponent;
            loader.Importer           = this;
            loader.GlobalTileDatabase = m_GlobalTileDatabase;

            // Create our layer and objects
            var objectLayer = goParent.AddSuperLayerGameObject <SuperObjectLayer>(loader, SuperImportContext);

            AddSuperCustomProperties(objectLayer.gameObject, xObjectLayer.Element("properties"));

            RendererSorter.BeginObjectLayer(objectLayer);

            using (SuperImportContext.BeginIsTriggerOverride(objectLayer.gameObject))
            {
                loader.CreateObjects();
            }

            RendererSorter.EndObjectLayer(objectLayer);

            return(objectLayer);
        }
Пример #3
0
        private Tilemap GetOrAddTilemapComponent(GameObject go)
        {
            if (RendererSorter.IsUsingGroups())
            {
                // If we have a group layer parent then use it instead as we are grouping tiles on the same tilemap (using the z-component of the tile location)
                var grouping = go.GetComponentInParent <SuperGroupLayer>();
                if (grouping != null)
                {
                    // The Tilemap will go onto the group layer
                    go = grouping.gameObject;
                }
            }

            // If we already have a Tilemap component then use it
            var tilemap = go.GetComponent <Tilemap>();

            if (tilemap != null)
            {
                return(tilemap);
            }

            tilemap = go.AddComponent <Tilemap>();
            tilemap.animationFrameRate = SuperImportContext.Settings.AnimationFramerate;
            tilemap.tileAnchor         = new Vector3(0, 0, 0);

            AddTilemapRendererComponent(go);

            // Figure out our opacity
            var layer = go.GetComponent <SuperLayer>();

            tilemap.color = layer.CalculateColor();

            return(tilemap);
        }
Пример #4
0
        protected override void InternalOnImportAssetCompleted()
        {
            m_RendererSorter          = null;
            m_NumberOfObjectsImported = SuperImportContext.GetNumberOfObjects();

            // Assets should be dirtied upon importing so that their meta files are serialized
            // Without this we may end up with old garbage in our meta files
            EditorUtility.SetDirty(this);
        }
        private GameObject ProcessGroupLayer(GameObject goParent, XElement xGroup)
        {
            var groupLayerComponent = goParent.AddSuperLayerGameObject <SuperGroupLayer>(new SuperGroupLayerLoader(xGroup), SuperImportContext);

            AddSuperCustomProperties(groupLayerComponent.gameObject, xGroup.Element("properties"));

            // Group layers can contain other layers
            RendererSorter.BeginGroupLayer(groupLayerComponent);
            ProcessMapLayers(groupLayerComponent.gameObject, xGroup);
            RendererSorter.EndGroupLayer();

            return(groupLayerComponent.gameObject);
        }
        private Tilemap GetOrAddTilemapComponent(GameObject go)
        {
            if (RendererSorter.IsUsingGroups())
            {
                // If we have a group layer parent then use it instead as we are grouping tiles on the same tilemap (using the z-component of the tile location)
                var grouping = go.GetComponentInParent <SuperGroupLayer>();
                if (grouping != null)
                {
                    // The Tilemap will go onto the group layer
                    go = grouping.gameObject;
                }
            }

            // If we already have a Tilemap component then use it
            var tilemap = go.GetComponent <Tilemap>();

            if (tilemap != null)
            {
                return(tilemap);
            }

            tilemap                    = go.AddComponent <Tilemap>();
            tilemap.tileAnchor         = Vector2.zero;
            tilemap.animationFrameRate = SuperImportContext.Settings.AnimationFramerate;

            if (m_MapComponent.m_Orientation == MapOrientation.Hexagonal)
            {
                tilemap.orientation = Tilemap.Orientation.Custom;

                float ox = SuperImportContext.MakeScalar(m_MapComponent.m_TileWidth) * 0.5f;
                float oy = SuperImportContext.MakeScalar(m_MapComponent.m_TileHeight) * 0.5f;
                tilemap.orientationMatrix = Matrix4x4.Translate(new Vector3(-ox, -oy));
            }
            else if (m_MapComponent.m_Orientation == MapOrientation.Isometric || m_MapComponent.m_Orientation == MapOrientation.Staggered)
            {
                tilemap.orientation = Tilemap.Orientation.Custom;

                float ox = SuperImportContext.MakeScalar(m_MapComponent.m_TileWidth) * 0.5f;
                tilemap.orientationMatrix = Matrix4x4.Translate(new Vector3(-ox, 0));
            }


            AddTilemapRendererComponent(go);

            // Figure out our opacity
            var layer = go.GetComponent <SuperLayer>();

            tilemap.color = new Color(1, 1, 1, layer.CalculateOpacity());

            return(tilemap);
        }
Пример #7
0
 protected override void InternalOnImportAssetCompleted()
 {
     m_RendererSorter          = null;
     m_NumberOfObjectsImported = SuperImportContext.GetNumberOfObjects();
 }
Пример #8
0
 protected override void InternalOnImportAsset()
 {
     m_RendererSorter = new RendererSorter();
     WrapImportContext(AssetImportContext);
 }