private void Start() { if (Sounds.Length > 0) { AudioSource.PlayClipAtPoint(Sounds[Random.Range(0, Sounds.Length)], transform.position, (float)GameProfiles.Current.GetAudioEffectsVolume()); } if (Prefab) { for (int i = 0; i < Num; i++) { float scaleHalf = Scale / 2; Vector3 pos = new Vector3(Random.Range(-scaleHalf, scaleHalf), Random.Range(-scaleHalf, Scale), Random.Range(-scaleHalf, scaleHalf)) / scaleHalf; GameObject obj = GameObjectHelper.CreateGameObject(Prefab, transform.position + pos, transform.rotation, true); GameObjectHelper.DestroyGameObject(obj, LifeTimeObject, true); float scale = Scale; if (RandomScale) { scale = Random.Range(1, Scale); } if (scale > 0) { obj.transform.localScale = new Vector3(scale, scale, scale); } if (obj.Has <Rigidbody>()) { Vector3 force = new Vector3(Random.Range(-Force.x, Force.x), Random.Range(-Force.y, Force.y), Random.Range(-Force.z, Force.z)); obj.Get <Rigidbody>().AddForce(force); } } } }
public static GameObject CreateGameObject( this GameObject go, Vector3 pos, Quaternion rotate, bool pooled) { return(GameObjectHelper.CreateGameObject(go, pos, rotate, pooled)); }
private void Dead() { if (Effect) { GameObjectHelper.CreateGameObject(Effect, transform.position, transform.rotation, true); } GameObjectHelper.DestroyGameObject(this.gameObject, true); }
void Start() { if (!GameDamageDirector.AllowChain) { //GameObjectHelper.DestroyGameObject(gameObject); //return; } int count = 0; for (int t = 0; t < TargetTag.Length; t++) { if (GameObject.FindGameObjectsWithTag(TargetTag[t]).Length > 0) { GameObject[] objs = GameObject.FindGameObjectsWithTag(TargetTag[t]); float distance = Distance; for (int i = 0; i < objs.Length; i++) { if (objs[i] != null) { Vector3 dir = (objs[i].transform.position - this.transform.position).normalized; float direction = Vector3.Dot(dir, this.transform.forward); float dis = Vector3.Distance(objs[i].transform.position, this.transform.position); if (dis < distance) { if (direction >= Direction) { if (ChainObject) { if (count <= NumberChain) { GameObject chain = GameObjectHelper.CreateGameObject( ChainObject, this.transform.position, this.transform.rotation, true); Quaternion targetlook = Quaternion.LookRotation( objs[i].transform.position - chain.transform.position); chain.transform.rotation = targetlook; count += 1; } } } distance = dis; } } } } } }
public static GamePlayerIndicator AddIndicator( GameObject parentObject, GameObject target, string type, string gameIndicatorType) { // Spawn indicator // target new player string modelPath = ContentPaths.appCacheVersionSharedPrefabLevelUI + "GamePlayerIndicatorHUD"; //LogUtil.Log("AddIndicator:modelPath:" + modelPath); GameObject prefabIndicator = Resources.Load(modelPath) as GameObject; //LogUtil.Log("AddIndicator:prefabIndicator:" + prefabIndicator.name); if (prefabIndicator != null) { GameObject indicator = GameObjectHelper.CreateGameObject( prefabIndicator, Vector3.zero, Quaternion.identity, GameConfigs.usePooledIndicators); indicator.transform.parent = parentObject.transform; indicator.ResetPosition(); if (indicator != null) { //LogUtil.Log("AddIndicator:indicator:" + indicator.name); GamePlayerIndicator indicatorObj = indicator.GetComponent <GamePlayerIndicator>(); if (indicatorObj != null) { //LogUtil.Log("AddIndicator:indicatorObj:" + indicatorObj.name); //LogUtil.Log("AddIndicator:gameIndicatorType:" + gameIndicatorType); //LogUtil.Log("AddIndicator:target.transform.name:" + target.transform.name); indicatorObj.HideIndicator(); indicatorObj.indicatorType = GamePlayerIndicatorPlacementType.SCREEN; indicatorObj.SetTarget(target.transform); indicatorObj.transform.localScale = Vector3.one; indicatorObj.type = gameIndicatorType;//(GamePlayerIndicatorType)Enum.Parse(typeof(GamePlayerIndicatorType), gameIndicatorType); indicatorObj.SetGameIndicatorType(gameIndicatorType); indicatorObj.Run(); } return(indicatorObj); } } return(null); }
public virtual void SetGameIndicatorType(string gameIndicatorType) { //LogUtil.Log("GamePlayerIndicator:gameIndicatorType:" + gameIndicatorType); gameIndicatorTypeCode = gameIndicatorType; if (indicatorObject == null) { return; } // Check if there is already an indicator loaded // If not load if (!indicatorObject.Has <GamePlayerIndicatorItem>()) { string modelPath = ContentPaths.appCacheVersionSharedPrefabLevelUI + "indicator-" + gameIndicatorType; //LogUtil.Log("AddIndicator:modelPath:" + modelPath); GameObject prefabIndicatorType = Resources.Load(modelPath) as GameObject; //LogUtil.Log("AddIndicator:prefabIndicatorType:" + prefabIndicatorType.name); if (prefabIndicatorType != null) { GameObject indicator = GameObjectHelper.CreateGameObject( prefabIndicatorType, Vector3.zero, Quaternion.identity, GameConfigs.usePooledIndicators); indicator.transform.parent = indicatorObject.transform; indicator.ResetPosition(); indicator.transform.localScale = indicator.transform.localScale * .1f; if (indicator != null) { if (!indicator.Has <GamePlayerIndicatorItem>()) { gamePlayerIndicatorItem = indicator.AddComponent <GamePlayerIndicatorItem>(); } else { gamePlayerIndicatorItem = indicator.Get <GamePlayerIndicatorItem>(); } gamePlayerIndicatorItem.gameIndicatorTypeCode = gameIndicatorType; } } } }
void Start() { if (!GameDamageDirector.AllowRayShoot) { GameObjectHelper.DestroyGameObject(gameObject); return; } trail = this.gameObject.GetComponent <LineRenderer>(); RaycastHit hit; GameObject explosion = null; if (Physics.Raycast(this.transform.position, this.transform.forward, out hit, Range)) { AimPoint = hit.point; if (Explosion != null) { explosion = GameObjectHelper.CreateGameObject( Explosion, AimPoint, this.transform.rotation, true); } } else { AimPoint = this.transform.forward * Range; explosion = GameObjectHelper.CreateGameObject( Explosion, AimPoint, this.transform.rotation, true); } if (explosion) { GameDamageBase dmg = explosion.GetComponent <GameDamageBase>(); if (dmg) { dmg.TargetTag = TargetTag; } } if (trail) { trail.SetPosition(0, this.transform.position); trail.SetPosition(1, AimPoint); } GameObjectHelper.DestroyGameObject(this.gameObject, LifeTime); }
/// <summary> /// 创建对象 有缓存:从池中返回,无缓存:加载后再返回 /// </summary> /// <returns></returns> /**************************************** 高层 ************************************************/ public GameObject CreateObject(string pKey, GameObject pGameObject, Transform pParent, Vector3 pLocalPostion, Quaternion pLocalRotation, string pGameObjectName = "") { GameObject tempGO = FindUsable(pKey); //有缓存(没有出现在画面中的对象):从池中返回, if (tempGO != null) { tempGO = CreateLocalExitObject(pKey, pParent, pLocalPostion, pLocalRotation, pGameObjectName); } else //无缓存:创建后再返回 { tempGO = GameObjectHelper.CreateGameObject(pGameObject, pParent, pLocalPostion, pLocalRotation, pGameObjectName); Add(pKey, tempGO); } return(tempGO); }
public void Active() { if (!GameDamageDirector.AllowExplosion) { GameObjectHelper.DestroyGameObject(gameObject); return; } if (Effect) { GameObject obj = GameObjectHelper.CreateGameObject(Effect, transform.position, transform.rotation, true); GameObjectHelper.DestroyGameObject(obj, 3, true); } if (Explosive) { ExplosionDamage(); } GameObjectHelper.DestroyGameObject(gameObject, 3, true); }
public void Shoot() { if (InfinityAmmo) { Ammo = 1; } if (Ammo > 0) { if (Time.time > nextFireTime + FireRate) { nextFireTime = Time.time; torqueTemp = TorqueSpeedAxis; Ammo -= 1; Vector3 missileposition = this.transform.position; Quaternion missilerotate = this.transform.rotation; if (MissileOuter.Length > 0) { missilerotate = MissileOuter[currentOuter].transform.rotation; missileposition = MissileOuter[currentOuter].transform.position; } if (MissileOuter.Length > 0) { currentOuter += 1; if (currentOuter >= MissileOuter.Length) { currentOuter = 0; } } if (Muzzle) { GameObject muzzle = GameObjectHelper.CreateGameObject( Muzzle, missileposition, missilerotate, true); muzzle.transform.parent = this.transform; GameObjectHelper.DestroyGameObject(muzzle, MuzzleLifeTime); if (MissileOuter.Length > 0) { muzzle.transform.parent = MissileOuter[currentOuter].transform; } } for (int i = 0; i < NumBullet; i++) { if (Missile) { Vector3 spread = new Vector3( Random.Range(-Spread, Spread), Random.Range(-Spread, Spread), Random.Range(-Spread, Spread)) / 100; Vector3 direction = this.transform.forward + spread; GameObject bullet = GameObjectHelper.CreateGameObject( Missile, missileposition, missilerotate, true); NameEffect(bullet); GameDamageBase damageBase = bullet.GetComponent <GameDamageBase>(); if (damageBase) { damageBase.gamePlayerController = gamePlayerController; damageBase.TargetTag = TargetTag; } GameWeaponBase weaponBase = bullet.GetComponent <GameWeaponBase>(); if (weaponBase) { weaponBase.gamePlayerController = gamePlayerController; weaponBase.Target = target; weaponBase.TargetTag = TargetTag; } bullet.transform.forward = direction; if (RigidbodyProjectile) { if (bullet.Has <Rigidbody>()) { Rigidbody rigid = bullet.Get <Rigidbody>(); if (rigid != null) { if (gamePlayerController != null && gamePlayerController.gameObject.GetRigidbody()) { rigid.velocity = gamePlayerController.gameObject.GetRigidbody().velocity; } rigid.AddForce(direction * ForceShoot); } } } } } if (!FPSDisplay.isUnder25FPS && Shell) { Transform shelloutpos = this.transform; if (ShellOuter.Length > 0) { shelloutpos = ShellOuter[currentOuter]; } GameObject shell = GameObjectHelper.CreateGameObject( Shell, shelloutpos.position, Random.rotation, true); GameObjectHelper.DestroyGameObject(shell.gameObject, ShellLifeTime); if (shell.Has <Rigidbody>()) { shell.Get <Rigidbody>().AddForce(shelloutpos.forward * ShellOutForce); } } if (SoundGun.Length > 0) { if (audio) { audio.volume = (float)GameProfiles.Current.GetAudioEffectsVolume(); audio.PlayOneShot(SoundGun[Random.Range(0, SoundGun.Length)]); } } nextFireTime += FireRate; } } }
public virtual void AttackPrimary() { if (gameWeaponLauncher != null) { gameWeaponLauncher.Shoot(); } else { if (!useGameObjectProjectile) { } else { if (currentItems != null) { LogUtil.Log("GamePlayerWeapon::AttackPrimary:currentItems:" + currentItems); if (currentItems.Count > 0) { // TODO work in other shoot buttons GameObject currentItem = currentItems[0]; LogUtil.Log("GamePlayerWeapon::AttackPrimary:currentItem:" + currentItem); Vector3 projectileStartPosition = transform.position; projectileStartPosition.x = projectileStartPosition.x + 2f; GamePlayerProjectile projectile = GameObjectHelper.CreateGameObject( currentItem.gameObject, projectileStartPosition, Quaternion.identity, GameConfigs.usePooledProjectiles ).GetComponent <GamePlayerProjectile>(); ; GameObject gameObject = currentItem; if (projectile != null) { projectile.transform.parent = null; //LogUtil.Log("GamePlayerWeapon::AttackPrimary:gameObject.transform.localRotation.eulerAngles:" + gameObject.transform.localRotation.eulerAngles); //LogUtil.Log("GamePlayerWeapon::AttackPrimary:gameObject.transform.localRotation:" + gameObject.transform.localRotation); //LogUtil.Log("GamePlayerWeapon::AttackPrimary:gameObject.transform.rotation.eulerAngles:" + gameObject.transform.rotation.eulerAngles); //LogUtil.Log("GamePlayerWeapon::AttackPrimary:gameObject.transform.rotation:" + gameObject.transform.rotation); /* * LogUtil.Log("GamePlayerWeapon::AttackPrimary:gameObject.transform:" + gameObject.transform); * LogUtil.Log("GamePlayerWeapon::AttackPrimary:gameObject.transform.name:" + gameObject.name); * LogUtil.Log("GamePlayerWeapon::AttackPrimary:gameObject.transform.position:" + gameObject.transform.position); * LogUtil.Log("GamePlayerWeapon::AttackPrimary:gameObject.transform.rotation:" + gameObject.transform.rotation); * LogUtil.Log("GamePlayerWeapon::AttackPrimary:gameObject.transform.localRotation:" + gameObject.transform.localRotation); * LogUtil.Log("GamePlayerWeapon::AttackPrimary:gameObject.transform.rotation.y:" + gameObject.transform.rotation.y); * LogUtil.Log("GamePlayerWeapon::AttackPrimary:gameObject.transform.localRotation.y:" + gameObject.transform.localRotation.y); * LogUtil.Log("GamePlayerWeapon::AttackPrimary:gameObject.transform.eulerAngles:" + gameObject.transform.eulerAngles); * LogUtil.Log("GamePlayerWeapon::AttackPrimary:gameObject.transform.localEulerAngles:" + gameObject.transform.localEulerAngles); * * * LogUtil.Log("GamePlayerWeapon::AttackPrimary:gameObject.parent.transform:" + gameObject.transform.parent.gameObject.transform); * LogUtil.Log("GamePlayerWeapon::AttackPrimary:gameObject.parent.transform.name:" + gameObject.transform.parent.gameObject.name); * LogUtil.Log("GamePlayerWeapon::AttackPrimary:gameObject.parent.transform.position:" + gameObject.transform.parent.gameObject.transform.position); * LogUtil.Log("GamePlayerWeapon::AttackPrimary:gameObject.parent.transform.rotation:" + gameObject.transform.parent.gameObject.transform.rotation); * LogUtil.Log("GamePlayerWeapon::AttackPrimary:gameObject.parent.transform.localRotation:" + gameObject.transform.parent.gameObject.transform.localRotation); * LogUtil.Log("GamePlayerWeapon::AttackPrimary:gameObject.parent.transform.eulerAngles:" + gameObject.transform.parent.gameObject.transform.eulerAngles); * LogUtil.Log("GamePlayerWeapon::AttackPrimary:gameObject.parent.transform.localEulerAngles:" + gameObject.transform.parent.gameObject.transform.localEulerAngles); */ projectile.gameObject.transform.position = gameObject.transform.position; projectile.speed = 1f;//currentAcceleration * .1f; if (InputSystem.Instance != null) { //LogUtil.Log("GamePlayerWeapon::AttackPrimary:gInputSystem.Instance.lastTargetDirection:" + InputSystem.Instance.lastTargetDirection); //projectile.direction = InputSystem.Instance.lastTargetDirection; projectile.transform.position = transform.parent.position; projectile.direction = transform.parent.position; } projectile.projectileObject = currentItem; projectile.Launch(); } } } } } }
public virtual void PlayProjectiles() { if (gameWeaponData.data.HasProjectiles()) { foreach (GameDataItemProjectile projectile in gameWeaponData.data.projectiles) { GameObject projectilePrefab = AppContentAssets.LoadAssetPrefab("weapon", projectile.code); GameObject projectileExplosionPrefab = AppContentAssets.LoadAssetPrefab("weapon", "projectile-explosion-star-1"); if (projectilePrefab != null) { GameObject projectileObject = GameObjectHelper.CreateGameObject( projectilePrefab, containerProjectiles.transform.position, containerProjectiles.transform.rotation, true); // TODO add to configs // add components DetachToWorld detachToWorld = projectileObject.Get <DetachToWorld>(); if (detachToWorld == null) { detachToWorld = projectileObject.AddComponent <DetachToWorld>(); } DestroyObjectTimed destroyObjectTimed = projectileObject.Get <DestroyObjectTimed>(); if (destroyObjectTimed == null) { destroyObjectTimed = projectileObject.AddComponent <DestroyObjectTimed>(); } destroyObjectTimed.delay = 5f; SpawnOnContact spawnOnContact = projectileObject.Get <SpawnOnContact>(); if (spawnOnContact == null) { spawnOnContact = projectileObject.AddComponent <SpawnOnContact>(); } spawnOnContact.objectToCreate = projectileExplosionPrefab; GameObjectMove gameObjectMove = projectileObject.Get <GameObjectMove>(); if (gameObjectMove == null) { gameObjectMove = projectileObject.AddComponent <GameObjectMove>(); } gameObjectMove.translationSpeedX = 0f; gameObjectMove.translationSpeedY = 0f; gameObjectMove.translationSpeedZ = 20f; gameObjectMove.local = true; BoxCollider projectileCollider = projectileObject.Get <BoxCollider>(); if (projectileCollider == null) { projectileCollider = projectileObject.AddComponent <BoxCollider>(); } Rigidbody projectileBody = projectileObject.Get <Rigidbody>(); if (projectileBody == null) { projectileBody = projectileObject.AddComponent <Rigidbody>(); } projectileBody.mass = .001f; projectileBody.angularDrag = .0f; projectileBody.useGravity = false; projectileBody.collisionDetectionMode = CollisionDetectionMode.ContinuousDynamic; } } } }