/// <summary> Validate a single component's field and handle Custom Attributes </summary> private bool ValidateField(FieldInfo field, GunComponent component) { bool valid = true; bool is_null = (component == null || field.GetValue(component) == null || field.GetValue(component).Equals(null)); foreach (object attribute in field.GetCustomAttributes(true)) { if (is_null && attribute is HasTransformPathAttribute path_attribute) // Try to restore a reference if it is missing { if (RestoreReference(field, component, path_attribute.paths)) { valid = ValidateField(field, component); // Revalidate when we assigned something } } if (attribute is IsNonNull) // This field needs to be set { if (is_null) { valid = false; } } } return(valid); }
// Drawing public void DrawAspectData(GunComponent component) { // Init var obj = new SerializedObject(component); var prop = obj.GetIterator(); prop.Next(true); // Display properties do { if (prop.displayName == "Script" || prop.displayName == "Object Hide Flags") { continue; } if (!IsValid(prop, component)) { Color temp_color = GUI.color; GUI.color = Color.red; EditorGUILayout.PropertyField(prop, new GUIContent(GetFieldLabel(prop.displayName)), true); GUI.color = temp_color; } else { EditorGUILayout.PropertyField(prop, new GUIContent(GetFieldLabel(prop.displayName)), true); } } while (prop.NextVisible(false)); // Finalize obj.ApplyModifiedProperties(); }
//TODO REDUCE COST OF FUNCTION LOL public static void RefreshBulletsText() { if (DontUpdateUI) { return; } //Get Player Current GunComponent Entity currentWeaponEntity = EventsHolder.LevelEvents.CurrentLevel != MapType.Level_Hell ? GameVariables.Player.PlayerWeaponEntities[GameVariables.Player.CurrentWeaponHeld] : GameVariables.Player.PlayerHellWeaponEntities[GameVariables.Player.CurrentWeaponHeld]; GunComponent gun = World.DefaultGameObjectInjectionWorld.EntityManager.GetComponentData <GunComponent>(currentWeaponEntity); //Figure out which text should be displayed if (gun.HasInfiniteAmmo) { if (!MonoGameVariables.Instance.BulletsInfiniteText.gameObject.activeSelf) { ToggleText(true); } return; } if (!MonoGameVariables.Instance.BulletsNormalText.gameObject.activeSelf) { ToggleText(false); } MonoGameVariables.Instance.BulletsNormalText.text = $"{gun.CurrentAmountBulletOnPlayer}/{gun.MaxBulletOnPlayer}"; }
//############################################################################################## // Setup the player, and collect the different components that will get used. //############################################################################################## void Start() { player = this; respawnState = RespawnState.Alive; // Hide the cursor and lock it to screen Cursor.visible = false; Cursor.lockState = CursorLockMode.Locked; // Try to target 60 Application.targetFrameRate = 60; movementEnabled = true; lookingEnabled = true; gun = GetComponent <GunComponent>(); character = GetComponent <CharacterController>(); damage = GetComponent <DamageableComponent>(); damage.RegisterOnDamagedDelegate(OnDamaged); damage.RegisterOnKilledDelegate(OnKilled); respawnTimer = new Timer(respawnTime); shakeDecayTimer = new Timer(SHAKE_DECAY_TIME); safeTimer = new Timer(SAFE_TIME); recoilDecayTimer = new Timer(); jumpTimer = new Timer(jumpTime); sideJumpCooldownTimer = new Timer(SIDE_JUMP_COOLDOWN_TIME); }
private void SelectFire(GunComponent component, SelectiveFire fire, EntityUid?user = null) { if (component.SelectedMode == fire) { return; } DebugTools.Assert((component.AvailableModes & fire) != 0x0); component.SelectedMode = fire; var curTime = Timing.CurTime; var cooldown = TimeSpan.FromSeconds(InteractNextFire); if (component.NextFire < curTime) { component.NextFire = curTime + cooldown; } else { component.NextFire += cooldown; } PlaySound(component.Owner, component.SoundModeToggle?.GetSound(Random, ProtoManager), user); Popup(Loc.GetString("gun-selected-mode", ("mode", GetLocSelector(fire))), component.Owner, user); Dirty(component); }
public void Update(GunComponent gunComponent, InputComponent input, GameobjectComponent gameobjectComponent) { if (gunComponent == null || gunComponent.enable == false) { return; } if (gunComponent.entity.identity.isAIControl == false) { SetDirection(gunComponent, input, gameobjectComponent.transform); } gunComponent.laserTimer.Update(); if (gunComponent.laserTimer.isRunning == false) { if (InputSystem.GetHoldAction(input, "laser")) { gunComponent.laserTimer.Enter(); EmitLaser(gunComponent, gameobjectComponent.transform); return; } } gunComponent.fireTimer.Update(); if (gunComponent.fireTimer.isRunning == false) { if (InputSystem.GetHoldAction(input, "fire")) { gunComponent.fireTimer.Enter(); Fire(gunComponent, gameobjectComponent.transform); } } }
private int GetAmmoAmount(Inventory supply) { int amount = 0; if (supply == null) { return(0); } GunComponent gunComponent = itemReference.GetComponent <GunComponent>(); if (gunComponent == null) { return(0); } foreach (AmmoComponent ammoComponent in supply.GetItemsOfType <AmmoComponent>()) { if (ammoComponent.IsSameType(gunComponent.ammoType)) { amount += ammoComponent.Item.Amount; } } return(amount); }
protected override void Init(SystemComponent component, out float maxDistance) { GunComponent gun = (GunComponent)component; maxDistance = gun.distance; shotType = gun.shipClass; }
private void SwapWeapon(WeaponType type) { swapWeaponTimer = delaySwapWeapon; //Add event to NativeList EventsHolder.WeaponEvents.Add(new WeaponInfo { Parent = GameVariables.Player.Entity, WeaponType = type, EventType = WeaponInfo.WeaponEventType.ON_SWAP }); //Activate/Deactivate weapons Entity currentWeaponEntity = EventsHolder.LevelEvents.CurrentLevel != MapType.Level_Hell ? GameVariables.Player.PlayerWeaponEntities[GameVariables.Player.CurrentWeaponHeld] : GameVariables.Player.PlayerHellWeaponEntities[GameVariables.Player.CurrentWeaponHeld]; Entity desiredWeaponEntity = EventsHolder.LevelEvents.CurrentLevel != MapType.Level_Hell ? GameVariables.Player.PlayerWeaponEntities[type] : GameVariables.Player.PlayerHellWeaponEntities[type]; EntityManager.SetEnabled(currentWeaponEntity, false); EntityManager.SetEnabled(desiredWeaponEntity, true); //Set Cooldown to shoot after swap GunComponent gun = EntityManager.GetComponentData <GunComponent>(desiredWeaponEntity); gun.SwapTimer = gun.OnSwapDelayToShoot; EntityManager.SetComponentData(desiredWeaponEntity, gun); //Set CurrentGunType GameVariables.Player.CurrentWeaponHeld = type; }
public void AddComponent(GunComponent newMod, int indexToInsertInto) { toAddLater[indexToInsertInto] = (new later(newMod, indexToInsertInto)); //var nextOpen = toAddLater.FindIndex(x => x == null); //toAddLater[nextOpen] = new later(newMod, nextOpen); //return; }
public override void AddMod(GunComponent mod, int index) { base.AddMod(mod, index); Refresh(); //var nextOpen = mods.FindIndex(x => x == null); //mods[nextOpen] = mod; }
protected void EquipGun(GunData gunData, GunComponent gunComponent, GameobjectComponent gameobjectComponent) { gunComponent.gunData = gunData; var sprite = Resources.Load <Sprite>(gunData.spritePath); Debug.Log(gameobjectComponent); gameobjectComponent.spriteRenderer.sprite = sprite; }
/// <summary> Check if a component is cached as valid </summary> private bool IsValid(GunComponent component) { if (!validation_cache_components.ContainsKey(component.GetType())) { return(false); } return(validation_cache_components[component.GetType()]); }
public virtual void AddMod(GunComponent mod, int index) { if (mods == null || mods.Capacity == 0 || mods.Count == 0) { Start(); } //var index = mods.FindIndex(x => x == null); mods[index] = mod; }
private void OnGunMeleeAttempt(EntityUid uid, GunComponent component, ref MeleeAttackAttemptEvent args) { if (TagSystem.HasTag(args.User, "GunsDisabled")) { return; } args.Cancelled = true; }
public void InitGun(int gunID, GunComponent gunComponent, GameobjectComponent gameobjectComponent) { if (gunComponent == null || gunComponent.enable == false) { return; } Debug.Log("GunSystem.Init"); EquipGun(EquipmentManager.GetInstance().GetGun(1), gunComponent, gameobjectComponent); }
protected void SetDirection(GunComponent gunComponent, InputComponent input, Transform transform) { Vector3 shotPosition; shotPosition = Input.mousePosition; shotPosition = Camera.main.ScreenToWorldPoint(shotPosition); RotateGun(transform, shotPosition, 1.0f); }
/// <summary> Check if a property is cached as valid </summary> private bool IsValid(SerializedProperty property, GunComponent component) { FieldInfo field = component.GetType().GetField(property.name); if (!validation_cache_fields.ContainsKey(field)) { return(false); } return(validation_cache_fields[field]); }
public override void PickUp() { var player = GameObject.Find("Player"); if (player == null) { return; } _gunComponent = player.GetComponent <GunComponent>(); }
protected void Fire(GunComponent gunComponent, Transform transform) { //Debug.Log("fire, tag:" + gunComponent.entity.identity.tag); Vector3 bulletPos = transform.position + transform.up * gunComponent.fireOffset; Entity bullet = world.entitySystem.CreateFrom(gunComponent.bulletPrefab, bulletPos); bullet.gameobjectComponent.transform.rotation = transform.rotation; bullet.bulletComponent.buffName = gunComponent.gunData.bulletBuff; bullet.identity.master = gunComponent.entity; }
public virtual void RemoveMod(GunComponent mod) { var location = mods.FindIndex(x => x == mod); if (location != -1) { mods[location] = null; return; } Debug.Log("This mod was not found when removing it from its prev holder."); }
public void Shoot( GunComponent gun, IShootable ammo, EntityCoordinates fromCoordinates, EntityCoordinates toCoordinates, EntityUid?user = null) { Shoot(gun, new List <IShootable>(1) { ammo }, fromCoordinates, toCoordinates, user); }
private void StopShooting(GunComponent gun) { if (gun.ShotCounter == 0) { return; } Sawmill.Debug($"Stopped shooting {ToPrettyString(gun.Owner)}"); gun.ShotCounter = 0; gun.ShootCoordinates = null; Dirty(gun); }
protected override void OnUpdate() { Entity gunEntity = GetSingletonEntity <GunComponent>(); int pos = 1; if (Input.GetKey(KeyCode.S) || Input.GetKey(KeyCode.DownArrow)) { pos--; } if (Input.GetKey(KeyCode.W) || Input.GetKey(KeyCode.UpArrow)) { pos++; } if (Input.GetKey(KeyCode.Space) && Time.ElapsedTime >= _cooldownTimer) { GunComponent gunComponent = EntityManager.GetComponentData <GunComponent>(gunEntity); _cooldownTimer = Time.ElapsedTime + gunComponent.Cooldown; EntityQueryDesc query = new EntityQueryDesc { None = new ComponentType[] { ComponentType.ReadOnly <IsMoving>() }, All = new ComponentType[] { typeof(Translation), typeof(MovableComponent), ComponentType.ReadOnly <BulletComponent>() } }; EntityQuery entityQuery = GetEntityQuery(query); if (!entityQuery.IsEmptyIgnoreFilter) { NativeArray <Entity> entities = entityQuery.ToEntityArray(Allocator.Persistent); Entity entity = entities[0]; float3 direction = Quaternion.AngleAxis(60 - 30 * pos, Vector3.back) * Vector3.up; MovableComponent component = EntityManager.GetComponentData <MovableComponent>(entity); component.Direction = direction; PostUpdateCommands.AddComponent(entity, new IsMoving()); PostUpdateCommands.SetComponent(entity, component); entities.Dispose(); GameManager.Instance.ShotFired(); } } var materialReferencesEntity = GetSingletonEntity <MaterialReferences>(); var materialReferences = EntityManager.GetSharedComponentData <MaterialReferences>(materialReferencesEntity); RenderMesh renderMesh = EntityManager.GetSharedComponentData <RenderMesh>(gunEntity); Material newMaterial = materialReferences.GunPositions[pos]; if (newMaterial != renderMesh.material) { renderMesh.material = newMaterial; PostUpdateCommands.SetSharedComponent(gunEntity, renderMesh); } }
/// <summary> /// Cycles the gun's <see cref="SelectiveFire"/> to the next available one. /// </summary> public void CycleFire(GunComponent component, EntityUid?user = null) { // Noop if (component.SelectedMode == component.AvailableModes) { return; } DebugTools.Assert((component.AvailableModes & component.SelectedMode) == component.SelectedMode); var nextMode = GetNextMode(component); SelectFire(component, nextMode, user); }
public static void SetDelayOnPlayerWeapon() { EntityManager e = World.DefaultGameObjectInjectionWorld.EntityManager; //Set delay on Player Weapon (Quick fix for bullets spawning at wrong spot) Entity weaponEntity = EventsHolder.LevelEvents.CurrentLevel != MapType.Level_Hell ? GameVariables.Player.PlayerWeaponEntities[GameVariables.Player.CurrentWeaponHeld] : GameVariables.Player.PlayerHellWeaponEntities[GameVariables.Player.CurrentWeaponHeld]; GunComponent weapon = e.GetComponentData <GunComponent>(weaponEntity); weapon.SwapTimer = 0.02f; e.SetComponentData(weaponEntity, weapon); }
/// <summary> Try to find a transform inside the gun with any of the specified names, and set the field to it. </summary> private bool RestoreReference(FieldInfo field, GunComponent component, string[] names) { foreach (string name in names) { Transform transform = gun_script.transform.Find(name, true); if (transform != null) { field.SetValue(component, transform); return(true); } } return(false); }
void Pickup(GunComponent comp, int i) { //Debug.Log(comp.gameObject); Destroy(comp.GetComponent <MeshFilter>()); Destroy(comp.GetComponent <MeshRenderer>()); Destroy(comp.GetComponent <Collider>()); Destroy(comp.GetComponent <Light>()); for (int j = 0; j < comp.transform.childCount; j++) { Destroy(comp.transform.GetChild(0).gameObject); } comp.AddToInventory(i); }
//############################################################################################## // Make sure to call base start, then setup some simple state //############################################################################################## protected override void Start() { base.Start(); patrollingAToB = true; patrolIdleTimer = new Timer(patrolIdleTime); shootTimer = new Timer(shootCooldown); gun = GetComponent <GunComponent>(); patrolIdleTimer.Start(); }
public void Shoot( GunComponent gun, EntityUid ammo, EntityCoordinates fromCoordinates, EntityCoordinates toCoordinates, EntityUid?user = null) { var shootable = EnsureComp <AmmoComponent>(ammo); Shoot(gun, new List <IShootable>(1) { shootable }, fromCoordinates, toCoordinates, user); }
void displayAttachMenu(Vector2 pos) { Rect background = new Rect(pos.x, pos.y, 140, (AvailableComponents.Count)*20 + 20); GUI.Box(background, ""); foreach(KeyValuePair<int, GameObject> attachment in AvailableComponents) { Rect buttonRect = new Rect(background.x + 10,background.y + (attachment.Key * 20) + 10, 110, 20); if(GUI.Button (buttonRect,attachment.Value.name)){ Debug.Log("add "+attachment.Value.name+" component here"); GameObject newObj = Instantiate(attachment.Value) as GameObject; GunComponent newObjScript = newObj.GetComponent<GunComponent>(); newObjScript.Attach(1, newObjScript); //temporary, todo: change inputs to something that is right selectedNode = null; selectedComponent = null; selectedPiece = null; } } }
void selectPiece(RaycastHit select) { if(selectedPiece != null){ deselectPiece(); } Debug.Log("selected " +select.transform.name); selectedPiece = select.transform.gameObject; selectedComponent = selectedPiece.GetComponent<GunComponent>(); selectedPiece.renderer.material.color = Color.red; }
void deselectPiece() { selectedPiece.renderer.material.color = Color.white; selectedPiece = null; selectedComponent = null; }