This is the multi-page printable view of this section. Click here to print.

Return to the regular view of this page.

Documentation

I appreciate your interest in Case Opening Toolkit, welcome to the documentation. Please follow through with the documentation for getting started.

You can reach me out in solclovser@gmail.com or my discord server for any additional questions.

1 - Getting Started - Setup

After you import the package, you will be greeted with some console error messages saying “unknown reference DG”. It refers to DOTween not being present in the project. Go ahead and get and import it from the Unity Asset Store.

Then when you open the Demo scene in the demo folder you will be prompted to install Text Mesh Pro. Select the essentials and you will be ready to explore!

When you hit play you will be able to select one of the two pre-made cases as well as one example case with pre-determined outcome.

2 - Start Using It

Drag and drop Generic Case Opening Panel into your Canvas. Then right click on the newly created object in the hierarchy and select Prefab > Unpack.

(The Canvas Scaler settings in demo scene is 1280 x 720 Scale With Screen Size if you want the exact same result.)

«Case Opening Visual Controller» script is responsible for filling the case with items, playing the opening animations, reporting the start and complete events and customization settings.

The «Generic Case Controller» is the simple basis of any implementation you might want to do. It holds the main functionality. It includes comments in each step in the script file and demo cases are a changed copy of it.

You can assign one of the demo case configs in the appropriate field and test if it’s working. I don’t recommend directly editing the script, that’s why we are going to create ours.

2.1 - Create Your Own Controller

Copy

Create a script file on anywhere you are comfortable (outside of the package folder). Copy the contents of «Generic Case Controller» and paste it on your own script.

Change the class name with your own and change the namespace with yours or completely remove it.

Rewire

We are going to delete the «Generic Case Controller» from our panel and add our new script.

Some fields gone missing now because we deleted the script.

  1. Drag and drop your case controller on inspector (not the actual file) to On Animation Start and On Animation Complete fields. Then select the appropriate function from your controller from the dropdown.
  2. Select the Open Button from hierarchy and drop it on the Open Button field on your controller script.
  3. Click on the Open Button and drag Generic Case Opening Panel to button On Click field. Select your controller from the dropdown and select OpenCase function.
  4. Select one of the pre-made configs for Case Config field for testing purposes.
  5. And test opening the case.

We should have a functioning case with our own editable script at this point. Try Debug.Logging something out on animation complete!

Next we are going to create our own case contents.

2.2 - Create Your Own Case Contents

Create a Case Item

You can inspect the items in Demo > Cases > (Select any) > Items for example.

Visual

Most effective way of creating a Case Item visual is actually creating it in the panel because width and height of the visual is governed by the Grid Layout Group that is on the Strip Inner - Item Container.

Select Strip Inner - Item Container located in Generic Case Opening Panel from the hierarchy and add an UI Image to it. Then duplicate it until you can see it in the panel.

Now do your decoration to it and maybe add some icons or text.

Script

Now we need to handle the script for the item.

Create a script for your item. Then inherit from CaseItemBase.

using SolClovser.CaseOpeningToolkit.Base;

public class YourCaseItem : CaseItemBase
{    
}

Then add it to your item and save your item as a prefab. Don’t forget to clear the contents of Strip Inner - Item Container after doing this.

Config

We need to create a config file to store our case config.

Right click anywhere in the project window and select Create > Case Opening Toolkit > New Config.

Add your item to the filler items list in config. This list is used to populate the unimportant parts of the case such as the portion before your actual items show up.

Then add a Probability Group to the list and add your item to Items in it. Raise the probability slider. It’s probability will be 100% because it is the only item in the list.

Select your Case Config as the config for the panel. Now name your panel and save it as a prefab. Congratulations! You just created your first case.

2.3 - Testing Probabilities

After selecting the case config, you can press Test Spin and see the outcome of 1000 (or any amount) case openings in the logs.

3 - Customizing Further

Panel Visual

Anything you see in the panel is changeable and editable.

  1. You can change the panel size by playing with width and height in Rect Transform(changing by scale is not supported).
  2. You can change the panel background image.
  3. You can change the panel border image.
  4. You can change the strip’s height and background.
  5. You can change the button.

Item Spacing And Size

The width and height of the visual is governed by the Grid Layout Group that is on the Strip Inner - Item Container.

Case Opening Visual Controller

Max Landing Padding

It is how further you want item to be away from the left and right edges upon landing. Leave it at default if you want landing to be possible close to the edges. Increase it if you want pointer to stop more in the middle.

Animation Duration

How long the opening animation will take.

Starting Filler Count

How fast the items will move while opening.

4 - Scripting Reference

Here you will find useful public properties you will most likely use and methods you can override.

4.1 - SolClovser.CaseOpeningToolkit.CaseConfig

Properties

public List<CaseItemBase> ItemList

Built when the case is first initialized. It is linear, meaning, if you were to open case config and start counting items in all groups top to bottom, it would end up being same with this list.

4.2 - SolClovser.CaseOpeningToolkit.Base.CaseItemBase

Public Fields

Generic fields that’s common in every item.

public long itemId;
public RawImage itemIcon;       // The raw image component that holds the item icon.
public string itemName;
public int itemValue;

Properties

public float ProbabilityInheritedFromGroup

The true probability of the item, inherited from the group it was in.



Methods

Overrideable Methods

public virtual void Setup()

Called during the population process of the case, when the item is instantiated. You can override this to do any setup work in your item. For example; setting the name text of the item.

4.3 - SolClovser.CaseOpeningToolkit.Base.CaseController

Properties

protected CaseItemBase SelectedItem

Set after the item has been selected. Can be accessed from within child classes.



protected int SelectedItemIndex

Index of the SelectedItem within the built ItemList of config.



Methods

protected void Init()

Initializes the case and populates the visuals of the case.



Overrideable Methods

protected virtual int PickItem()

Selects an item from the case based on probabilities. You can override this in your case controller to change item selection algorithm.



public virtual void OpenCase(bool skipRandomizing = false)

Kicks off the case opening process. Pass true if you want to skip re-populating the case before opening.