Search Unity

[Released] Prefab Atlas - Easiest pooling solution

Discussion in 'Assets and Asset Store' started by JakeTBear, Jun 18, 2015.

  1. JakeTBear

    JakeTBear

    Joined:
    Feb 15, 2014
    Posts:
    123


    features:
    • Easy to setup, easy to use pooling solution, simplicity is key.
    • Allows you to choose what to load on a scene by scene basis.
    • Manage preloading of prefabs to avoid hiccups during gameplay.
    • Manage how many elements a pool can contain, so you choose the perfect balance between memory and efficiency.
    • Manage how many elements of a type can exist period, allows you to get all the control over allocations in your game.
    • Organization, dont bother creating prefabs the old way anymore, let this tool organize them for you, automatically creates a prefab from a game object in the scene when drag and dropping on the group (see the tutorials on how to add elements to a group) and puts them in a folder created for you using the groups's name. You dont have to look for the prefabs as well, use the custom window to select prefabs that are inside any group.
    • Lightning fast performance and self managed, you really dont have to worry about keeping any kind of reference to any prefab, any instance of any pool, anything, just setup the atlas and use. The spawning is as fast as it can get.
    • Dedicated development with over three years of improvements and counting. I hear the feedback of everyone and take it in consideration when adding/improving features, I always answer within 48 hours and you can count on my continuous support.


    BASIC USAGE TUTORIAL

    This tutorial seeks to illustrate how to setup step by step the Prefab Atlas and how to use it in code.

    Open the Prefab Atlas Window by clicking on Tools->Prefab Atlas Editor:



    By doing this, the prefab atlas will check if you have a prefab atlas object already created within your Assets folder, if it cant find one it will create one. You should see this window:


    The window is divided in 3 sections (Groups, Prefabs, Scene Object Setup), this window reads your Scene Object, if it cant find one then it will display the option to create an Scene Object:


    Click the Create Scene Object button and the option will hide. After doing this we require a new Group, click on the plus sign on the Groups section:


    This will create a new Group with the default name "GroupName", you can click on this group name to change it (Note: Groups need to start with a letter or code friendly symbol such as underscore "_", this is because the groups get parsed into C#).

    Now we only need to add an element to our new group, there are two ways of doing this, the first one is the classic way, drag and drop a prefab that was created previously:



    But in recent updates, a new way of adding prefabs was introduced, and it is also the recommended way, simply drag and drop a GameObject in the hierarchy to automatically create a prefab from it and add it to the Group:


    All the elements inside the group can be seen within the Scene object setup, where you can modify their Preloads, Capacity and Max Instance, a bit of explanation on each element:

    Preload: The amount of instances the pool will create once the game starts, this is useful to avoid making instances during gameplay which could cause hiccups.

    Capacity: The amount of elements a pool can hold at any given moment, this is useful to limit how much memory you want to actually hold, say you create 1000 elements freshly from your pool, but you only want to keep a 100, so you set your capacity to this number and once 100 go back in, the pool will stop accepting new elements and will destroy them, freeing up memory. -1 will disable this feature.

    Max instance: Think of this a rule of how many can be alive in the pool or out of it, combined, extremely useful for particle effects or sound related elements. Only want 400 snow flakes at all times? set this to 400.

    You will also notice a "DEFAULT VALUES" section in all groups, in this section you can massively apply the defaults to all the elements in the group, this is for convenience to quickly setup the values in mass, just press the "apply defaults" button.

    Finally to conclude the setup of our Prefab Atlas, we require to commit our changes, press the button on the top right corner of the window:



    Your project will reload if there were any changes, this is because the prefab atlas when you click commit it will parse the information from the editor to C# code that will allow you to use the prefab atlas in code and in the editor. That concludes the basic setup, you can create more groups, add more prefabs to the groups, and tweak your Scene Object setup.

    Now onto the code usage:

    Fire up your favorite IDE and create a new Monobehaviour class, I will name mine PAtlasExample:


    We will first use the most straight forward way to use the prefab atlas, on the OnEnable function we will do a direct call and create an instance of the prefab we added to the atlas, remember my group was called "GroupName" and the prefab was called "Cube":


    This is doing the following:
    - "PrefabAtlas.Spawn(GroupNameTag.Cube, new Vector3(0.0f, 0.0f, 0.0f));" gets the element from the pool with Tag "Cube" and creates an instance of it at position 0,0,0.

    Note that there are several options for the "Spawn" function, you can specify its position, rotation, or none of them, if you dont specify anything it will create it at position 0 with the rotation also at 0 in all angles. Thats the most basic way to use the prefab atlas in code, now we will take a look at the PAT values:



    The biggest difference here is that the code doesnt need to know before hand what it is creating, because the PAT values (Prefab Atlas Tag) are to be set within the editor. this makes it very handy when creating versatile game objects, for example, wave spawners in a tower defense game, or a bullet changing gun, or even different types of particles/sounds, the PAT is one of the features that makes the prefab atlas very versatile. Lets take a look at it in the inspector:



    The PAT value (SpawnThis) is represented in two parts, the first one being the group, you can select any group inside the prefab atlas, secondly we have the ID of the prefab that only appears when a group is selected, this list will only display elements inside the group selected.


    This feature also allows for some very nice organization (much better than dragging and dropping a prefab onto a public gameobject field). Once you have setup the PAT you will be able to spawn any prefab from this script.

    Now lets take a look at how to return things to the pool in code. it is very simple and it doesnt create any intrusive or special calls, the only thing you need to do is "deactivate" your game object:


    What the pooled object does is listen to when the prefab gets deactivated, and returns it to the pool. Simple as that, you can even destroy the object if you wish, the Prefab Atlas will handle the instance being destroyed as well.

    If you would prefer some videos, here you go (I am terribly sorry for my accent):

    Basic setup:


    Examples of usage:
     
    Last edited: Jul 6, 2021
  2. JakeTBear

    JakeTBear

    Joined:
    Feb 15, 2014
    Posts:
    123
    Pending review: PlayMaker Integration, here is a quick video that shows how to use it:
     
    Last edited: Nov 12, 2015
  3. JakeTBear

    JakeTBear

    Joined:
    Feb 15, 2014
    Posts:
    123
    The Playmaker extension is live in the Asset Store now: LINK
     
  4. JakeTBear

    JakeTBear

    Joined:
    Feb 15, 2014
    Posts:
    123
    The prefab atlas is on sale Today, pick up your copy! and if you have any questions prior to buying or after buying please dont hesitate in posting here!

    Have a link: Link
     
  5. Masaco

    Masaco

    Joined:
    Jan 29, 2013
    Posts:
    2
    REMOTE POOLS?
    Does Prefab Atlas support any remote prefab pool mechanism? For example client app wants to load objects from a remote Prefab Atlas file or a Unity AssetBundle file that is located on a remote server. If remoting is not supported yet is there any plans to implement it later on? The asset looks so cool that I may buy it anyway :)
     
  6. JakeTBear

    JakeTBear

    Joined:
    Feb 15, 2014
    Posts:
    123
    Hey Masaco,
    As of now, the prefab atlas only works locally, I can definitively look into the feature, I could make the "prefab scene object" to load the prefab atlas from a server.

    Thanks for the idea, I will investigate :)
     
    Masaco likes this.
  7. kilik128

    kilik128

    Joined:
    Jul 15, 2013
    Posts:
    909
    hi here i try make list of one group for loading by int ? for exemple

    any way to clear or reduce to big pool ? if it's serve to somethink's

    about name duplicate it's possible to use id ? i'am slaking on that's lol
     
  8. JakeTBear

    JakeTBear

    Joined:
    Feb 15, 2014
    Posts:
    123
    Hey Kilik, I am not sure I understood what you meant, but groups need to be uniquely named in order to compile (this i because it creates code for you).

    As of using the same prefabs in differents groups, it is possible and it will not give you any troubles, all the elements are actually hash values (ints) that are created when doing a commit.

    If I was way of on what you meant you could type it in your native language and I will try my best to traduce from there.
     
  9. kilik128

    kilik128

    Joined:
    Jul 15, 2013
    Posts:
    909
    sure and for the list for exemple

    when need the item 3 on one group
     
  10. JakeTBear

    JakeTBear

    Joined:
    Feb 15, 2014
    Posts:
    123
    Do you mean you want to add IDS into a list to be configurable in the inspector?
    If this is the case, you can use a PAT value inside a public or serializablefield list, for example:

    Code (CSharp):
    1.     public List<PAT> IDS;
    This will show a list in any monobehaviour for you to play with.

    Hope it helps!
     
  11. kilik128

    kilik128

    Joined:
    Jul 15, 2013
    Posts:
    909
    Yes it's somethink's like that's
    in fake i think's if this list can already created like
    for exemple

    public List<PAT> IDS =new pat group1 object1 , group1 object2 .. etc ;
     
  12. Not_Sure

    Not_Sure

    Joined:
    Dec 13, 2011
    Posts:
    3,546
    Man, I'm struggling here to follow how to create something in the pool via script.

    The video for it is REALLY hard to read and follow. I've got it set to 1080 and the text is barely visible and it blasts through the stuff I need to see. And it looks like you cut off a library that I need at the top of the script.

    Is there any way you could do a script tutorial that isn't a video? Like maybe a series of screen shots and code exerts? It would be a good way to bump your asset on the forum :rolleyes:.

    Or at least do another video that is easier to follow?
     
  13. JakeTBear

    JakeTBear

    Joined:
    Feb 15, 2014
    Posts:
    123
    Thats an excellent idea! I have edited the first post and it now contains a full basic usage of the Prefab Atlas, if this is not clear dont hesitate in letting me know, I will try my very best to help you utilize this tool :)
     
  14. JakeTBear

    JakeTBear

    Joined:
    Feb 15, 2014
    Posts:
    123
    Version 1.0.3 has been accepted and is now live in the Unity asset store.

    Changes:
    - In some cases if the project contains many folders the prefab atlas used to take a longer time to load its window, this will no longer be the case.

    - When committing a group without prefabs, the tool used to create an empty switch block which would throw a warning. now the atlas will no longer create the empty switch.

    - Editor prefabs integrity was heavily improved, the tool used to check every tick for changes, now it handles changes differently.

    A new price has been set as well, after comparing the tool with other similar solutions.

    I wanted to thank everyone who has given me feedback, it helps me to better serve everyone who uses the Prefab Atlas. If you have any questions or any feedback, please don't hesitate in asking.
     
  15. Hyldemoer

    Hyldemoer

    Joined:
    Jan 31, 2013
    Posts:
    3
    Hey there, really nice tool I must say. Thanks and well done!

    However, I've got a little problem there - I wish if there was a "None" enum for every generated tags so I could do a check whether I need to spawn the prefab or not. Probably None = 0 or something
    This also helps "reset" the selection in the editor too i.e. if you were selecting some tag, there is no way to clear it, right ?

    Cheers,
    H
     
  16. JakeTBear

    JakeTBear

    Joined:
    Feb 15, 2014
    Posts:
    123
    @Hyldemoer The default could be None instead of simply not having any tags, I like this idea very much, the Prefab Atlas could also handle when None is passed.

    Thanks for the feedback! I will definitively implement this :)
     
    Hyldemoer likes this.
  17. Hyldemoer

    Hyldemoer

    Joined:
    Jan 31, 2013
    Posts:
    3
    Cool! I look forward for the new release! Cheers :)
     
  18. JakeTBear

    JakeTBear

    Joined:
    Feb 15, 2014
    Posts:
    123
    The Unity Asset store team are working very fast! Version 1.0.4 is out right now, it implements the "None" tag as the default value in all the groups.

    Also, PAT values are now properly cached just like the normal tags were, thanks to this there are no more look ups besides the initial one. The performance gain is pretty awesome while still allowing the versatile usage of the PAT values. (I would dare to say it is as fast as it can get in terms of queries :) )

    And lastly, Unity has been kind of odd when re exporting packages as of late, it has happened to me that instead of overriding the files inside the folders it simply deletes and replaces the entire folder or parts of it, this could potentially delete your PrefabAtlas.prefab and PrefabAtlasExtension.cs files, for safety before updating your PrefabAtlas make sure to backup these 2 files as they contain all your custom information(located in PrefabAtlas->Components), if something goes wrong just delete the entire folder (PrefabAtlas) and re export the package, then re add these 2 files.

    Thank you all for your feedback and for supporting this tool.
     
  19. JakeTBear

    JakeTBear

    Joined:
    Feb 15, 2014
    Posts:
    123
    Version 1.1.0 is live in the store.

    Changelog:

    - Scene objects now have default values, before it was possible that if you didn't update your scene objects in scene "A" (by having the Prefab Atlas window open while in that scene) and added more prefabs to the atlas while in scene "B" when running the game and navigating to scene "A" the atlas would have thrown an exception due to not having the newest added prefabs configured, this is now fixed and you can safely add prefabs to the atlas while not updating all the scene objects, if they don't find an entry they will use their default values (preload 0, max instance -1, capacity -1) (is still recommended that you do so, but do it at your own leisure).

    - Creating prefabs out of hierarchy game objects by dragging and dropping in the groups. Before, the atlas wouldn't accept anything that wasn't a prefab. now it will automatically create a prefab out of any hierarchy game object you give, example:



    As you can see, the element turns into a prefab, and you can use the prefabs tabs to quickly select it to be shown on the inspector, still, all the prefabs generated by the Prefab Atlas are sent to "Assets/PA_GeneratedPrefabs":

    As always, back up your projects before updating, and if you have any feedback don't hesitate in letting me know.
     
    Last edited: Oct 24, 2015
  20. cranecam

    cranecam

    Joined:
    Nov 25, 2013
    Posts:
    25
    hi,
    how would you spawn a random prefab, only once, then remove it from pool, so the next call picks another prefab?
     
  21. JakeTBear

    JakeTBear

    Joined:
    Feb 15, 2014
    Posts:
    123
    @cranecam

    Hello! you would simply destroy it instead of deactivating it, this will make it so it doesn't get returned to the pool. Hope this helps!

    Edit: As for the random part:

    You could make a list of PAT values or simply any specific tags (such as GroupNameTag) and get a random one from the list, a quick example:

    Code (CSharp):
    1. using System;
    2. using System.Collections.Generic;
    3. using System.Collections;
    4. using UnityEngine;
    5.  
    6.  
    7. public class RandomPrefabSpawn : MonoBehaviour
    8. {
    9.     public List<CelebrationTag> _RandomCelebrations = new List<CelebrationTag>();
    10.  
    11.     void OnEnable()
    12.     {
    13.         //here we get a random tag to be used. Notice that this will use a random
    14.         CelebrationTag RandomChosenCelebration = _RandomCelebrations[UnityEngine.Random.Range(0, _RandomCelebrations.Count)];
    15.         //Then we use the chosen tag to spawn an element from the prefab atlas.
    16.         GameObject Chosen = PrefabAtlas.Get(RandomChosenCelebration).Create();
    17.         //then we do what we wanted to do with this gameobject, after that we can simply destroy it to get rid of it by using
    18.         //(Destroy(Chosen);) or simple deactivate it to return it to the pool (Chosen.SetActive(false);)
    19.     }
    20. }  
    21.  
    Going even further on what you asked, I believe what you are wanting to do is to make it so it is impossible to spawn that element from the pool ever again. This is currently not possible from the prefab atlas itself (but I will make it possible), still you can achieve the same result if you remove the tag chosen from the list, like this:

    Code (CSharp):
    1. //Finally we remove the chosen tag from the possible list. this will make it impossible to spawn the same element again.
    2.         _RandomCelebrations.Remove(RandomChosenCelebration);
    Okay I believe thats what you asked, if you have any more questions or if I misunderstood your question, let me know!
     
    Last edited: Oct 21, 2015
  22. cranecam

    cranecam

    Joined:
    Nov 25, 2013
    Posts:
    25
    yes, I was thinking along those lines, using a List
     
  23. JakeTBear

    JakeTBear

    Joined:
    Feb 15, 2014
    Posts:
    123
    Thats awesome! lists are very versatile, but if you end up using a PAT values inside lists, remember to check against their HashValue.
     
  24. JakeTBear

    JakeTBear

    Joined:
    Feb 15, 2014
    Posts:
    123
    Hey everyone! version 1.2 is now live in the store, this version brings some more niceness to the tool and a couple small bug fixes:

    New features:
    - Reordering of the groups (sorry for not having this feature sooner!)
    - Automatic folder generation. In the previous update if you were to make a prefab out of an scene game object it would create an special folder named PA_GeneratedPrefabs and put the newly created prefab inside, now instead of doing that it will create a folder with the groups name inside the PA_GeneratedPrefabs, to allow a nicer organization. Now I am never creating prefabs the old way and I simply allow the atlas to organize the prefabs for me.

    Bug fixes:
    - In the previous version a bug fix was made to handle the event when you add a prefab to the atlas without updating all the scene objects in different scenes. Now this fixes the event when you delete a prefab and you dont update all the scene objects in different scenes.
    - PAT look up switch now correctly checks if an ID is defined twice before doing a code generation, this error would happen if the same named appeared in more than one group.

    As always, remember to back up your files before updating, any questions or suggestions I will check them out and get back to you within 24 hours (here in the forums or twitter)

    I am already working on version 1.3 which hopes to bring some more ease of use and some specialized features (Asset bundle), also I am planning on working on new tutorials once the update is submitted to the store (voiced video tutorials that go slower).

    Thanks for reading and for all your feedback!
     
  25. JakeTBear

    JakeTBear

    Joined:
    Feb 15, 2014
    Posts:
    123
    Hey everyone, the Prefab Atlas 2.0 has been accepted and it is now live in the asset store.

    I have also edited the first post reflecting the changes.

    This version brings a lot of niceness to the custom window and some big additions to the code.

    • UI is more Unity like, a lot of efforts have been taken into making the editor as friendly as possible.
    • Default values: a quick way to apply default values to all your elements inside a group, set your default values and then apply them with the button located inside the section.
    • In addition to Get() and Create() we now have Spawn() which effectively combines both calls, easier and more straightforward usage.
    • Component caching, now every single create or spawn call has a generic counterpart, this will internally do a GetComponent on the object being created or spawned, and it will cache it in case the component gets asked for again, avoiding a second GetComponent call, very handy for special setup calls (such as PrefabAtlas.Spawn<Missile>(ID, Pos).SetDirection(Direction); ).
    • Every call is now fully documented.
    • Prefab replace during runtime, this feature allows server interaction with the prefab atlas, you can load and use a prefab from a server and replace an existing prefab in the atlas, making remote pools possible.
    I have included an example on how to change prefabs during runtime, even though this doesnt directly show how to load a prefab from a server using asset bundles, it will be fairly simple to implement your custom method to do so and make it work with the atlas.

    Any questions? ask away, thanks for reading!
     
  26. Crystan

    Crystan

    Joined:
    Oct 11, 2014
    Posts:
    20
    Hi,
    I'm having trouble spawning a pooled object (or the atlasBag ) as a child. I've tried it with transform.parent but it looks like it breaks the pooling. In my case i need to spawn a shield hit effect at the position of a moving object and the effect should, of course, follow the objects movement. I've watched your videos and read through your tutorials here but I couldn't found any informations about it (I hope I didn't miss anything :p ).
     
  27. JakeTBear

    JakeTBear

    Joined:
    Feb 15, 2014
    Posts:
    123
    Hello @Crystan
    If you change the parent during runtime it will not break the pooling, the only thing you will notice is that the prefab will no longer be organized inside of its bag, thats perfectly fine and if you deactivate and unparent this object it will be pooled properly :)

    Now, there are a couple ways you can spawn an object as a child of another, currently the "Spawn" function doesnt have a "with parent" option (coming on a couple releases more) but the Container itself has a "with parent" option.

    Here is a generic example on how to spawn an object as a child of another.

    Code (CSharp):
    1. PAT ID;
    2.  
    3.     void YourOwnFunction()
    4.     {
    5.         PrefabAtlas.Get(ID).CreateWithParent(transform, transform.position);
    6.     }
    Remember you dont need to use a PAT value, you can use the tag itself. If you post your code I can give you more details on how you can achieve what you want, dont hesitate in asking again if you need further help, thanks for using the Prefab Atlas! :D
     
  28. Crystan

    Crystan

    Joined:
    Oct 11, 2014
    Posts:
    20
    Thanks for the fast reply! Everything seems to work properly now. The spawned prefab disables itself after a second (through a script attached to the spawned object) and is reused if necessary. Thanks a lot! :)

    Here's the line of code I'm using now:
    Code (CSharp):
    1.     PrefabAtlas.Get(EffectsTag.shield_effect_normal).CreateWithParent(this.transform, transform.position);
     
  29. JakeTBear

    JakeTBear

    Joined:
    Feb 15, 2014
    Posts:
    123
    Glad to hear that! That's perfect also, no need to change it :), enjoy!
     
  30. RickRok

    RickRok

    Joined:
    Dec 23, 2014
    Posts:
    2
    Hello Jake,

    Was taking a look at your asset and it looks very promising for a project I am working on. I have, what I hope to be, a simple question. Will this work running off a server, spawning an object to all connected clients? I am using the Bearded Man Studio's Forge Networking.

    Thank you for your time,
    Rick
     
  31. JakeTBear

    JakeTBear

    Joined:
    Feb 15, 2014
    Posts:
    123
    Hey @RickRok
    I cant say with certainty exactly what you looking for since I have not done this myself, but in theory it should work no problems, still, I will send you a pm to further assist you.
     
  32. JakeTBear

    JakeTBear

    Joined:
    Feb 15, 2014
    Posts:
    123
    It is an amazing feeling when something I worked very hard on gets used by other people, and then they make an awesome game with it, I am very happy that @Crystan showed me his game that uses the Prefab Atlas, guys check it out here: https://play.google.com/store/apps/details?id=net.AtomicGear.SuperArkatis

    Its very cool! it uses 3d models and awesome particle effects and still runs very well, he mentioned everything is pooled with the Prefab Atlas.

    Thanks for sharing!
     
  33. paraself

    paraself

    Joined:
    Jun 30, 2012
    Posts:
    139
    Hi, I've purchased and began to integrate Prefab Atlas into my project! It looks very handy! Is there any API doc currently?
     
  34. JakeTBear

    JakeTBear

    Joined:
    Feb 15, 2014
    Posts:
    123
    @paraself Hey, thank you for purchasing!
    I havent done an API documentation, still, all the code usage can be accessed through the static class "PrefabAtlas", the code itself is fully documented. I want to work on a pdf that I will include in the package with more easy step by step ways of using the Atlas, but for now, the first post on this forum contains a detailed step by step walk through to begin using the tool. Also if you encounter any issues or require some examples, I will always reply within 24 hours.

    Thanks again!
     
  35. paraself

    paraself

    Joined:
    Jun 30, 2012
    Posts:
    139
    Thanks for your prompt reply. Emm I'll go through your source code to fully understand the every possible use of this plugin. Thanks for providing the source code ;D However an API doc as an overview is still prefered ;D Cheers!
     
  36. JakeTBear

    JakeTBear

    Joined:
    Feb 15, 2014
    Posts:
    123
    The code gets generated depending on what you add to your prefab atlas in the editor window. So for every prefab, new code gets added once you commit your changes, there are a few things to consider when naming your prefabs, such as to have a code friendly name and to avoid naming two prefabs that are inside the atlas the same name. Besides that it is all straightforward. PrefabAtlas.Spawn/Get

    Still dont hesitate in asking if you have any questions, I am here everyday :)
     
  37. gagwieg

    gagwieg

    Joined:
    Dec 22, 2015
    Posts:
    3
    hi I have two questions
    - can I get the prefab gameobject from prefab atlas without instantiate it by atlas so i can instantiate myself or do anything?

    - numbers of prefab enum is generating random or have some kind of sequence because maybe when making a new version of the game it will have different numbering so if it is multiplayer they will not be able to understand which the other version by the number of prefab.

    Thanks
     
  38. JakeTBear

    JakeTBear

    Joined:
    Feb 15, 2014
    Posts:
    123
    Hello!

    - Yes you can, in order to get the Prefab you will want to use the PrefabAtlas.Get function, pass the id you would like to retrieve and that will return a "PrefabContainer", in this class you have access to the "PrefabPrint", which is the prefab you looking for.

    - The ID is created using a hashvalue on the name of the prefab, as long the hash algorithm maintains constant between versions there should not be any problems, since everything is hardcoded by code generation it is pretty safe.

    Dont hesitate in asking if you need more information, hope this helps!
     
  39. gagwieg

    gagwieg

    Joined:
    Dec 22, 2015
    Posts:
    3
    thank you very much this is useful information and prefab atlas is very good asset.
     
    JakeTBear likes this.
  40. JakeTBear

    JakeTBear

    Joined:
    Feb 15, 2014
    Posts:
    123
    I am pleased to inform that version 2.2 of the Prefab Atlas is out, some nice features were added to grant a better experience:

    • PAT values now contain a small search bar type of element to minimize the amount of elements shown (in cases you have way too many elements in a group)
    • PrefabAtlas.Spawn now also has a "WithParent" version, both generic and non generic. PrefabAtlas.SpawnWithParent<T>
    • The editor starts to lag a bit if you contain way too many groups, well no longer! the Scene object setup will only allow a single entry to be edited at the time, all the others will be minimized, and it will auto scroll on the one you click, also now you dont need to click the arrow in order to open the settings.

    As always, back up your project before updating, and for any support I will always reply within 24 hours, cheers!
     
    paraself likes this.
  41. heroes1

    heroes1

    Joined:
    Nov 16, 2015
    Posts:
    17
    Hi Jake,

    I like your asset very much. But I was wondering how to make custom editor with this asset? Some of my script required for custom editor on OnInspectorGui but I have no idea how to do It with your asset. Please Help Me Out. Thanks.
     
  42. JakeTBear

    JakeTBear

    Joined:
    Feb 15, 2014
    Posts:
    123
    hello @heroes1
    Thanks for using the Atlas!
    Can you give me an example of what you are looking for? I will gladly help you.
     
  43. heroes1

    heroes1

    Joined:
    Nov 16, 2015
    Posts:
    17
    Hi Jake,

    Below is 2 scripts ItemSpawner and ItemSpawnerEditor.

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class ItemSpawner : MonoBehaviour
    5. {
    6.  
    7.     public GameObject[] prefabItems;
    8.     public Transform[] itemSpawnerTrans;
    9.  
    10.     // Use this for initialization
    11.     void Start ()
    12.     {
    13.         for (int i = 0; i < prefabItems.Length; i++)
    14.         {
    15.             Instantiate(prefabItems[i],itemSpawnerTrans[i]);
    16.         }
    17.     }
    18.    
    19.  
    20. }
    21.  
    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEditor;
    3. using System.Collections;
    4. using System.Collections.Generic;
    5.  
    6. [CustomEditor(typeof(ItemSpawner))]
    7. public class ItemSpawnerEditor : Editor
    8. {
    9.  
    10.     public override void OnInspectorGUI()
    11.     {
    12.         ItemSpawner _ItemSpawner = (target as ItemSpawner);
    13.  
    14.         if (GUILayout.Button ("ADD"))
    15.         {
    16.             List<GameObject> _TempPrefabItems = new List<GameObject> (_ItemSpawner.prefabItems);
    17.  
    18.             List<Transform> _TempItemSpawnerTrans = new List<Transform> (_ItemSpawner.itemSpawnerTrans);
    19.  
    20.  
    21.  
    22.             _TempPrefabItems.Add (null);
    23.             _TempItemSpawnerTrans.Add (null);
    24.  
    25.  
    26.             _ItemSpawner.prefabItems = _TempPrefabItems.ToArray();
    27.             _ItemSpawner.itemSpawnerTrans = _TempItemSpawnerTrans.ToArray();
    28.         }
    29.         for (int i = 0; i < _ItemSpawner.prefabItems.Length; i++)
    30.         {
    31.  
    32.             EditorGUILayout.LabelField ("Item "+i);
    33.             EditorGUILayout.BeginHorizontal ();
    34.  
    35.             _ItemSpawner.prefabItems [i] = (GameObject)EditorGUILayout.ObjectField ( _ItemSpawner.prefabItems [i], typeof(GameObject), true);
    36.             _ItemSpawner.itemSpawnerTrans [i] = (Transform)EditorGUILayout.ObjectField ( _ItemSpawner.itemSpawnerTrans [i], typeof(Transform), true);
    37.  
    38.             if (GUILayout.Button ("REMOVE"))
    39.             {
    40.                 List<GameObject> _TempPrefabItems = new List<GameObject> (_ItemSpawner.prefabItems);
    41.                 List<Transform> _TempItemSpawnerTrans = new List<Transform> (_ItemSpawner.itemSpawnerTrans);
    42.  
    43.  
    44.  
    45.                 _TempPrefabItems.Remove (_TempPrefabItems[i]);
    46.                 _TempItemSpawnerTrans.Remove (_TempItemSpawnerTrans[i]);
    47.  
    48.  
    49.                 _ItemSpawner.prefabItems = _TempPrefabItems.ToArray();
    50.                 _ItemSpawner.itemSpawnerTrans = _TempItemSpawnerTrans.ToArray();
    51.             }
    52.  
    53.             EditorGUILayout.EndHorizontal ();
    54.         }
    55.  
    56.  
    57.     }
    58. }
    59.  
    When i replace the GameObject to PAT then i have no idea how to code in the ItemSpawnerEditor

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class ItemSpawner : MonoBehaviour
    5. {
    6.  
    7.     public PAT[] prefabItems;
    8.     public Transform[] itemSpawnerTrans;
    9.  
    10.     // Use this for initialization
    11.     void Start ()
    12.     {
    13.         for (int i = 0; i < prefabItems.Length; i++)
    14.         {
    15.             PrefabAtlas.Get (prefabItems [i]).Create (itemSpawnerTrans [i].position, itemSpawnerTrans [i].rotation);
    16.         }
    17.     }
    18.    
    19.  
    20. }
     
  44. JakeTBear

    JakeTBear

    Joined:
    Feb 15, 2014
    Posts:
    123
    @heroes1
    I see! that is not such a trivial thing, I don't know why it never occurred to me that someone might have wanted to add PATs to their own custom editors. The thing is you would normally use a "PropertyField" to deal with custom inspectors, but the way you want to do it makes it a little more tricky even. Still, I went ahead and made a small editor window to help you with your use case.
    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEditor;
    3. using System.Collections;
    4. using System.Collections.Generic;
    5. using PrefabAtlasElements;
    6. using System;
    7.  
    8. [CustomEditor(typeof(ItemSpawner))]
    9. public class ItemSpawnerEditor : Editor
    10. {
    11.     public override void OnInspectorGUI()
    12.     {
    13.         ItemSpawner _ItemSpawner = (target as ItemSpawner);
    14.         SerializedObject Obj = new SerializedObject(_ItemSpawner);
    15.         if (GUILayout.Button("ADD"))
    16.         {
    17.             List<PAT> _TempPrefabItems = new List<PAT>(_ItemSpawner.prefabItems);
    18.             List<Transform> _TempItemSpawnerTrans = new List<Transform>(_ItemSpawner.itemSpawnerTrans);
    19.  
    20.             _TempPrefabItems.Add(new PAT());
    21.             _TempItemSpawnerTrans.Add(null);
    22.  
    23.             _ItemSpawner.prefabItems = _TempPrefabItems.ToArray();
    24.             _ItemSpawner.itemSpawnerTrans = _TempItemSpawnerTrans.ToArray();
    25.             return;
    26.         }
    27.  
    28.         for (int i = 0; i < _ItemSpawner.prefabItems.Length; i++)
    29.         {
    30.             EditorGUILayout.LabelField("Item " + i);
    31.             EditorGUILayout.BeginVertical(GUI.skin.box);
    32.  
    33.             SerializedProperty prop = Obj.FindProperty("prefabItems");
    34.             if (prop.arraySize > i)
    35.             {
    36.                 GlobalPAT(prop.GetArrayElementAtIndex(i), "Spawn");
    37.             }
    38.             EditorGUILayout.BeginHorizontal();
    39.             _ItemSpawner.itemSpawnerTrans[i] = (Transform)EditorGUILayout.ObjectField(_ItemSpawner.itemSpawnerTrans[i], typeof(Transform), true);
    40.  
    41.             if (GUILayout.Button("REMOVE"))
    42.             {
    43.                 List<PAT> _TempPrefabItems = new List<PAT>(_ItemSpawner.prefabItems);
    44.                 List<Transform> _TempItemSpawnerTrans = new List<Transform>(_ItemSpawner.itemSpawnerTrans);
    45.  
    46.                 _TempPrefabItems.RemoveAt(i);
    47.                 _TempItemSpawnerTrans.RemoveAt(i);
    48.  
    49.                 _ItemSpawner.prefabItems = _TempPrefabItems.ToArray();
    50.                 _ItemSpawner.itemSpawnerTrans = _TempItemSpawnerTrans.ToArray();
    51.                 i--;
    52.             }
    53.             EditorGUILayout.EndHorizontal();
    54.             EditorGUILayout.EndVertical();
    55.         }
    56.     }
    57.  
    58.     public static void GlobalPAT(SerializedProperty prop, string ID)
    59.     {
    60.         if(prop == null)
    61.         {
    62.             return;
    63.         }
    64.         EditorGUILayout.LabelField("");
    65.         Rect position = GUILayoutUtility.GetLastRect();
    66.         SerializedProperty Group = prop.FindPropertyRelative("enumType");
    67.         PrefabAtlasGroup Current = PrefabAtlasEditor.GetEnumPrefab((PrefabAtlasGroup)Group.objectReferenceValue, position, prop.name);
    68.         Group.objectReferenceValue = Current;
    69.  
    70.         if (Current != null)
    71.         {
    72.             string name = Current.GroupName + "Tag";
    73.             SerializedProperty Val = prop.FindPropertyRelative("HashVal");
    74.             PrefabAtlasEditor.DrawEnumToInt(position, Val.intValue, GetType(name), new GUIContent(ID), Val, prop.FindPropertyRelative("SearchHelper"));
    75.         }
    76.         else
    77.         {
    78.             SerializedProperty Val = prop.FindPropertyRelative("HashVal");
    79.             Val.intValue = 0;
    80.         }
    81.         if(GUI.changed)
    82.         {
    83.             prop.serializedObject.ApplyModifiedProperties();
    84.         }
    85.     }
    86.     private static Type GetType(string typeName)
    87.     {
    88.         var type = Type.GetType(typeName);
    89.         if (type != null) return type;
    90.         foreach (var a in AppDomain.CurrentDomain.GetAssemblies())
    91.         {
    92.             type = a.GetType(typeName);
    93.             if (type != null)
    94.                 return type;
    95.         }
    96.         return null;
    97.     }
    98. }
    99.  
    100.  
    The function "GlobalPAT" is basically a copy of the property drawer for PATs, I will add such an static function to the actual PAT so people can use it with serialized properties (thanks for that!), let me know if you need further assistance, hope it helps!
     
  45. heroes1

    heroes1

    Joined:
    Nov 16, 2015
    Posts:
    17
    Hi Jake,

    Thanks alot for your help. :):)
    Now i can make my own custom editors.
     
    JakeTBear likes this.
  46. orangewk

    orangewk

    Joined:
    Jun 16, 2015
    Posts:
    1
    Hi,Thank you for updating!

    I updated prefabAtlas to 2.3.0.

    PA 2.3.0 could have bugs,(maybe they occur when recycling pooled objects?)

    "NullReferenceException: Object reference not set to an instance of an object
    PrefabContainer.Create (UnityEngine.Vector3 Pos, UnityEngine.Quaternion Rotation) (at Assets/PrefabAtlas/Components/PrefabContainer.cs:688)
    PrefabAtlas.SpawnWithParent (UnityEngine.Transform Parent, BulletsTag ID, UnityEngine.Vector3 Position, UnityEngine.Quaternion Rotation) (at Assets/PrefabAtlas/Components/PrefabAtlasExtension.cs:756)"
     
  47. JakeTBear

    JakeTBear

    Joined:
    Feb 15, 2014
    Posts:
    123
    @orangewk Hey, could you please share the code you using? I would like to better assist you.