public EntPhysics(EntityKeyValues KVs) { string ModelName = KVs.Get <string>("model"); libTechModel Model = KVs.Map.LoadModel(ModelName); Init(Model, 18); SetWorldTransform(Vector3.One, KVs.Get <Quaternion>("qangles"), KVs.Get <Vector3>("origin")); }
public DynamicLight(EntityKeyValues KVs) { float Radius = KVs.Get <float>("_distance"); if (Radius == 0) { Radius = KVs.Get <float>("_zero_percent_distance"); if (Radius == 0) { Radius = 250; } } Init(KVs.Get <Vector3>("position"), KVs.Get("_light", Color.White), Radius); }
public static Entity CreateInstance(string ClassName, EntityKeyValues KVs) { for (int DefIdx = 0; DefIdx < EntityDefs.Length; DefIdx++) { if (EntityDefs[DefIdx].ClassName == ClassName) { Type EntType = EntityDefs[DefIdx].EntityType; if (KVs.Count == 0) { return((Entity)Activator.CreateInstance(EntType)); } foreach (var C in EntType.GetConstructors()) { EntityKeyAttribute[] KeyAttribs = C.GetParameters().Select(P => P.GetCustomAttribute <EntityKeyAttribute>()).ToArray(); if (KeyAttribs.Length == 0) { continue; } bool ValidConstructor = true; for (int i = 0; i < KeyAttribs.Length; i++) { if (KeyAttribs[i] == null || !KVs.Contains(KeyAttribs[i].KeyName)) { ValidConstructor = false; break; } } if (!ValidConstructor) { continue; } return((Entity)C.Invoke(KeyAttribs.Select(KA => KVs.Get(KA.KeyName).Value).ToArray())); } ConstructorInfo CInf = null; if ((CInf = EntType.GetConstructor(new[] { typeof(EntityKeyValues) })) != null) { return((Entity)CInf.Invoke(new object[] { KVs })); } throw new NotImplementedException(); } } return(null); }