Skip to content

Instantly share code, notes, and snippets.

View tolgayilmaz86's full-sized avatar
๐Ÿ 
Working from home

Tolga YILMAZ tolgayilmaz86

๐Ÿ 
Working from home
  • Freelance
  • The Netherlands
  • 19:54 (UTC +02:00)
  • LinkedIn in/tlgylmz
View GitHub Profile
@tolgayilmaz86
tolgayilmaz86 / SingletonContainer.cpp
Last active November 17, 2024 17:16
๐—ฆ๐˜๐—ผ๐—ฟ๐—ถ๐—ป๐—ด ๐—”๐—ป๐˜† ๐—ข๐—ฏ๐—ท๐—ฒ๐—ฐ๐˜ ๐—ถ๐—ป ๐—ฎ ๐—–๐—ผ๐—ป๐˜๐—ฎ๐—ถ๐—ป๐—ฒ๐—ฟ ๐—ช๐—ถ๐˜๐—ต๐—ผ๐˜‚๐˜ ๐šŸ๐š˜๐š’๐š* ๐—ผ๐—ฟ ๐—›๐—ถ๐—ฒ๐—ฟ๐—ฎ๐—ฟ๐—ฐ๐—ต๐—ถ๐—ฒ๐˜€
/*
If you're looking to store any type of object in a container without using ๐šŸ๐š˜๐š’๐š*
or creating a new hierarchy, ๐šœ๐š๐š::๐šŠ๐š—๐šข might be a good choice.
It can store any type, but retrieving the stored value requires caution,
as you need to know the type to use ๐šœ๐š๐š::๐šŠ๐š—๐šข_๐šŒ๐šŠ๐šœ๐š effectively.
One useful application for this approach is an object storage class that maintains
a list of singletons. This class, ๐š‚๐š’๐š—๐š๐š•๐šŽ๐š๐š˜๐š—๐š‚๐š๐š˜๐š›๐šŠ๐š๐šŽ,
offers a ๐š๐šŽ๐š method that either returns an existing object or creates
a new one if it doesnโ€™t exist. Internally,
๐š‚๐š’๐š—๐š๐š•๐šŽ๐š๐š˜๐š—๐š‚๐š๐š˜๐š›๐šŠ๐š๐šŽ uses a hash map with ๐šœ๐š๐š::๐š๐šข๐š™๐šŽ_๐š’๐š—๐š๐šŽ๐šก as the key and ๐šœ๐š๐š::๐šŠ๐š—๐šข as the value.
// Credit to damien_oconnell from http://forum.unity3d.com/threads/39513-Click-drag-camera-movement
// for using the mouse displacement for calculating the amount of camera movement and panning code.
using UnityEngine;
using System.Collections;
public class MoveCamera : MonoBehaviour
{
//