[OPEN SOURCE] TypeSafe - Replace 'magic' strings with automatically generated code


GITHUB | WEBSITE | DOCUMENTATION

One principle advantage of type safety is catching errors at compile time.
TypeSafe brings this same advantage to your Unity-powered game when loading resources, scenes or using layers and tags.

Key Features

  • Automatically scans your project and generates strong-typed classes than can be used to replace raw strings in your code.
  • Using these safe classes ensures that any resource, layer or scene you try and use in code always exists.
  • Moving, renaming or deleting a resource will cause compile errors at the place in code they were used.
  • Read more on the website, download on github.

DOWNLOAD ON GITHUB | WEBSITE | DOCUMENTATION

2 Likes

Hey all, I have 3 voucher codes to give away. If you’re interested just reply here and I’ll PM you one, first come first served!

1 Like

Very interesting product! Would love to give it a go!

1 Like

@mimminito , PM sent! Thanks for your interest!

1 Like

Would love to test it as I was planning on doing something similar for my current project. Thanks.

1 Like

Curious, would this solve the magic string problem with WPF PropertyChangedEventHandler?

private string _name;
public string Name
{
   get { return _name; }
   set
   {
      _name = value;
      PropertyChanged("Name");
   }
}
private void PropertyChanged(string prop)
{
   if( PropertyChanged != null )
   {
      PropertyChanged(this, new PropertyChangedEventArgs(prop);
   }
}

In C# 5 that’s solved with [CallerMemberName], but that’s a long way off on the Unity roadmap.

edit: Oops, now that I read the description better it seems I got a bit ahead of myself when reading “replace raw strings”. :stuck_out_tongue:

@iamsam , voucher sent via PM. Thanks for your interest!

@movra , unfortunately TypeSafe won’t help there :frowning: In C#6 there is the nameof() operator which is perfect, but we’ll have to wait for Unity to upgrade their version of Mono for that. Alas! Were you interested in having a voucher?

@Simie Sure, I want to try using TypeSafe with Entitas. It’s a nifty framework but you still have code like this to load prefabs:

  public void Start() {
        const string resourceName = "Opponent";
        for (int i = 1; i < 10; i++) {
            var speed = Random.value * 0.02f;
            _pool.CreateEntity()
                .AddResource(resourceName)
                .AddPosition(i + i, 0, 0)
                .AddMove(speed, speed);
        }
    }

which connects to

public void Execute(List<Entity> entities) {
        foreach (var e in entities) {
            var res = Resources.Load<GameObject>(e.resource.name);
            var gameObject = Object.Instantiate(res);
            gameObject.transform.parent = _viewContainer;
            e.AddView(gameObject);
        }
    }

TypeSafe can make that more robust, right?

1 Like

@movra , Entitas looks very interesting. I’ll be sure to check that out in the future. I’ll be sending you a PM in a moment with a voucher :slight_smile:

@Everyone Else
I’ve got just one voucher left, so next person to ask for one will be the last, for now!

1 Like

I have used it for only half an hour just replacing the resource path magic strings, but I can already tell TypeSafe makes development in Unity a lot more robust. Looking at the feature list I’ve barely scraped the surface.

The asset itself is also very polished, just looking at details like filtering folders and the ability to customize the naming scheme.

Thumbs up!

1 Like

@movra , Thanks very much for the review you left on the asset store, I’m glad you like it!

Hey, I’d love to give this a shot if you’ve still got the voucher left!

I’ve got something that I cooked up for myself that works pretty well on a basic level, but it’s nowhere near as feature-complete (or customizable) as TypeSafe.

@electroflame , PM sent with a voucher code for you. Thanks for your interest!

That’s the last of my voucher codes for now, folks. Thanks for checking out TypeSafe!

@Simie thanks for the voucher, will check it out today and surely leave a review in a day or two. Thanks again.

@movra thanks for the info on Entitas, looks like a useful system and something much needed for Unity.

I said thanks in my return PM, but I totally spaced and forgot to thank you in this thread. Thanks @Simie !

@electroflame , no problem! Enjoy!

Hey all, I just submitted a quick bug fix release for approval on the asset store. Should be up in a few days.

Changelog:

1.0.1

New:

  • Added documentation comments to generated resource folder methods (GetContents, etc).

Fixes:

  • Welcome window no longer shows up after the first time
  • Fixed Editor-only resources being included in scan
1 Like

1.0.1 is been approved and is now available on the asset store.

The next version, 1.1.0, will have a system for hooking external data into TypeSafe so you can generate classes with your own data. This should be submitted within a few days and be available shortly after.

2 Likes

This is an extremely polished asset store product which will really make your code robust and bug free. Extremely easy to use and is very polished. I was working on something similar but after trying this last week, I can say a million thanks to the author for creating the plugin. I fully recommend it :).

PS. I am sorry for the late update, will put a review on the asset store too.

1 Like

@iamsam , thanks for the kind words! I’m really pleased you have found TypeSafe useful.

I’ve just submitted version 1.1.0 to the asset store. A big thanks to @electroflame for helping me test the custom data source part of this release. Changelog is below, and it should be approved and available on the asset store within about a week.

1.1.0

New:

  • Added ITypeSafeDataSource interface for using TypeSafe for custom data. See documentation for details.
  • Added TypeSafeApi static class for invoking TypeSafe scan/compile process via script.
  • PrefabResource.Instantiate(Vector3) overload added (no rotation)

Fixes:

  • Fixed “Object has been cleaned up” warning when saving a scene with TypeSafe enabled.
1 Like