Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System;
- namespace Skatebirb.Util
- {
- /// <summary>
- /// This is a market component that exists purely to be found by spawning things that need to spawn at a specific position, or under a specific parent
- /// </summary>
- public class SpawnLocationMarker : MonoBehaviour
- {
- static private SpawnLocationMarker atLeastOneExists;
- /// <summary>
- /// Finds a spawn location of the given name in the currently loaded scene
- /// </summary>
- /// <param name="locName">the name of location to find</param>
- /// <returns>the location, or NULL if none was found</returns>
- static public SpawnLocationMarker FindLocation(string locName)
- {
- if (atLeastOneExists == null) { return null; }
- return atLeastOneExists.FindLocationInternal(locName);
- }
- private SpawnLocationMarker FindLocationInternal(string locName)
- {
- if (string.IsNullOrEmpty(locName)) { return null; }
- // We're searching by name, let's NOT include case, because for fuck's sake
- locName = locName.ToLowerInvariant();
- // @TODO: We could cache this list on Awake, if we needed to? Though it's unlikely to ever be called that often.
- SpawnLocationMarker[] locations = FindObjectsOfType<SpawnLocationMarker>();
- foreach(SpawnLocationMarker location in locations)
- {
- if (location.gameObject.name.ToLowerInvariant() == locName) { return location; }
- }
- return null;
- }
- private void Awake()
- {
- // We do this so that we can do static operations that would normally require a MonoBehavior (like finding-by-component)
- atLeastOneExists = this;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment