示例#1
0
 public void AddGlobalProjectile(string name, GlobalProjectile globalProjectile)
 {
     globalProjectile.mod         = this;
     globalProjectile.Name        = name;
     this.globalProjectiles[name] = globalProjectile;
     ProjectileLoader.globalProjectiles.Add(globalProjectile);
 }
示例#2
0
        private void AutoloadGlobalProjectile(Type type)
        {
            GlobalProjectile globalProjectile = (GlobalProjectile)Activator.CreateInstance(type);

            globalProjectile.mod = this;
            string name = type.Name;

            if (globalProjectile.Autoload(ref name))
            {
                AddGlobalProjectile(name, globalProjectile);
            }
        }
示例#3
0
        /// <summary>
        /// Create a new instance of this GlobalProjectile for a Projectile instance.
        /// Called at the end of Projectile.SetDefaults.
        /// If CloneNewInstances is true, just calls Clone()
        /// Otherwise calls the default constructor and copies fields
        /// </summary>
        public virtual GlobalProjectile NewInstance(Projectile projectile)
        {
            if (CloneNewInstances)
            {
                return(Clone());
            }
            GlobalProjectile copy = (GlobalProjectile)Activator.CreateInstance(GetType());

            copy.Mod           = Mod;
            copy.index         = index;
            copy.instanceIndex = instanceIndex;
            return(copy);
        }
示例#4
0
        internal static void VerifyGlobalProjectile(GlobalProjectile projectile)
        {
            var type = projectile.GetType();

            bool hasInstanceFields = type.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)
                                     .Any(f => f.DeclaringType != typeof(GlobalProjectile));

            if (hasInstanceFields)
            {
                if (!projectile.InstancePerEntity)
                {
                    throw new Exception(type + " has instance fields but does not set InstancePerEntity to true. Either use static fields, or per instance globals");
                }
            }
        }
示例#5
0
文件: Mod.cs 项目: popovn/tModLoader
 public void AddGlobalProjectile(string name, GlobalProjectile globalProjectile)
 {
     globalProjectile.mod = this;
     globalProjectile.Name = name;
     this.globalProjectiles[name] = globalProjectile;
     ProjectileLoader.globalProjectiles.Add(globalProjectile);
 }