Project: Treasure Hunter (formerly Dungeon Explorer)
Goal: Develop and release first game
Initial Commit: 7 Aug 2019

Dev Hours Since Last Devlog: 60.29
Total Dev Hours Spent: 130.5
Allocated Dev Hours: 160

At a Glance

If I let them side quests will suck away all my time, and that’s what happened since I wrote my last devlog in September. On the up side, I finally made my way back to my primary quest line, to develop and release my first game. Since then, I managed to log about 60 hours of dev time as well as naming my game Treasure Hunter: Quixxen’s Suit. Rather than discuss all of the things I worked on I will focus on the draggable panel I created.

Main Quest Progress

After making it so a player can complete a quest, I turned my attention to the research tree. The first thing I created was a custom sortable ResearchItem class. That was straightforward, so next up I wanted a draggable panel to display the research tree. I found some code that implemented a simple draggable window, however, it didn’t work whenever I changed the resolution and had a few other issues with some features I wanted to add.

I wanted to add a few features that seemed simple.

  • Clamping the panel to the screen at all resolutions;
  • Allow the user to toggle clamping on/off;
  • Toggle on/off the ability to move the panel partially off screen and then have it close automatically;
  • Configured the offset amount for the auto-close feature.

It turned out that the code I found couldn’t support my features without extensive refactoring. Back to Google I went.

On my second try I found the Unity Samples: UI asset pack. The DragPanel.cs script had the basic functionality I needed and was simpler then my last code. At first I tried to merge the two code bases together, but that didn’t work. After that I wiped the slate clean and dropping in Unity’s code. It worked perfectly at all tested resolutions. Awesome!

Now that I got the basics working, next up my extras, which turned out to be easy to fold into Unity’s code. Now that I had my code working I created a GitHub public repo for my 2D examples. So far, just DragWindow.cs and a GameObject extension called FindInParents<T> are there but I have to start somewhere.

The gifs below showoff my work. The first one displays the panel clamped to the screen, while the second showcases the offset close feature.

Here is my code, the first one is the GameObject extension that implements FindInParents<T> and the second is my DragWindow script.

using UnityEngine;

namespace SpaceMonkeys.Core
    public static class GameObjectExtension
        public static T FindInParents<T>(this GameObject gameObject, GameObject go) where T : Component
            if (go == null) return null;
            var comp = go.GetComponent<T>();

            if (comp != null) return comp;

            var t = go.transform.parent;
            while (t != null && comp == null)
                comp = t.gameObject.GetComponent<T>();
                t = t.parent;
            return comp;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
using SpaceMonkeys.Core;

namespace SpaceMonkeys.UI
    /// <summary>
    /// A script that you drop on a child object to the "window" GameObject you want to move around.
    /// </summary>
    /// <remarks>
    /// Find the GitHub code at
    /// Find the specific file at
    /// </remarks>
    public class DragWindow : MonoBehaviour, IDragHandler, IPointerDownHandler, IPointerUpHandler
        #region Members
        [SerializeField] private Image _contentImage = default;
        [SerializeField] [Range(0f, 1f)] private float _contentImageAlpha = .4f;

        [Header("Clamping Options")]
        [SerializeField] private bool _clampToScreen = true;
        [SerializeField] private bool _useOffScreenToClose = false;
        [SerializeField] private float _allowedOffset = 250f;

        private RectTransform _panelRT;
        private RectTransform _dragAreaRT;
        private Vector2 _originalLocalPointerPos;
        #endregion Members

        #region MonoBehaviours
        void Awake()
            _panelRT = transform.parent as RectTransform;
            _dragAreaRT = gameObject.FindInParents<Canvas>(transform.parent.gameObject).gameObject.GetComponent<RectTransform>();
        #endregion MonoBehaviours

        #region Interface Implementations
        public void OnPointerDown(PointerEventData data)
            OriginalPosition = _panelRT.localPosition;
            RectTransformUtility.ScreenPointToLocalPointInRectangle(_dragAreaRT, data.position, data.pressEventCamera, out _originalLocalPointerPos);
        public void OnDrag(PointerEventData data)
            if (_panelRT == null || _dragAreaRT == null) return;

            if (RectTransformUtility.ScreenPointToLocalPointInRectangle(_dragAreaRT, data.position, data.pressEventCamera, out Vector2 localPointerPos))
                Vector3 offsetToOriginal = localPointerPos - _originalLocalPointerPos;
                _panelRT.localPosition = OriginalPosition + offsetToOriginal;
            if (_clampToScreen)
                _panelRT.localPosition = _useOffScreenToClose ? ClampToScreen(_allowedOffset) : ClampToScreen();
        public void OnPointerUp(PointerEventData data)
            if (!IsFullyOnScreen)
                _panelRT.localPosition = OriginalPosition;
        #endregion Interface Implementations

        #region Properties
        public Vector3 OriginalPosition { get; private set; }
        public bool IsFullyOnScreen
                bool ans = true;
                Vector3[] worldCorners = new Vector3[4];

                ans &= !(worldCorners[0].x < 0);
                ans &= !(worldCorners[2].x > Screen.width);
                ans &= !(worldCorners[0].y < 0);
                ans &= !(worldCorners[2].y > Screen.height);

                return ans;

        #endregion Properties

        #region Helpers
        private void ChangeAlpha()
            if (_contentImage != null)
                Color bg = _contentImage.color;
                switch (bg.a)
                    case 1f:
                        bg.a = _contentImageAlpha;
                        bg.a = 1f;
                _contentImage.color = bg;
        private Vector3 ClampToScreen() => ClampToScreen(0f);
        private Vector3 ClampToScreen(float offset)
            Vector3 pos = _panelRT.localPosition;
            Vector3 minPos = _dragAreaRT.rect.min - _panelRT.rect.min;
            Vector3 maxPos = _dragAreaRT.rect.max - _panelRT.rect.max;

            pos.x = Mathf.Clamp(_panelRT.localPosition.x, minPos.x - offset, maxPos.x + offset);
            pos.y = Mathf.Clamp(_panelRT.localPosition.y, minPos.y - offset, maxPos.y + offset);

            return pos;
        #endregion Helpers


Keep On Questing

I’m roughly on track with my schedule from Planning For More Adventures. However, I don’t think I’ll make the 160 hours for v1. It’s good to have goals and it’s good to know when need to adapt to meet those goals.

Life’s an adventure – what’s your quest?

Git Commit History

fe6ae22 Update DragWindow so it acutally works; 2020-03-30
2327193 Create baseline to start implementing Research; 2020-03-23
0f1a39f Update Quest Location prefab button to cover progress bar; 2020-03-23
e89ee92 Create basic Research Item game object for testing; 2020-03-23
b185cfa Create StartingIncomeResearch class; 2020-03-23
47df235 Move ResearchItem to Classes folder; 2020-03-23
78702aa Merge branch ‘Research’ of into Research; 2020-03-23
e2e4376 Refactor LeveledFloat; 2020-03-23
07b2b76 Refactor LeveledFloat; 2020-03-23
657b6e2 Refactor ResearchItem; 2020-03-23
e036d7e Refactor Equality and HashCode; 2020-03-20
f3ce21f Fix DragWindow for multiple screen sizes; 2020-03-16
cfdd968 Fix ResearchPanel blocking GameManager; 2020-03-16
3aed3c6 Save MainGame file; 2020-03-15
d21282b Remove temp sounds and unneeded areas; 2020-03-15
cc7f6bd Update research points; 2020-03-14
74d10e4 Update ResearchPanel to correctly display available zones; 2020-03-09
ebfdcaa Make Goals easier to achieve for testing; 2020-03-01
598efa1 Update PointDisplay to use ReserachManager; 2020-03-01
a8a935d Add ResearchManager to ExplorationZone; 2020-03-01
caf5768 Update Researchitem for equality and comparability; 2020-02-29
c265dff Implement ResearchManager; 2020-02-29
9fc50ce Fix Unity project ref warnings; 2020-02-29
33d5345 Updated to Unity 2019.2.21f1; 2020-02-26
aa066ef Refactored EncounterIndex; 2020-02-25
7e6018c Convert To Unity 2019.3; 2020-02-18
9b46931 Fixed IncomeGoal Bug; 2020-02-11
2cc6c0d Fixed Research Toggle Bug; 2020-02-11
03bcdb4 Fixed Double GoalCompleted Bug; 2020-02-11
d2579d0 Refactored Stat; 2020-02-10
6801422 Refactored Lots; 2020-02-10
bc2d009 Added RequiredComponent; 2020-02-10
c0efeab Standardizing Code; 2020-02-10
c2afafa Renamed QuestGoal to Goal; 2020-02-09
a78eb22 Created ExplorationZone; 2020-02-09
abe2429 Added ‘s’ to BurialMound; 2020-02-09
521f720 Change QuestZone to ExplorationZone; 2020-02-09
2dd72a3 Wired CompleteGoal In Editor; 2020-02-09
7faaf9e Tweaked QuestZoneDetails; 2020-02-09
a0cca43 Tweaked Location; 2020-02-09
d6b3230 Lazy Load Location’s Quest; 2020-01-28
b1e8725 Refactored WorkingQuest to Location; 2020-01-27
b010771 Added Location to Quest; 2020-01-27
fd6376f Removed Awake from Location.cs; 2020-01-20
47b72d4 Prepped Changes For Adding Location to Quest; 2020-01-20
8722104 Updated DisplayCurrency; 2020-01-20
97a54cb Created Location To Replace WorkingQuest; 2020-01-20
88a0987 Cleaned Up GameManager Code; 2020-01-11
f9704e8 Saved MainGame File; 2020-01-10
66931e8 Updated ScreenActionShortcuts For Research Toggle; 2020-01-01
3d5fab8 Updated Point Display Prefab; 2020-01-01
81404cd Created Window Prefabs; 2020-01-01
5a6e64f Saved MainGame File; 2019-12-31
403280c Create GameObjectExtension Class; 2019-12-31
a040872 Completed DragWindow Script; 2019-12-30
06aa124 Creating Standard Window; 2019-12-29
5758411 Created Toggle Button Prefab; 2019-12-27
8e12441 Added Up/Down Arrow Image; 2019-12-26
a2d869c Added ResearchItem Base class; 2019-12-26
8ecb78d More Folder Cleanup And Research Shortcut; 2019-12-26
5c3c301 Folder Cleanup On Aisle 2; 2019-12-26
e9a05ad Created PointDisplay Prefab; 2019-12-24
7214067 Cleaned Up Prefab Folder; 2019-12-24
13190e5 Numerous Updates; 2019-12-22
1debe03 Refactored WorkingQuests Images; 2019-11-30
47e6953 Refactor QuestZoneDetails; 2019-11-30
28c934f More ProgressBar Refactoring; 2019-11-13
8e95e34 Refactored ProgressBar; 2019-11-12
56baeb9 Started Refactoring ProgressBar; 2019-11-12
bd7a93b Refactored DisplayQuest; 2019-11-10
74a8ade Refactored Shortcuts To Simulate Button Clicks; 2019-11-10
d7d0461 Refactored Encounter Completion; 2019-11-09
9f86cae Commented Out Music Audio Source; 2019-11-09
d24446b Refactored AdventurerDisplay; 2019-11-09
ca43ca8 Refactor Shortcuts; 2019-11-09
56af740 Coded EncounterList Class; 2019-11-09
be5a513 Updated ActiveQuest Refs to ActiveWorkingQuest; 2019-11-09
24c899c Code Reorg; 2019-11-09
587c8e2 Removed DidComplete From EncounterCompletedEventArgs; 2019-11-09
7d5fda2 Changed Variable EncounterNumber to EncounterIndex; 2019-11-09
3858474 Created EncounterCompleted Event; 2019-11-02
fd33999 Created Initial Adventurer’s UI; 2019-11-01
be0e8de Started Overhauling Skills; 2019-10-27
e79e6e1 Added Formulas and LeveledFloat Classes; 2019-10-27
22ba643 Fixed Bug In Stat Class; 2019-10-27
a9deb4d Refactored Quest Income To Use Stat Class; 2019-10-27
b5189aa Renamed Trait to Stat; 2019-10-27
d0932f9 Created Batch File To Change LFS Custom Location; 2019-10-20
4c76283 Updated Gitignore File To Include TextMesh Pro Folder; 2019-10-20
e56dac8 Created GrantIncomeSkill; 2019-09-28
8cfd05a Created Base Skill Class; 2019-09-27
904727c Created ExpertiseType; 2019-09-27
acd0b77 Coded Trait Classes; 2019-09-26
0f0c6b4 Completed Alpha AudioManager; 2019-09-24
9ac7baa Created AudioManager Singleton; 2019-09-23
1926759 Created Save On Run Menu Item; 2019-09-23
0d139a7 Final GameManager-A Commit; 2019-09-23
0c3f380 Started Testing, Found Bugs, Fixed Some, Created More; 2019-09-22

1 Comment »

Send a Missive

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.