Unity3D : Global Debug On/Off

I have a custom template class for new C# class in Unity. Mostly cause I was too „lazy“ to use a debug singelton class or enhance the GameObject/Object class with a custom debug function.

        protected void dbg(string message, bool error = false)
        {
            if (debugMode & !error)
                Debug.Log("[ " + this.GetType().Name + " ( " + Time.time + " / " + Time.frameCount + " )] " + message);

            if (error)
                Debug.LogError("<color=\"red\">[" + this.GetType().Name + " (" + Time.time + ")] " + message + "</color>");
        }

So now I have a lot of Classes using this function and it can be turned off in the inspector with a toggle. But after a while of course this ends in chaos, since when you just want a certain aspect you are working appear in the console, you have to go through all of those classes and turn debug off manualy.

Instead I now added a static menu function that uses reflection to turn the debug state of each class on or off globally.

#if UNITY_EDITOR

using UnityEditor;
using System.Reflection;

#endif

        [MenuItem("InterAction Project/Global Debug Toogle - On")]
        public static void GlobalDebugToggleOn()
        {
            List<Component> componentsWithDebugModeMember = new List<Component>();

            GameObject[] allGameObjects = FindObjectsOfType<GameObject>();

            foreach (GameObject gO in allGameObjects)
            {
                Component[] components = gO.GetComponents(typeof(Component));
                foreach (Component component in components)
                {
                    Type typeOfComponent;

                    typeOfComponent = component.GetType();

                    var f = typeOfComponent.GetField("debugMode");

                    if (f != null)
                    {
                        foreach (FieldInfo propBase in component.GetType().GetFields())
                        {
     
                            if (propBase.Name == "debugMode")
                                propBase.SetValue(component, true);

                        }

                    }
                }
            }
        }

Then I can turn on only the Classes I actually need to display debug informations at the moment. Nothing fancy, but I think it may be useful for some of you out there. 🙂

Rigging or Scripting – that is here the question.

My character is holding a flashlight.

My character is holding a flashlight. But I also have two animations in the animation controller running. One for the idle animation or walking in one layer, and one for the hand actions in another layer, seperated by a layer mask.

„Rigging or Scripting – that is here the question.“ weiterlesen

The ActionableObjects and the User Input

When the player has focused an object that, or, on that an action can be performed, a menu with the action options is shown. (see last entries)

Overview of the flow of user input to actionable objects

In the character controller, which handles the player input, the event functions in the scene controller for these two actions are registered to event delegates in the character controller.

„The ActionableObjects and the User Input“ weiterlesen

Not really a quest system (yet), rather a basic interaction system. #4

So this is growing, but its now a fully functional interaction system. The player (or other entities soon) can see objects they can interact with and get a menu that builds itself from the actions they can perform on that object.

This is not as flexible as I want it to be at all, yet. But I have to make a comprimise between getting it done and make it perfectly reusable.

Being seen is half the battle – a (very simple) Quest-System for Unity (#3)

This is the system now that makes it possible for the Actionable Object to track if its seen or not seen. Now it can give the Game System (ControllerGameScene in this case) all the actions or informations that the game system needs to present the player choices or possible actions. This will be done via a UI menu or hotkeys.

See the things in the world. A (very basic) Object identifier and interaction system for Unity (work in progress #1)

The player, or anything with the ability to „see“, needs a way to recoginze objects. But only those objects that can be interacted with are actually interesting.

Those objects I call „ActionableObjects„. If the player is looking at one, the ActionableObject gets informed about this. It also gets notified if the viewer (player) stops looking at it.

To accomplish this, a viewer (player) has an Eye Module.

„See the things in the world. A (very basic) Object identifier and interaction system for Unity (work in progress #1)“ weiterlesen

A (very basic) Quest/Environment System for Unity (ongoing) #1

Questnodes

Questnodes are the trigger elements. They work closly together with the Game Scene Controller. After being triggerd once, a Questnode deactivates itself, if multipleTriggering is not set to true. If it is set to true, the Questnode will trigger again if the player leaves and enteres the trigger collider again.

„A (very basic) Quest/Environment System for Unity (ongoing) #1“ weiterlesen