grofit / dotween-nodecanvas

Node Canvas actions for DoTween library
12 stars 4 forks source link

DOTween Pro Support #6

Open DogeThis opened 8 years ago

DogeThis commented 8 years ago

http://dotween.demigiant.com/pro.php

If we were to add support for Pro, what's the best way to separate the Pro actions from the free ones?

grofit commented 8 years ago

I have not looked at the pro actions but in other libraries which are used with node canvas (such as A* pathfinding) to support the free and pro versions "polyfill" classes are added with empty shell to fake the pro part of the library. Pragmas are added to these files to stop them being included unless the user manually removes them.

From prior experience there is no easy way to seamlessly support free and pro versions of a library in a single output package, you either have 2 separate releases targetting each version or you make the user do some magic dance to turn on or off support for free.

DogeThis commented 8 years ago

Thanks for the explanation, grofit. I'm new to C# development.

Pragmas are added to these files to stop them being included unless the user manually removes them.

I think I want to go with this route. You OK with that?

grofit commented 8 years ago

Sure, for an example of how it was done in the A* pathfinding actions for NC.

//#define IS_ASTAR_FREE

#if IS_ASTAR_FREE
using UnityEngine;
namespace Pathfinding
{
    public class FleePath  : Path
    {   
        public static FleePath Construct (Vector3 position , Vector3 avoid , int searchLength, OnPathDelegate callback)
        { return null; }

        protected override void Recycle()
        {
            throw new System.NotImplementedException();
        }

        public override void Prepare()
        {
            throw new System.NotImplementedException();
        }

        public override void Initialize()
        {
            throw new System.NotImplementedException();
        }

        public override void CalculateStep(long targetTick)
        {
            throw new System.NotImplementedException();
        }
    }
}
#endif

The above pragma definition is commented out so if someone wants to enable the pro polyfills they comment out the top line and the code below in the #if section is enabled.

So the FleePath class is only available in the PRO version of A* Pathfinding, and the code contained inside basically pretends this class exists, so actions that use it will work at compile time, just at runtime if you were to try and use pro features with only a free library it would blow up.

However using this approach means you need to basically create placeholders for EVERY aspect of pro functionality you want to wrap (I have not looked at it so dont know how much work is involved).

If you have any problems or queries let me know.