Cocodrilo Dog's core tools for general purpose.
To install the Core package in your Unity project, open the Package Manager and click the plus button, "Add package from URL..." and the use this URLs:
https://github.com/cocodrilodog/tools-core.git
A code standard guide for C# in Unity.
For more details:
See the CodeStandard_Example script from the samples of this package.
This helps a team of developers to agree on the coding style and makes every script in a project to look as if it was created by the same person. This makes it very easy to understand the code of your teammates.
A set of attributes that improves quality of life for Unity developers.
For more details:
See the Attributes_Example scene from the samples of this package.
[MinMaxRange]Inspector control to set ranges with sliders.[HorizontalLine]A decorative horizontal line in the inspector.[CreateAsset]Creates an asset of the type of the property, where the property derives fromScriptableObject.[StringOptions]On a string field, draws a popup with options to choose from.[Help]Draws a HelpBox based on a custom method.[Hide]Hides the field, depending on a custom method.[Button]Makes an inspector button that invokes the method below the attribute.[ReadOnly]Makes the field read-only.[UnityEventGroup]Groups multiple Unity events under a toolbar.
This component helps to easily identify and react to collisions.
For more details:
See the Collision_Example scene from the samples of this package.
Normally developers would need to create some code in MonoBehaviours implementing OnCollision... or OnTrigger... functions and comparing game object tags or any other identifying system in place, in order to achieve the desired collision results.
With the CollisionTrigger, you can decide what to do when an object collides with another object and react according to the nature of other object. And you can set all that in the inspector!
For example, you can use a CollisionTrigger in a character and make the character gain gold when the it collides with coins, and lose health when it collides with spikes, without writing a single line of code related to the collision. All that can be setup in the inspector in a matter of seconds.
Base class to create System.Objects that use the [SerializeReference] attribute and that need to be polymorphic. This class is suitable for creating composite structures like the one shown below, hence the name CompositeObject.
For more details:
See the Composite_Example scene from the samples of this package.
Derived classes from CompositeObject support polymorphism, which means that any field declared as MyCompositeObject, for example, can serialize data of any other class that derives from MyCompositeObject.
In the example of the images below, I created an abstract class FileBase:
[Serializable]
public abstract class FileBase : CompositeObject { }
Then I created a concrete class TextFile:
[Serializable]
public class TextFile : FileBase {
[SerializeField]
private string m_Text;
}
Additionally, I created a container class Folder:
[Serializable]
public class Folder : FileBase {
[SerializeReference] // <- Notice the SerializeReference attribute.
private List<FileBase> m_Files;
}
Finally, in the MonoBehaviour example class, I declared a Folder field , like this:
[SerializeReference] // <- Notice the SerializeReference attribute.
private Folder m_MyDisk;
In this example, any field declared as FieldBase can hold either a Folder or a TextFile instance, and a Folder can contain children FileBase instances which again, could be either Folder or TextField. This creates a composite structure.
In the images sequence below, I navigate throught the composite of folders and files:
This last image shows how a new entry would be created:
This tech, was designed to be used in the MotionKit initially, but it has found its place in many other tools created by Cocodrilo Dog. It incorporates a breadcrumb structure in the inspector so that complex composite structures can be easily navigated.
Base classes MonoCompositeStateMachine, ScriptableCompositeStateMachine and concrete classes MonoFlowStateMachine and ScriptableFlowStateMachine used to create state machines that uses the CompositeObject technology to create polymorphic states.
For more details:
See the CompositeStateMachine_Example scene from the samples of this package.
State machines using these classes expose the individual states of the machines in the inspector, allowing the developer to edit custom properties of each state, as well as to trigger actions OnEnter and OnExit of each state.
State machines that inherit from MonoCompositeStateMachine or ScriptableCompositeStateMachine can implement any logic in the states and their respective transitions. By programming the custom state machines and their respective states, the states can be left open for further editing or can be made read-only in the inspector, depending on the specific needs of the state machine.
Example of a class derived from MonoCompositeStateMachine:
This rotates a circle around a distant point, and depending on the angle, it will have one of three colors. The logic is implemented in the individual state classes, like this:
[Serializable]
public class Red : State {
public Red() => m_Color = Color.red;
public override void Enter() {
base.Enter();
Machine.m_BallContainer.GetComponentInChildren<Image>().color = m_Color;
Debug.Log("Red");
}
public override void Update() {
base.Update();
if(Machine.m_BallContainer.localEulerAngles.z >= 120) {
TransitionToState("Green");
} else if (Machine.m_BallContainer.localEulerAngles.z >= 240) {
TransitionToState("Blue");
}
}
}
Example of MonoFlowStateMachine used to create a simple media player mechanism:
Did you ever wanted to work with interfaces in a Unity-friendly way, like this?
// Declare a variable of type IAnyInterface
[SerializeField]
private InterfaceField<IAnyInterface> m_AnyInterfaceObject;
// And then use it
private void Start() {
m_AnyInterfaceObject.Value.SomeMethod();
}
For more details:
See the InterfaceField_Example scene from the samples of this package.
InterfaceField was created for this purpose. This works with the normal Unity drag-and-drop system. If you declare an InterfaceField<SomeInterface>, It will receive any MonoBehaviour or ScriptableObject that implements SomeInterface, for example.
The Core package comes with some MonoBehavior-derived classes that solve common problems. Here is a table of the main ones:
ScriptableObjects that are used to store values or reference of other objects at a project level.
For more details:
See the ScriptableReference_Example scene from the samples of this package.
This is an easy way to store variables in a "global" way. This helps when:
- A value is shared by many objects. For example a
stringor afloat. - We need to have a reference of an object from another scene.
- We need to have a reference of an object that resides in the
DonDestroyOnLoadgroup. - We create objects with code and want wo have reference to other objects, and we don't want to set the references with code.
With this system, we can avoid the temptation of making singletons just to get the reference to an object through the GetInstance() method, which is a very common pitfall.
1- A ScriptableValue<T> is created in the project:
2- The value is used by another object:
1- A ScriptableReference is created in the project:
2- An object is sent to that ScriptableReference with the ScriptableReferenceSetter:
3- The object is used by another object with the ScriptableReferenceField<T>:
StringOptions is a ScriptableObject that contains a list of strings and can be used in conjunction with the [StringOptions] attribute to make a string property to use a popup with the available values to choose from, instead of the normal input text.
For more details:
See the StringOptions_Example scene from the samples of this package.
This is a clean way to work with a set of strings with fixed values. Some possible advantages:
- This can be used to replace enums in many cases, without the need to add enum values in the code, but just adding new strings to the
StringOptionsasset. - This can be used to replace Unity's built-in tags system. If the number of tags in the project increases, with
StringOptions, the tags can be easily grouped, added, removed, changed, and reordered. This is a way more scalable solution as compared with Unity tags.
1- Create a StringOptions asset:
2- Declare a string field and use the [StringOptions] attribute:
[StringOptions("SomeStringOptions"))]
public string SomeString;
The string parameter can be:
- The name of a
StringOptionsasset on a Resources folder. - The name of a field of type
StringOptions, declared in the same object. - The name of a method that returns a
List<string>.
This system is used by the CollisionTrigger component for tagging the objects.

