Brush.TilePainted params

jlevet
Member
From: Marseille, France
Registered: 2014-03-31
Posts: 33
Website

Topic

Hello there,

as discussed in this topic, is there a possibility to have as additionnal parameters to the Brush.TilePainted Event :

  • the TileIndex

  • some kind of 'type' to know if it is called for a paint/erase/refresh

I currently need that to properly trigger some Particules when some Tiles are destroyed.

ps : I am currently using rotorz 2.3.2 BETA 6.

Cheers, Jérôme L.

Last edited by jlevet (2014-10-01 10:45:46)


Game Developper working on Zombie Night Terror.

Lea Hayes
Rotorz Limited
From: United Kingdom
Registered: 2014-03-04
Posts: 638

Response 1

In the next BETA release the following event will be obsolete Brush.TilePainted because it has been replaced by the new event PaintingUtility.TilePainted which includes the tile index.

Here is a preview of the new event:

using UnityEngine;
using Rotorz.Tile;

public class ExampleBehaviour : MonoBehaviour {

    private void Awake() {
        PaintingUtility.TilePainted += OnTilePainted;
    }

    private void OnDestroy() {
        PaintingUtility.TilePainted -= OnTilePainted;
    }

    private void OnTilePainted(TilePaintedEventArgs args) {
        // Tile might not have a game object attached!
        if (args.GameObject != null)
            args.GameObject.transform.LookAt(Vector3.zero);

        Debug.Log(args.TileIndex);
    }

}
jlevet wrote:

I currently need that to properly trigger some Particules when some Tiles are destroyed.

To achieve this you could add a custom behaviour to your tile and then use the "OnDestroy" message.

Lea Hayes
Rotorz Limited
From: United Kingdom
Registered: 2014-03-04
Posts: 638

Response 2

There is now another event (for the next BETA release) which may interest you PaintingUtility.ChunkCreated which can be used to add components to freshly created chunks.

jlevet
Member
From: Marseille, France
Registered: 2014-03-31
Posts: 33
Website

Response 3

Thanks for your reply, I don't want to attach a prefab with a custom OnDestroy() script on all my tiles for performances reasons.

i'll use as you suggest

PaintingUtility.TilePainted

event when next Beta will be available :)


Game Developper working on Zombie Night Terror.

Lea Hayes
Rotorz Limited
From: United Kingdom
Registered: 2014-03-04
Posts: 638

Response 4

jlevet wrote:

i'll use as you suggest

PaintingUtility.TilePainted

event when next Beta will be available :)

This new event will still not occur when tiles are erased.

Presumably you already know which tile will be erased prior to invoking TileSystem.EraseTile right? So why not just raise your own event handler?

private void MyEraseTile(TileSystem system, TileIndex index) {
    system.EraseTile(index);
    if (MyTileErasedEvent != null)
        MyTileErasedEvent(system, index);
}

Last edited by Lea Hayes (2014-10-02 08:40:38)

jlevet
Member
From: Marseille, France
Registered: 2014-03-31
Posts: 33
Website

Response 5

I See, and is that possible to add a PaintingUtility.TileErased event triggered everytime a Tile is Erased? with the TileIndex and the TileData the Tile was using?


Game Developper working on Zombie Night Terror.

Lea Hayes
Rotorz Limited
From: United Kingdom
Registered: 2014-03-04
Posts: 638

Response 6

jlevet wrote:

I See, and is that possible to add a PaintingUtility.TileErased event triggered everytime a Tile is Erased? with the TileIndex and the TileData the Tile was using?

It is not so straightforward to introduce a "TileErased" event because during bulk editing mode the following could happen:

  1. Begin bulk edit

  2. Paint tile (only updates tile data) (doesn't raise paint event)

  3. Paint same tile (only updates tile data) (would NOT raise erase or paint event)

  4. Erase same tile (can't raise event here)

  5. End bulk edit ("TilePainted" events are raised here; without storing lots of data we cannot determine whether tiles were erased here).

  6. Tile never existed and so the "TileErased" event would have been raised in error if naively called from the erase tile function.

Even more so, you couldn't have access to the TileData of an erased tile since that TileData object still belongs to that tile.

Lea Hayes
Rotorz Limited
From: United Kingdom
Registered: 2014-03-04
Posts: 638

Response 7

You should be able to determine which tiles will be erased prior to erasing them right? Thus you should be able to do whatever pre-erase and post-erase manipulations you want already.

If you are using the various PaintingUtility paint methods then perhaps you will want to take a look at the "Get{Thing}Indices" methods:

http://rotorz.com/tilesystem/api?ref=505F6B1E

Lea Hayes
Rotorz Limited
From: United Kingdom
Registered: 2014-03-04
Posts: 638

Response 8

I have added a highly experimental event "PaintingUtility.WillEraseTile" which happens immediately before a corporeal tile is erased (that is, a tile that existed before bulk edit mode was initiated).

If this event does not work properly then I may removed it again.

jlevet
Member
From: Marseille, France
Registered: 2014-03-31
Posts: 33
Website

Response 9

Lea Hayes wrote:

You should be able to determine which tiles will be erased prior to erasing them right? Thus you should be able to do whatever pre-erase and post-erase manipulations you want already.

If you are using the various PaintingUtility paint methods then perhaps you will want to take a look at the "Get{Thing}Indices" methods:

http://rotorz.com/tilesystem/api?ref=505F6B1E

I can do that, i was just asking if this event would be possibly implemented cause it just clean / symplify the process and maybe can be used by other people too !

I'll test your event when it will be on Beta :)


Game Developper working on Zombie Night Terror.

Lea Hayes
Rotorz Limited
From: United Kingdom
Registered: 2014-03-04
Posts: 638

Response 10

jlevet wrote:

I'll test your event when it will be on Beta :)

The beta was released earlier today :D

Thanks for your input, as always it is very much appreciated!!