/// <summary>
        /// Register a FieldGenerator with EMController. Called automatically by every FieldGenerator on scene start or
        /// upon its creation, whichever is earlier.
        /// </summary>
        /// <param name="NewFieldGenerator">FieldGenerator to register.</param>
        public void RegisterFieldGenerator(FieldGenerator NewFieldGenerator)
        {
            // Make sure new field generator isn't already registered
            if (fieldGenerators.Contains(NewFieldGenerator))
            {
                return;
            }
            // Add new field generator
            fieldGenerators.Add(NewFieldGenerator);

            // Register field type
            RegisterFieldType(NewFieldGenerator.generatedField);
            OnFieldGeneratorRegistered?.Invoke(NewFieldGenerator);
        }
        // Start is called before the first frame update
        protected virtual void Start()
        {
            if (!RigidBody)
            {
                RigidBody = gameObject.GetComponent <Rigidbody>();
            }

            if (!associatedGenerator)
            {
                FieldGenerator generator = GetComponent <FieldGenerator>();
                if (generator)
                {
                    if (generator.generatedField == fieldReactingTo)
                    {
                        associatedGenerator = GetComponent <FieldGenerator>();
                    }
                }
            }
        }
        /// <summary>
        /// Calculate the value of the <paramref name="field"/> at world-space <paramref name="position"/>.
        /// If <paramref name="generatorToExclude"/> is specified, it is left out of the calculation, e.g. for
        /// calculating the electric field at a point charge due to other charges.
        /// </summary>
        /// <param name="position"></param>
        /// <param name="field"></param>
        /// <param name="generatorToExclude"></param>
        /// <returns>Direction and magnitude of the field.</returns>
        public Vector3 GetFieldValue(Vector3 position, InteractionField field, FieldGenerator generatorToExclude = null)
        {
            Vector3 fieldValue = new Vector3(0, 0, 0);

            foreach (FieldGenerator fieldGenerator in fieldGenerators)
            {
                if (generatorToExclude)
                {
                    if (fieldGenerator == generatorToExclude)
                    {
                        continue;
                    }
                }
                if (fieldGenerator.generatedField == field)
                {
                    fieldValue = fieldValue + fieldGenerator.FieldValue(position);
                }
            }

            return(fieldValue);
        }
 /// <summary>
 /// Removes a FieldGenerator from EMController's registry. Called automatically by all FieldGenerators on their
 /// destruction.
 /// </summary>
 /// <param name="RemoveFieldGenerator">FieldGenerator to remove.</param>
 public void UnRegisterFieldGenerator(FieldGenerator RemoveFieldGenerator)
 {
     fieldGenerators.Remove(RemoveFieldGenerator);
     OnFieldGeneratorUnregistered?.Invoke(RemoveFieldGenerator);
 }