예제 #1
0
        public override void OnEnter()
        {
            if (trailOwner.GameObject.Value == null)
            {
                Finish();
            }

            var go = Fsm.GetOwnerDefaultTarget(trailOwner);

            trail = go.gameObject.GetComponent <XWeaponTrail>();

            if (enable.Value == true)
            {
                trail.Activate();
            }
            else
            {
                if (stopSmoothly.Value == true)
                {
                    trail.StopSmoothly(fadeTime.Value);
                }
                else
                {
                    trail.Deactivate();
                }
            }
        }
예제 #2
0
        public void Init(Saber saber, ColorManager colorManager)
        {
            Logger.log.Debug($"Replacing Trail for '{saber?.saberType}'");

            if (gameObject.name != "LeftSaber" && gameObject.name != "RightSaber")
            {
                Logger.log.Warn("Parent not LeftSaber or RightSaber");
                Destroy(this);
            }

            if (!saber)
            {
                Logger.log.Warn("Saber not found");
                Destroy(this);
            }

            IEnumerable <XWeaponTrail> trails = Resources.FindObjectsOfTypeAll <XWeaponTrail>();

            foreach (XWeaponTrail trail in trails)
            {
                ReflectionUtil.SetField(trail, "_trailWidth", 0f);
            }

            XWeaponTrail oldtrail = Resources.FindObjectsOfTypeAll <GameCoreSceneSetup>().FirstOrDefault()
                                    ?.GetField <BasicSaberModelController, GameCoreSceneSetup>("_basicSaberModelControllerPrefab")
                                    ?.GetField <XWeaponTrail, BasicSaberModelController>("_saberWeaponTrail");

            if (oldtrail)
            {
                try
                {
                    oldTrailRendererPrefab = ReflectionUtil.GetField <XWeaponTrailRenderer, XWeaponTrail>(oldtrail, "_trailRendererPrefab");
                }
                catch (Exception ex)
                {
                    Logger.log.Error(ex);
                    throw;
                }

                if (Configuration.OverrideTrailLength)
                {
                    Length      = (int)(Length * Configuration.TrailLength);
                    Granularity = (int)(Granularity * Configuration.TrailLength);
                }

                if (Length > 1)
                {
                    trail = gameObject.AddComponent <CustomWeaponTrail>();
                    trail.Init(oldTrailRendererPrefab, colorManager, PointStart, PointEnd, TrailMaterial, TrailColor, Length, Granularity, MultiplierColor, colorType);
                }

                //if (Configuration.OverrideTrailLength) SetGranularity((int)(trail.GetField<int, CustomWeaponTrail>("_granularity") * Configuration.TrailLength));
            }
            else
            {
                Logger.log.Debug($"Trail not found for '{saber?.saberType}'");
                Destroy(this);
            }
        }
예제 #3
0
        public override void OnEnter()
        {
            var go = Fsm.GetOwnerDefaultTarget(gameObject);

            theScript = go.GetComponent <XWeaponTrail>();

            if (!everyFrame.Value)
            {
                MakeItSo();
                Finish();
            }
        }
예제 #4
0
 private void ModifyTrail(XWeaponTrail trail, int length)
 {
     if (Configuration.Trail.TrailEnabled)
     {
         trail.enabled = true;
         trail.SetField("_maxFrame", length);
         trail.SetField("_granularity", length * 3);
     }
     else
     {
         trail.enabled = false;
     }
 }
예제 #5
0
        private void RescaleWeaponTrail(XWeaponTrail trail, float lengthMultiplier, bool usingCustomModels)
        {
            float trailWidth = trail.GetField <float, XWeaponTrail>("_trailWidth");

            trail.SetField("_trailWidth", trailWidth * lengthMultiplier);

            // Fix the local z position for the default trail on custom sabers
            if (usingCustomModels)
            {
                Transform pointEnd = trail.GetField <Transform, XWeaponTrail>("_pointEnd");
                pointEnd.localPosition = Vector3Extensions.Rescale(pointEnd.localPosition, 1.0f, 1.0f, pointEnd.localPosition.z * lengthMultiplier);
            }
        }
예제 #6
0
        void ModifyTrail(XWeaponTrail trail)
        {
            var length = Preferences.TrailLength;

            if (Preferences.IsTrailEnabled)
            {
                ReflectionUtil.SetPrivateField(trail, "_maxFrame", length);
                ReflectionUtil.SetPrivateField(trail, "_granularity", length * 3);
            }
            else
            {
                trail.enabled = false;
            }
        }
예제 #7
0
        private IEnumerator ApplyGameCoreModifications()
        {
            IEnumerable <BasicSaberModelController> basicSaberModelControllers = Resources.FindObjectsOfTypeAll <BasicSaberModelController>();

            foreach (BasicSaberModelController basicSaberModelController in basicSaberModelControllers)
            {
                XWeaponTrail saberTrail = basicSaberModelController.GetField <XWeaponTrail, BasicSaberModelController>("_saberWeaponTrail");
                if (saberTrail.name == "BasicSaberModel")
                {
                    ModifyTrail(saberTrail, Configuration.Trail.Length);
                    Logger.log.Info("Successfully modified trails!");
                }
            }

            yield return(null);
        }
예제 #8
0
    public override void activeWeaponTrail(bool isUse = false)
    {
        if (trail == null)
        {
            GameObject weapon = this.getPartObj(EntityPartType.weapon);
            trail = weapon.GetComponent <XWeaponTrail>();
        }

        if (trail != null)
        {
            if (isUse)
            {
                trail.Activate();
            }
            else
            {
                trail.Deactivate();
            }
        }
    }
예제 #9
0
        private void Start()
        {
            Console.WriteLine("Replacing Trail");

            if (gameObject.name != "LeftSaber" && gameObject.name != "RightSaber")
            {
                Console.WriteLine("Parent not LeftSaber or RightSaber");
                Destroy(this);
            }

            GameObject _saber = FindParentWithName(this.gameObject, "Saber");

            if (_saber == null)
            {
                Console.WriteLine("Saber not found");
                Destroy(this);
            }

            trail = _saber.GetComponent <XWeaponTrail>();
            if (trail != null)
            {
                ReflectionUtil.SetPrivateField(trail, "PointStart", PointStart);
                ReflectionUtil.SetPrivateField(trail, "PointEnd", PointEnd);
                ReflectionUtil.SetPrivateField(trail, "MyColor", TrailColor);
                ReflectionUtil.SetPrivateField(trail, "MyMaterial", TrailMaterial);
                ReflectionUtil.SetPrivateField(trail, "MaxFrame", Length);

                XWeaponTrailRenderer trailRenderer = ReflectionUtil.GetPrivateField <XWeaponTrailRenderer>(trail, "_trailRenderer");
                MeshRenderer         meshRenderer  = ReflectionUtil.GetPrivateField <MeshRenderer>(trailRenderer, "_meshRenderer");
                meshRenderer.material = TrailMaterial;

                trail.UpdateHeadElem();
                trail.UpdateVertex();
            }
            else
            {
                Console.WriteLine("Trail not found");
                Destroy(this);
            }
        }
예제 #10
0
 public override void Reset()
 {
     trailOwner = null;
     trail      = null;
 }
예제 #11
0
        private IEnumerator ApplyGameCoreModifications()
        {
            bool       usingCustomModels = false;
            Saber      defaultLeftSaber  = null;
            Saber      defaultRightSaber = null;
            GameObject LeftSaber         = null;
            GameObject RightSaber        = null;

            // Find and set the default sabers first
            IEnumerable <Saber> sabers = Resources.FindObjectsOfTypeAll <Saber>();

            foreach (Saber saber in sabers)
            {
                if (saber.saberType == SaberType.SaberB)
                {
                    defaultLeftSaber = saber;
                    LeftSaber        = saber.gameObject;
                }
                else if (saber.saberType == SaberType.SaberA)
                {
                    defaultRightSaber = saber;
                    RightSaber        = saber.gameObject;
                }
            }

            if (Utilities.Utils.IsPluginEnabled("Custom Sabers"))
            {
                // Wait a moment for CustomSaber to catch up
                yield return(new WaitForSeconds(0.1f));

                GameObject customSaberClone = GameObject.Find("_CustomSaber(Clone)");

                // If customSaberClone is null, CustomSaber is most likely not replacing the default sabers.
                if (customSaberClone != null)
                {
                    LeftSaber         = GameObject.Find("LeftSaber");
                    RightSaber        = GameObject.Find("RightSaber");
                    usingCustomModels = true;
                }
                else
                {
                    Logger.log.Debug("Either the Default Sabers are selected or CustomSaber were too slow!");
                }
            }

            // Scaling default saber will affect its hitbox, so save the default hitbox positions first before scaling
            HitboxRevertWorkaround hitboxVariables = null;

            if (!usingCustomModels && !Configuration.Scale.ScaleHitBox)
            {
                hitboxVariables = new HitboxRevertWorkaround(defaultLeftSaber, defaultRightSaber);
            }

            // Rescale visible sabers (either default or custom)
            RescaleSaber(LeftSaber, Configuration.Scale.Length, Configuration.Scale.Girth);
            RescaleSaber(RightSaber, Configuration.Scale.Length, Configuration.Scale.Girth);

            // Scaling custom sabers will not change their hitbox, so a manual hitbox rescale is necessary, if the option is enabled
            if (usingCustomModels && Configuration.Scale.ScaleHitBox)
            {
                RescaleSaberHitBox(defaultLeftSaber, Configuration.Scale.Length);
                RescaleSaberHitBox(defaultRightSaber, Configuration.Scale.Length);
            }

            // Revert hitbox changes to default sabers, if hitbox scaling is disabled
            if (hitboxVariables != null)
            {
                hitboxVariables.RestoreHitbox();
            }

            IEnumerable <BasicSaberModelController> basicSaberModelControllers = Resources.FindObjectsOfTypeAll <BasicSaberModelController>();

            foreach (BasicSaberModelController basicSaberModelController in basicSaberModelControllers)
            {
                XWeaponTrail saberWeaponTrail = basicSaberModelController.GetField <XWeaponTrail, BasicSaberModelController>("_saberWeaponTrail");
                if (!usingCustomModels || saberWeaponTrail.name != "BasicSaberModel")
                {
                    RescaleWeaponTrail(saberWeaponTrail, Configuration.Scale.Length, usingCustomModels);
                }
            }

            yield return(null);
        }