コード例 #1
0
        public void SpawnSelf(CombatGameState Combat)
        {
            this.Combat = Combat;
            GameObject gameObject = Combat.DataManager.PooledInstantiate(this.prefabName, BattleTechResourceType.Prefab, new Vector3?(), new Quaternion?(), (Transform)null);

            if ((UnityEngine.Object)gameObject == (UnityEngine.Object)null)
            {
                Log.LogWrite("Can't find " + prefabName + " in in-game prefabs\n");
                if (CACMain.Core.AdditinalFXObjects.ContainsKey(prefabName))
                {
                    Log.LogWrite("Found in additional prefabs\n");
                    gameObject = GameObject.Instantiate(CACMain.Core.AdditinalFXObjects[prefabName]);
                }
                else
                {
                    Log.LogWrite(" can't spawn prefab " + this.prefabName + " it is absent in pool,in-game assets and external assets\n", true);
                    return;
                }
            }
            gameObject.transform.SetParent(this.parentObject.transform);
            gameObject.transform.localPosition = this.localPos;
            gameObject.transform.localScale.Set(scale.x, scale.y, scale.z);
            if (!this.keepPrefabRotation)
            {
                gameObject.transform.rotation = this.worldRotation;
            }
            if (this.playFX)
            {
                ParticleSystem component = gameObject.GetComponent <ParticleSystem>();
                if (component != null)
                {
                    component.transform.localScale.Set(scale.x, scale.y, scale.z);
                    gameObject.SetActive(true);
                    component.Stop(true);
                    component.Clear(true);
                    component.transform.transform.SetParent(this.parentObject.transform);
                    component.transform.localPosition = this.localPos;
                    if (!this.keepPrefabRotation)
                    {
                        component.transform.rotation = this.worldRotation;
                    }
                    BTCustomRenderer.SetVFXMultiplier(component);
                    component.Play(true);
                }
            }
            this.spawnedObject = gameObject;
        }
コード例 #2
0
        public void SpawnSelf(CombatGameState Combat)
        {
            this.Combat = Combat;
            GameObject gameObject = Combat.DataManager.PooledInstantiate(this.prefabName, BattleTechResourceType.Prefab, new Vector3?(), new Quaternion?(), (Transform)null);

            if ((UnityEngine.Object)gameObject == (UnityEngine.Object)null)
            {
                Log.LogWrite("Can't find " + prefabName + " in in-game prefabs\n");
                if (CACMain.Core.AdditinalFXObjects.ContainsKey(prefabName))
                {
                    Log.LogWrite("Found in additional prefabs\n");
                    gameObject = GameObject.Instantiate(CACMain.Core.AdditinalFXObjects[prefabName]);
                }
                else
                {
                    Log.LogWrite(" can't spawn prefab " + this.prefabName + " it is absent in pool,in-game assets and external assets\n", true);
                    return;
                }
            }
            Log.LogWrite("SpawnSelf: " + this.prefabName + "\n");
            Component[] components = gameObject.GetComponentsInChildren <Component>();
            foreach (Component component in components)
            {
                if (component == null)
                {
                    continue;
                }
                ;
                Log.LogWrite(" " + component.name + ":" + component.GetType().ToString() + "\n");
                ParticleSystem ps = component as ParticleSystem;
                if (ps != null)
                {
                    var main = ps.main;
                    main.scalingMode = ParticleSystemScalingMode.Hierarchy;
                    Log.LogWrite("  " + ps.main.scalingMode.ToString() + "\n");
                }
            }
            //gameObject.transform.SetParent(this.parentObject.transform);
            gameObject.transform.position = parentObject.transform.position;
            ObjectAncor ancor = gameObject.AddComponent <ObjectAncor>();

            ancor.ancor = parentObject.transform;
            gameObject.transform.localScale = new Vector3(scale.x, scale.y, scale.z);
            if (!this.keepPrefabRotation)
            {
                gameObject.transform.rotation = this.worldRotation;
            }
            if (this.playFX)
            {
                ParticleSystem component = gameObject.GetComponent <ParticleSystem>();
                if (component != null)
                {
                    //component.transform.localScale.Set(scale.x, scale.y, scale.z);
                    gameObject.SetActive(true);
                    component.Stop(true);
                    component.Clear(true);
                    //component.transform.transform.SetParent(this.parentObject.transform);
                    //component.transform.localPosition = this.localPos;
                    if (!this.keepPrefabRotation)
                    {
                        component.transform.rotation = this.worldRotation;
                    }
                    BTCustomRenderer.SetVFXMultiplier(component);
                    component.Play(true);
                }
            }
            this.spawnedObject = gameObject;
        }
コード例 #3
0
        public static bool Prefix(WeaponEffect __instance)
        {
            CustomAmmoCategoriesLog.Log.LogWrite("WeaponEffect.PlayProjectile");
            try {
                //__instance.t = 0.0f;
                typeof(WeaponEffect).GetField("t", BindingFlags.NonPublic | BindingFlags.Instance).SetValue(__instance, 0.0f);
                __instance.currentState = WeaponEffect.WeaponEffectState.Firing;
                GameObject projectileMeshObject = (GameObject)typeof(WeaponEffect).GetField("projectileMeshObject", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(__instance);
                if ((UnityEngine.Object)projectileMeshObject != (UnityEngine.Object)null)
                {
                    projectileMeshObject.SetActive(true);
                }
                GameObject projectileLightObject = (GameObject)typeof(WeaponEffect).GetField("projectileLightObject", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(__instance);
                if ((UnityEngine.Object)projectileLightObject != (UnityEngine.Object)null)
                {
                    projectileLightObject.SetActive(true);
                }
                ParticleSystem projectileParticles = (ParticleSystem)typeof(WeaponEffect).GetField("projectileParticles", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(__instance);
                if ((UnityEngine.Object)projectileParticles != (UnityEngine.Object)null)
                {
                    projectileParticles.Stop(true);
                    projectileParticles.Clear(true);
                }
                Transform projectileTransform = (Transform)typeof(WeaponEffect).GetField("projectileTransform", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(__instance);
                Transform startingTransform   = (Transform)typeof(WeaponEffect).GetField("startingTransform", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(__instance);
                projectileTransform.position = startingTransform.position;
                Vector3 endPos = (Vector3)typeof(WeaponEffect).GetField("endPos", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(__instance);
                projectileTransform.LookAt(endPos);
                typeof(WeaponEffect).GetField("startPos", BindingFlags.NonPublic | BindingFlags.Instance).SetValue(__instance, startingTransform.position);
                //__instance.startPos = __instance.startingTransform.position;
                if ((UnityEngine.Object)projectileParticles != (UnityEngine.Object)null)
                {
                    BTCustomRenderer.SetVFXMultiplier(projectileParticles);
                    projectileParticles.Play(true);
                    BTLightAnimator componentInChildren = projectileParticles.GetComponentInChildren <BTLightAnimator>(true);
                    if ((UnityEngine.Object)componentInChildren != (UnityEngine.Object)null)
                    {
                        componentInChildren.StopAnimation();
                        componentInChildren.PlayAnimation();
                    }
                }
                if ((UnityEngine.Object)__instance.weapon.parent.GameRep != (UnityEngine.Object)null)
                {
                    int num;
                    switch ((ChassisLocations)__instance.weapon.Location)
                    {
                    case ChassisLocations.LeftArm:
                        num = 1;
                        break;

                    case ChassisLocations.RightArm:
                        num = 2;
                        break;

                    default:
                        num = 0;
                        break;
                    }
                    __instance.weapon.parent.GameRep.PlayFireAnim((AttackSourceLimb)num, CustomAmmoCategories.getWeaponAttackRecoil(__instance.weapon));
                }
                int hitIndex = (int)typeof(WeaponEffect).GetField("hitIndex", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(__instance);
                if (!__instance.AllowMissSkipping || __instance.hitInfo.hitLocations[hitIndex] != 0 && __instance.hitInfo.hitLocations[hitIndex] != 65536)
                {
                    return(false);
                }
                __instance.PublishWeaponCompleteMessage();
            } catch (Exception e) {
                CustomAmmoCategoriesLog.Log.LogWrite("Exception " + e.ToString() + "\nFallback to default\n");
                return(true);
            }
            return(false);
        }
コード例 #4
0
        public static ParticleSystem PlayVFXAt(GameRepresentation gameRep, Transform parentTransform, Vector3 offset, string vfxName, string effectName,
                                               bool attached, Vector3 lookAtPos, bool oneShot, float duration)
        {
            if (string.IsNullOrEmpty(vfxName))
            {
                return(null);
            }

            GameObject gameObject = gameRep.parentCombatant.Combat.DataManager.PooledInstantiate(vfxName, BattleTechResourceType.Prefab, null, null, null);

            if (gameObject == null)
            {
                GameRepresentation.initLogger.LogError("Error instantiating VFX " + vfxName, gameRep);
                return(null);
            }
            ParticleSystem component = gameObject.GetComponent <ParticleSystem>();

            component.Stop(true);
            component.Clear(true);
            Transform transform = gameObject.transform;

            transform.SetParent(null);

            BTWindZone componentInChildren = gameObject.GetComponentInChildren <BTWindZone>(true);

            if (componentInChildren != null && componentInChildren.enabled)
            {
                componentInChildren.ResetZero();
            }

            BTLightAnimator componentInChildren2 = gameObject.GetComponentInChildren <BTLightAnimator>(true);

            if (attached)
            {
                transform.SetParent(parentTransform, false);
                transform.localPosition = offset;
            }
            else
            {
                transform.localPosition = Vector3.zero;
                if (parentTransform != null)
                {
                    transform.position = parentTransform.position;
                }
                transform.position += offset;
            }

            if (lookAtPos != Vector3.zero)
            {
                transform.LookAt(lookAtPos);
            }
            else
            {
                transform.localRotation = Quaternion.identity;
            }
            transform.localScale = Vector3.one;

            if (oneShot)
            {
                AutoPoolObject autoPoolObject = gameObject.GetComponent <AutoPoolObject>();
                if (autoPoolObject == null)
                {
                    autoPoolObject = gameObject.AddComponent <AutoPoolObject>();
                }
                if (duration > 0f)
                {
                    autoPoolObject.Init(gameRep.parentCombatant.Combat.DataManager, vfxName, duration);
                }
                else
                {
                    autoPoolObject.Init(gameRep.parentCombatant.Combat.DataManager, vfxName, component);
                }
            }
            else
            {
                List <ParticleSystem> list = null;
                if (gameRep.persistentVFXParticles.TryGetValue(effectName, out list))
                {
                    list.Add(component);
                    gameRep.persistentVFXParticles[effectName] = list;
                }
                else
                {
                    list = new List <ParticleSystem>();
                    list.Add(component);
                    gameRep.persistentVFXParticles[effectName] = list;
                }
            }

            BTCustomRenderer.SetVFXMultiplier(component);
            component.Play(true);
            if (componentInChildren != null)
            {
                componentInChildren.PlayAnimCurve();
            }
            if (componentInChildren2 != null)
            {
                componentInChildren2.PlayAnimation();
            }

            return(component);
        }