What is the difference between a unity plugin and a dll file? - sdk

i am new to Unity and i am try to understand plugins. I have got the difference between a managed plugin and a native plugin, but what is not very clear to me is:
what is the difference between a plugin and a dll? what should i expect to find in an sdk to make it usable in my unity project?
Thanks a lot

To expand on #Everts comment instead of just copying it into an answer, I'll go a little into details here
What is a plugin?
It's a somewhat vague word for a third-party library that is somehow integrated with the rest of your game. It means that it neither is officialy supported by Unity, nor is it a part of your core code. It can be "plugged" in or out without altering its internals, so it must provide some kind of API that can be used by the game code.
For example, you'll find many plugins that handle external services like ads, notifications, analytics etc. You'll also find a couple of developer-tools that can also be called plugins, like tile-based map editors and such.
Plugins come in many forms - DLL files are one example but some plugins actually provide full source code for easier use. And of course, other plugins will provide native code for different platforms, like Objective-C for iOS or .jars for Android.
So to answer your first question:
DLL is simply a pre-compiled source file that can be a part of a plugin
A plugin is a whole library that can consist of multiple files with different formats (.cs, .dll, .jar, .m etc)
What do you need to use an sdk?
First of all - documentation. Like I said before, and like you noticed yourself, not all plugins give you access to the source code. And unfortunately, not many sdks have extensive and developer-friendly documentations so it can be a tough task to actually understand how to use a given sdk.
Secondly - the code. Many sdks give you some kind of "drag & drop" library, a single folder with all the neccessary files inside that you simply add to your Unity projects. I've also seen sdks that use Unity packages that you have to import via Assets > Import Package > Custom Package.
Once you have the code and documentation it's time to integrate it with your game. I strongly recommend using an abstract lyer in your game as, in my experience, you often have to change sdks for various reasons and you don't want to rewrite your game logic every time. So I suggest encapsulating sdk-related code in a single class so that you have to change only one class in your code when switching from, say, one ad provider to another (and keep the old class in case you need to switch back).
So you basically need three things:
Documentation (either a readme file or an online documentation)
The code (precompiled or source)
A versatile integration

Related

Load pre-compiled dart code at runtime using a shared library

Let's assume I have the following project structure:
interfaces/
A.dart, B.dart, etc
app/
main.dart, etc
addon1/
Aimpl.dart, Bimpl.dart, etc
addon2/ etc
The code being executed lies in app/, with some features using the functionalities defined in the interfaces located under interfaces/. However, the actual implementation of those interfaces lie in various addonX/ folders, whose code ONLY accesses code in the interfaces/ folder. The name of that folder might be a bit misleading, really it should be shared/, as my addon/ code is also allowed to instantiate classes from there and so on.
When I compile my app this way, everything works fine - after all, it's all the same project.
However, I would now like to essentially "outsource" the whole code in the addon folders, initially only compiling my interfaces/ and app/ code, and then loading various implementations (which can therefore be chosen by the user) at runtime.
In essence, I would like to have a plugin system where each plugin has access to all interfaces and functionalities in a shared folder (the shared folder would, in essence, be the SDK of my project), similar to how it can be done in Java with the usage of pre-compiled jar files. About a decade ago I saw one implementation of this system that I quite liked in the Bukkit project.
Is there a simple way to achieve this in dart? I've seen some talk about plugins in dart on stackoverflow already, but it took a much different form, with plugins "communicating" with the main app via messages, which is, imo, incredibly cumbersome.

How to manage 3rd-party library in iOS project if its source code needs to be modified in order to be used?

We need to use some 3rd-party libraries in our iOS app project (which is an Xcode project). The 3rd-party libraries are either managed by Cocoapods or directly added in the project by importing source code files.
Sometimes we need to modify a library's source code in order to actually use it appropriately in our project. It's easy to make the modification since we have all the source code at our hand, but how can we maintain the modification when some time in the future we upgrade the version of the 3rd-party library? Is there any tools or best practice out there that can help with this? And after the upgrade of the 3rd-party library, it will be good if we could differentiate in the code history about which part is done by library upgrade and which part is done by our modification.
That depends entirely on what your change is...
The best option is to not change the external code. Instead, subclass the part you need to change and use only public API so you should find out early when updating if the subclass needs to change. Unit tests also help.
If you can't subclass then you should fork the external code, then you have to manually merge updates on top of your change when you want them. This is obviously significantly more effort both in terms of importing and managing the code.

Divide an app to multiple apps that have different UI design and share logic code

I have an app which I will call it the "base app". The app works with many brands.
I need now to separate those brands, and to make a distinct app for every brand.
Every app will have a slightly different design (including different images) and here and there maybe some specific-to-a-brand code.
All of the apps should also use the same base code from the "base app" that deals with logic.
I have some options I have thought, but I am not sure if any of them suit my needs. Will be happy for clarifying the difference among the options.
The options I have thought are:
1) Creating an app for each one of the brands and just copy-paste the class files from the "base app" as a reference, except the .xib files, which will be copied as a copy. The problem is that then I do not know how and where to write a brand specific code (because it will be shared among others).
2) Creating a workspace that will include the projects for each one of the brand. Not sure how this works and if this is correct, will be glad for help clarifying here.
3) Nest a "base app" project inside every brand's project. Any help clarifying what does it do will be appreciated.
3) Using the base app as a static library which will be linked in every brand's project. Not sure what will happen with the UI (shared, not shared). Will be glad for help clarifying here too.
4) Using a simple way of maintaining each one of the brand's project, including the shared code (which will be a disaster, I guess).
The simple solution in iOS is use targets.
For resources you can use different targets for each brand and then select different resources (images, xibs, etc) for each target.
Also if the changes in code are minimal you can then refactor some part of your code and create different classes with different implementation for each target (you can use some pattern like a Factory). Also you can simply use preprocessor macros.
It's not the better, but this is the simplest and quick approach, but if your code changes a lot it's better to create a core library like the other answers say.
A good approach would be to split your app up into the following components:
Core Model Library
Reusable views & view controllers. The views can be designed to support skinning and customization.
Any other reusable code that can be encapsulated as its own 'identity'.
These core projects should ideally have their own continuous integration (quality control) builds and tests.
And then use CoocaPods
Instead of manually performing all this complex integration, use CocoaPods. CocoaPods will create the Xcode workspace, build the libraries and link them into your project. You then create a custom build just by gluing the pieces together.
In addition to this, CocoaPods also performs tasks such as:
Resolving transitive dependencies - which just means building and fetching any libraries that your libraries themselves use.
Managing versions of the libraries being integrated.
Private Spec Repo is possible, or just use GitHub
The main CocoaPods repository is of course public and contains open-source and/or freely available libraries.
You can host your own CocoaPods spec repository, or simply set up a private GitHub account, and include a PodSpec in each project, then resolve as follows:
pod 'MyLibraryName', :git => 'https://github.com/myOrgName/MyLibrary.git'
this will install all of your libraries into your workspace. To update your project to include any changes to the core libraries, simply:
pod update
Advantages of this approach
You'll have a separate set of quality controls that gets applied to each core project.
There'll be much less reputation.
You can use more automation. More automation equals less waste equals more customer value.
As the team grows, you can split up core product devlopment and solution integration into separate roles/teams. A team working on an integration build, need not pull the latest library features, if that would disrupt them.
You can have two different customers on different builds of the core library. CocoaPods will manage this seamlessly. So you wouldn't necessarily have to update a build, until you get an enhancement request or scheduled maintenance. (Again reducing waste, thus increasing customer value).
Inspired by Piggly Wiggly (but lean through and through)
This approach is modeled after the production line style approach that was popularized in Japan after World War II. Its called Lean Methodology, and is all about having a fast, small inventory and reducing waste. (Delivering more with less). . Japanese execs got the inspiration for this when they went to America and visited Piggly Wiggly Supermarket stores.
This is often something you encounter creating cheap flash-games or apps.
These have very generic frameworks like: kicking a ball, shooting at the screen, or generating a list with some data downloaded from a specific server etc...
Everytime they want to create a new shootergame, they just load up their shooting framework, add a bunch of graphics and can release a crappy game within a day.
How do they do it?
They often create a framework which contains shared models, handlers, interfaces etc.
Put a lot of general utility functions like downloading files etc in a library.
And you can also create some default framework views and view-controllers.
When you want to create a similar app, just import the library and re-use the base framework. Containing base-views, base-models etc.
You can find a good example in the demo-examples delivered with the ios SDK or android SDK.
Good luck.

Java: How to open a library?

I want to open libraries, because currently I want to see the algorithms used for drawing, modify them and implement them in my program. For example: I have tried to create an algorithm on my own for lines. But I failed. And even if I had succeeded, I fear that it might not give the same result as the algorithm in the libraries. And I don't want this to happen. That's why I want to copy the algorithms used for the methods in libraries. And I really hope that this will help me create the application I'm currently working on and with other applications in the future.
I tried to open the libraries with a code editor. But I had troubles finding the libraries- I don't really know where are they placed nor in what files are their codes stored.
How to open a Java library? Or is there a place in the Internet where the code is uploaded?
It sounds like what you want is to get inside the standard Java libraries (so you can see the code for methods like Graphics.drawLine()).
You can download the source files from the same place you got the JDK, if you are on Windows or Linux. For the Mac, see this question. You can even set up Eclipse so that you can debug into that source as if it were your own code.
However, you will probably not find line-drawing code in Java in these libraries - the Graphics implementation will almost certainly use native methods, and may just call existing methods in the OS.
If you are specifically looking for line drawing algorithms, another option would be to look at the Wikipedia page for the Bresenham (aliased) or Wu (antialiased) algorithm.
Edit:
The part of a Graphics2D call that actually puts pixels on the screen is probably inside a system call and therefore the source would not be available.
A java vector graphics library like Batik might have source for some of these algorithms, but probably relies on the Graphics2D calls for most of them. So, you might look for a comprehensive vector graphics library written in a language other than Java, where those graphics calls do not already exist by default.
Alternately, checking the table of contents for a computer graphics book might point you at a variety of algorithms that you could look up on Wikipedia.
For any given library:
Make sure to obey all licenses when using another's code
If you are referring to the Java SDK source code, you can find it here: http://grepcode.com/
If the project is open source, you can usually just get the source from the project website. No problem, though make sure to obey their license.
If the project is NOT open source, well, then you're in a pickle licensing wise, so I do NOT endorse this, however, you would need to use a Java Decompiler such as JD-Gui
As far as what drawing algorithms to use, there are so many different ones (obviously, people have been trying to draw quickly for many many years), your best bet is to figure out exactly what you need to do and then search for that specific need separately. There isn't really a good repository of ALL of them, except maybe wikipedia.
If you are using the libraries they are on your classpath. Check out how to figure out your classpath in whichever IDE you are using and you can find the JARs you depend on. If they are packaged with sources all you need to do it unjar them and look at the sources.
If you don't have access to the sources you can get the code using a Java Decompiler.
If you are trying to look at a standard Java library, see the other answers about getting the source to the JDK.
If you are interested in an open source library (such as something maintained by the Apache project), look on the site of the project for a 'source jar' which you can open with a standard zip utility.
If the library you want is not open source or you cannot find the source for it, you can try to decompile it. If you are using Eclipse, try this decompiler.

Organizing, Storing, and Keeping Track of code for reuse

Many moons ago I started storing my music as MP3’s. I downloaded like mad and just dumped them all into a folder. After collecting thousands of songs I had a big mess. After two years of organizing all music in my free time I have made it to “D” section of my library. I am starting to write code on a daily basis and I would like to keep a lot of what I do for reuse and future reference. I use Visual Studio a lot, and Eclipse sometimes, but I also do web development. Right now I am just have a folder on an external drive called Projects and inside that folder I have code I want to save broken down by its respective IDE and then the language it was developed in. This is working ok right now, but I fear after a few years it might get hard to navigate, and I don’t want another mess like my music library. What are some good ways to keep track of code and programming projects while also promoting easy navigation and future reuse?
I use a subversion repository for purpose of saving code for the future. In my repository I have the following folder structure:
\
|- Project1\
|- - Trunk\
|- - Branches\
|- - Tags\
|- Project2\
....
This is working for me and I have big and small projects that I coded on since high school in this repository. If I for instance want to port a project that I coded on Linux to Windows I create a branch that I for example call Win32-port. And when I have a 1.0 release of a project I create a tag named 1.0.
Using this method you can also set up back-up scripts and save a backup to another location. (I use a cron job and some python scripts to achieve this, but it all depends on what system the server uses.)
A book about subversion are freely available here: Link
For Mac OS X, there's the beautiful Snippets:
(source: snippetsapp.com)
Also, the new Xcode 4 will have native support for custom code snippets.
It won't really solve your organising problem, but you'll be more productive anyway by using snippet be it inside Eclipse or inside Visual Studio.
Here's a short tutorial for snippet in Eclipse : http://www.dansshorts.com/post/creating-snippets-in-eclipse
And here the explanation to create them and link them to a keyword in Visual Studio 2010 : http://www.visualstudiotutor.com/2010/02/create-snippet-visual-studio-2010/
This would take a bit more infrastructure to set up and is more for multiple people working together, but the best approach is to start thinking of Software as a Service.
For commonly used functions, wrap them as a web service with good documentation. For instance, if you have a phone validator that seems to be constantly used across projects, it would become part of your validator service.
With few exceptions, most shops don't seem to organize/share code effectively with static document type code libraries.
This would also force you to refactor the code snippets into reusable methods instead of just random code that is copied/pasted in. It also gives you a clean seperation between the public interface and private implementation.

Resources