public void Awake() { item = this.GetComponent <Item>(); module = item.data.GetModule <Shared.FirearmModule>(); try { if (!string.IsNullOrEmpty(module.muzzlePositionRef)) { muzzlePoint = item.GetCustomReference(module.muzzlePositionRef); } else { muzzlePoint = item.transform; } } catch { Debug.LogError(string.Format("[SimpleFirearmsFramework] Exception: '\"muzzlePositionRef\": \"{0}\"' was set in JSON, but \"{0}\" is not present on the Unity Prefab.", module.muzzlePositionRef)); muzzlePoint = item.transform; } // Fetch Animator, ParticleSystem, and AudioSources from Custom References (see "How-To Guide" for more info on custom references) if (!string.IsNullOrEmpty(module.fireSoundRef)) { fireSound = item.GetCustomReference(module.fireSoundRef).GetComponent <AudioSource>(); } else { Debug.LogError(string.Format("[SimpleFirearmsFramework] Exception: '\"fireSoundRef\": \"{0}\"' was set in JSON, but \"{0}\" is not present on the Unity Prefab.", module.fireSoundRef)); } if (!string.IsNullOrEmpty(module.emptySoundRef)) { emptySound = item.GetCustomReference(module.emptySoundRef).GetComponent <AudioSource>(); } else { Debug.LogError(string.Format("[SimpleFirearmsFramework] Exception: '\"emptySoundRef\": \"{0}\"' was set in JSON, but \"{0}\" is not present on the Unity Prefab.", module.emptySoundRef)); } if (!string.IsNullOrEmpty(module.reloadSoundRef)) { reloadSound = item.GetCustomReference(module.reloadSoundRef).GetComponent <AudioSource>(); } else { Debug.LogError(string.Format("[SimpleFirearmsFramework] Exception: '\"reloadSoundRef\": \"{0}\"' was set in JSON, but \"{0}\" is not present on the Unity Prefab.", module.reloadSoundRef)); } if (!string.IsNullOrEmpty(module.swtichSoundRef)) { switchSound = item.GetCustomReference(module.swtichSoundRef).GetComponent <AudioSource>(); } else { Debug.LogError(string.Format("[SimpleFirearmsFramework] Exception: '\"swtichSoundRef\": \"{0}\"' was set in JSON, but \"{0}\" is not present on the Unity Prefab.", module.swtichSoundRef)); } if (!string.IsNullOrEmpty(module.npcRaycastPositionRef)) { npcRayCastPoint = item.GetCustomReference(module.npcRaycastPositionRef); } else { Debug.LogError(string.Format("[SimpleFirearmsFramework] Exception: '\"npcRaycastPositionRef\": \"{0}\"' was set in JSON, but \"{0}\" is not present on the Unity Prefab.", module.npcRaycastPositionRef)); } if (!string.IsNullOrEmpty(module.muzzleFlashRef)) { MuzzleFlash = item.GetCustomReference(module.muzzleFlashRef).GetComponent <ParticleSystem>(); } else { Debug.LogError(string.Format("[SimpleFirearmsFramework] Exception: '\"muzzleFlashRef\": \"{0}\"' was set in JSON, but \"{0}\" is not present on the Unity Prefab.", module.muzzleFlashRef)); } if (!string.IsNullOrEmpty(module.animatorRef)) { Animations = item.GetCustomReference(module.animatorRef).GetComponent <Animator>(); } else { Debug.LogError(string.Format("[SimpleFirearmsFramework] Exception: '\"animatorRef\": \"{0}\"' was set in JSON, but \"{0}\" is not present on the Unity Prefab.", module.animatorRef)); } if (!string.IsNullOrEmpty(module.earlyFireSoundRef)) { earlyFireSound = item.GetCustomReference(module.earlyFireSoundRef).GetComponent <AudioSource>(); } else { Debug.LogError(string.Format("[SimpleFirearmsFramework] Exception: '\"secondaryFireSound\": \"{0}\"' was set in JSON, but \"{0}\" is not present on the Unity Prefab.", module.earlyFireSoundRef)); } if (!string.IsNullOrEmpty(module.earlyMuzzleFlashRef)) { earlyMuzzleFlash = item.GetCustomReference(module.earlyMuzzleFlashRef).GetComponent <ParticleSystem>(); } else { Debug.LogError(string.Format("[SimpleFirearmsFramework] Exception: '\"secondaryMuzzleFlashRef\": \"{0}\"' was set in JSON, but \"{0}\" is not present on the Unity Prefab.", module.earlyMuzzleFlashRef)); } if (npcRayCastPoint == null) { npcRayCastPoint = muzzlePoint; } // Setup ammo tracking if (module.ammoCapacity > 0) { remaingingAmmo = (int)module.ammoCapacity; } else { infAmmo = true; } // Override SFX volume from JSON if ((module.soundVolume > 0.0f) && (module.soundVolume <= 1.0f)) { if (fireSound != null) { fireSound.volume = module.soundVolume; } } if (module.loopedFireSound) { fireSound.loop = true; } // Get firemode based on numeric index of the enum fireModeSelection = (FireMode)Enum.Parse(typeof(FireMode), module.fireMode); if (module.allowedFireModes != null) { allowedFireModes = new List <int>(module.allowedFireModes); } // Handle interaction events item.OnHeldActionEvent += OnHeldAction; if (!string.IsNullOrEmpty(module.mainGripID)) { gunGrip = item.GetCustomReference(module.mainGripID).GetComponent <Handle>(); } if (gunGrip == null) { // If not defined, get the first handle named "Handle", and if still not found try to get the first object with a Handle component gunGrip = item.transform.Find("Handle").GetComponent <Handle>(); if (gunGrip == null) { gunGrip = item.GetComponentInChildren <Handle>(); } } if (gunGrip != null) { gunGrip.Grabbed += OnMainGripGrabbed; gunGrip.UnGrabbed += OnMainGripUnGrabbed; } }
void Awake() { soundCounter = 0; maxSoundCounter = 0; item = this.GetComponent <Item>(); module = item.data.GetModule <Shared.FirearmModule>(); DisableCulling(item); /// Set all Object References /// if (!String.IsNullOrEmpty(module.rayCastPointRef)) { rayCastPoint = item.GetCustomReference(module.rayCastPointRef); } if (!String.IsNullOrEmpty(module.muzzlePositionRef)) { muzzlePoint = item.GetCustomReference(module.muzzlePositionRef); } if (!String.IsNullOrEmpty(module.shellEjectionRef)) { shellEjectionPoint = item.GetCustomReference(module.shellEjectionRef); } if (!String.IsNullOrEmpty(module.animationRef)) { animations = item.GetCustomReference(module.animationRef).GetComponent <Animator>(); } if (!String.IsNullOrEmpty(module.fireSoundRef)) { fireSound = item.GetCustomReference(module.fireSoundRef).GetComponent <AudioSource>(); } if (!String.IsNullOrEmpty(module.fireSound1Ref)) { fireSound1 = item.GetCustomReference(module.fireSound1Ref).GetComponent <AudioSource>(); maxSoundCounter++; soundCounter = 1; } if (!String.IsNullOrEmpty(module.fireSound2Ref)) { fireSound2 = item.GetCustomReference(module.fireSound2Ref).GetComponent <AudioSource>(); maxSoundCounter++; } if (!String.IsNullOrEmpty(module.fireSound3Ref)) { fireSound3 = item.GetCustomReference(module.fireSound3Ref).GetComponent <AudioSource>(); maxSoundCounter++; } if (!String.IsNullOrEmpty(module.emptySoundRef)) { emptySound = item.GetCustomReference(module.emptySoundRef).GetComponent <AudioSource>(); } if (!String.IsNullOrEmpty(module.pullSoundRef)) { pullbackSound = item.GetCustomReference(module.pullSoundRef).GetComponent <AudioSource>(); } if (!String.IsNullOrEmpty(module.rackSoundRef)) { rackforwardSound = item.GetCustomReference(module.rackSoundRef).GetComponent <AudioSource>(); } if (!String.IsNullOrEmpty(module.flashRef)) { muzzleFlash = item.GetCustomReference(module.flashRef).GetComponent <ParticleSystem>(); } if (!String.IsNullOrEmpty(module.smokeRef)) { muzzleSmoke = item.GetCustomReference(module.smokeRef).GetComponent <ParticleSystem>(); } if (!String.IsNullOrEmpty(module.shellParticleRef)) { shellParticle = item.GetCustomReference(module.shellParticleRef).GetComponent <ParticleSystem>(); } if (!String.IsNullOrEmpty(module.mainHandleRef)) { mainHandle = item.GetCustomReference(module.mainHandleRef).GetComponent <Handle>(); } else { Debug.LogError("[Fisher-ModularFirearms][ERROR] No Reference to Main Handle (\"mainHandleRef\") in JSON! Weapon will not work as intended !!!"); } if (!String.IsNullOrEmpty(module.slideHandleRef)) { slideObject = item.GetCustomReference(module.slideHandleRef).gameObject; } else { Debug.LogError("[Fisher-ModularFirearms][ERROR] No Reference to Slide Handle (\"slideHandleRef\") in JSON! Weapon will not work as intended !!!"); } if (!String.IsNullOrEmpty(module.slideCenterRef)) { slideCenterPosition = item.GetCustomReference(module.slideCenterRef).gameObject; } else { Debug.LogError("[Fisher-ModularFirearms][ERROR] No Reference to Slide Center Position(\"slideCenterRef\") in JSON! Weapon will not work as intended..."); } if (slideObject != null) { slideHandle = slideObject.GetComponent <Handle>(); } lastSpellMenuPress = 0.0f; RACK_THRESHOLD = -0.1f * module.slideTravelDistance; PULL_THRESHOLD = -0.5f * module.slideTravelDistance; fireModeSelection = (FireMode)Enum.Parse(typeof(FireMode), module.fireMode); validMagazineIDs = new List <string>(module.acceptedMagazineIDs); /// Item Events /// item.OnHeldActionEvent += OnHeldAction; item.OnGrabEvent += OnAnyHandleGrabbed; item.OnUngrabEvent += OnAnyHandleUngrabbed; magazineHolder = item.GetComponentInChildren <Holder>(); magazineHolder.Snapped += new Holder.HolderDelegate(this.OnMagazineInserted); magazineHolder.UnSnapped += new Holder.HolderDelegate(this.OnMagazineRemoved); }
protected void Awake() { item = this.GetComponent <Item>(); module = item.data.GetModule <Shared.FirearmModule>(); /// Set all Object References /// if (!String.IsNullOrEmpty(module.muzzlePositionRef)) { muzzlePoint = item.GetCustomReference(module.muzzlePositionRef); } if (!String.IsNullOrEmpty(module.rayCastPointRef)) { rayCastPoint = item.GetCustomReference(module.muzzlePositionRef); } if (!String.IsNullOrEmpty(module.shellEjectionRef)) { shellEjectionPoint = item.GetCustomReference(module.shellEjectionRef); } if (!String.IsNullOrEmpty(module.animationRef)) { Animations = item.GetCustomReference(module.animationRef).GetComponent <Animator>(); } if (!String.IsNullOrEmpty(module.fireSoundRef)) { fireSound = item.GetCustomReference(module.fireSoundRef).GetComponent <AudioSource>(); } if (!String.IsNullOrEmpty(module.emptySoundRef)) { emptySound = item.GetCustomReference(module.emptySoundRef).GetComponent <AudioSource>(); } if (!String.IsNullOrEmpty(module.pullSoundRef)) { pullbackSound = item.GetCustomReference(module.pullSoundRef).GetComponent <AudioSource>(); } if (!String.IsNullOrEmpty(module.rackSoundRef)) { rackforwardSound = item.GetCustomReference(module.rackSoundRef).GetComponent <AudioSource>(); } if (!String.IsNullOrEmpty(module.shellInsertSoundRef)) { shellInsertSound = item.GetCustomReference(module.shellInsertSoundRef).GetComponent <AudioSource>(); } if (!String.IsNullOrEmpty(module.flashRef)) { muzzleFlash = item.GetCustomReference(module.flashRef).GetComponent <ParticleSystem>(); } if (!String.IsNullOrEmpty(module.smokeRef)) { muzzleSmoke = item.GetCustomReference(module.smokeRef).GetComponent <ParticleSystem>(); } if (!String.IsNullOrEmpty(module.mainHandleRef)) { gunGrip = item.GetCustomReference(module.mainHandleRef).GetComponent <Handle>(); } else { Debug.LogError("[ModularFirearmsFramework][ERROR] No Reference to Main Handle (\"mainHandleRef\") in JSON! Weapon will not work as intended !!!"); } if (!String.IsNullOrEmpty(module.slideHandleRef)) { slideObject = item.GetCustomReference(module.slideHandleRef).gameObject; } else { Debug.LogError("[ModularFirearmsFramework][ERROR] No Reference to Slide Handle (\"slideHandleRef\") in JSON! Weapon will not work as intended !!!"); } if (!String.IsNullOrEmpty(module.slideCenterRef)) { slideCenterPosition = item.GetCustomReference(module.slideCenterRef).gameObject; } else { Debug.LogError("[ModularFirearmsFramework][ERROR] No Reference to Slide Center Position(\"slideCenterRef\") in JSON! Weapon will not work as intended..."); } if (slideObject != null) { slideHandle = slideObject.GetComponent <Handle>(); } if (!String.IsNullOrEmpty(module.flashlightRef)) { attachedLight = item.GetCustomReference(module.flashlightRef).GetComponent <Light>(); } RACK_THRESHOLD = -0.1f * module.slideTravelDistance; //module.slideRackThreshold; PULL_THRESHOLD = -0.5f * module.slideTravelDistance; currentReceiverAmmo = module.maxReceiverAmmo; /// Item Events /// item.OnHeldActionEvent += OnHeldAction; item.OnGrabEvent += OnAnyHandleGrabbed; item.OnUngrabEvent += OnAnyHandleUngrabbed; //item.OnTouchActionEvent += TouchActionEvent; //item.OnSnapEvent += OnFirearmSnapped; //item.OnUnSnapEvent += OnFirearmUnSnapped; //shellReceiver = item.GetComponentInChildren<Holder>(); shellReceiver = item.GetCustomReference(module.shellReceiverDef).GetComponentInChildren <Holder>(); shellReceiver.Snapped += new Holder.HolderDelegate(this.OnShellInserted); shellReceiver.UnSnapped += new Holder.HolderDelegate(this.OnShellRemoved); }