Skip to content
Snippets Groups Projects
Select Git revision
  • b1d7e5080e04f57cd087f4f6d37fad2d19153844
  • main default
  • master
  • tempAndrToMaster
4 results

PointWrapper.cs

Blame
  • Gadget.cs 2.88 KiB
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Reflection;
    using UnityEngine;
    
    /// <summary>
    /// Base class for all Gadgets to derive from.
    /// A Gadget is a tool for the player (and level editor) to interact with the GameWorld.
    /// </summary>
    public abstract class Gadget: MonoBehaviour
    {
        /// <summary> Position in tool belt. </summary>
        /// <remarks>Set in Inspector or <see cref="Awake"/></remarks>
        public int id = -1;
        /// <summary> Tool Name </summary>
        /// <remarks>Set in Inspector or <see cref="Awake"/></remarks>
        public string UiName = "Name Not Set";
        /// <summary> Maximum range for this Tool. For consistency use GadgetDistances in <see cref="GlobalBehaviour"/>.</summary>
        /// <remarks>Set in Inspector or <see cref="Awake"/></remarks>
        public float MaxRange;
    
        /// <summary>Which sprite to use</summary>
        /// <remarks>Set in Inspector</remarks>
        public Sprite Sprite;
        /// <summary>Layers to ignore for this gadget by default.</summary>
        /// <remarks>Set in Inspector</remarks>
        public LayerMask ignoreLayerMask;
        /// <summary>Which cursor to use</summary>
        /// <remarks>When not set in Inspector, will be searching for any <see cref="WorldCursor"/>.</remarks>
        public WorldCursor Cursor;
    
        /// <summary>
        /// Collection of <c>Type</c>s of *all* available <see cref="Gadget"/>s to choose from.
        /// </summary>
        public static readonly IEnumerable<Type> GadgetTypes = Assembly.GetExecutingAssembly().GetTypes().Where(typeof(Gadget).IsAssignableFrom);
    
    
        void Awake()
        {
            if (Cursor == null)
                Cursor = GameObject.FindObjectOfType<WorldCursor>();
    
            CommunicationEvents.TriggerEvent.AddListener(_OnHit);
    
            _Awake();
        }
    
        void OnEnable()
        {
            this.Cursor.setLayerMask(~this.ignoreLayerMask.value);
            Cursor.MaxRange = MaxRange;
    
            _OnEnable();
        }
    
        void OnDisable()
        {
            _OnDisable();
        }
    
        public void OnHit (RaycastHit hit)
        {
            _OnHit(hit);
        }
    
        public abstract void _Awake();
        public abstract void _OnEnable();
        public abstract void _OnDisable();
    
        /// <summary>
        /// Called when <see cref="CommunicationEvents.TriggerEvent"/> is invoked, a.k.a. when Player clicks in GameWorld.
        /// </summary>
        /// <param name="hit">the position where it was clicked</param>
        public abstract void _OnHit(RaycastHit hit);
    
        public class UndefinedGadget : Gadget
        {
            public override void _Awake()
            {
                throw new NotImplementedException();
            }
    
            public override void _OnDisable()
            {
                throw new NotImplementedException();
            }
    
            public override void _OnEnable()
            {
                throw new NotImplementedException();
            }
    
            public override void _OnHit(RaycastHit hit)
            {
                throw new NotImplementedException();
            }
        }
    }