Ejemplo n.º 1
0
        public override void Init()
        {
            if (!_trailRenderer)
            {
                _trailRenderer = UnityEngine.Object.Instantiate <SaberTrailRenderer>(_trailRendererPrefab, new Vector3(0, TRAIL_Y_OFFSET), Quaternion.identity);
            }
            if (!leftClawRenderer)
            {
                leftClawRenderer = UnityEngine.Object.Instantiate <SaberTrailRenderer>(_trailRendererPrefab, new Vector3(-TRAIL_X_OFFSET, TRAIL_Y_OFFSET), Quaternion.identity);
            }
            if (!rightClawRenderer)
            {
                rightClawRenderer = UnityEngine.Object.Instantiate <SaberTrailRenderer>(_trailRendererPrefab, new Vector3(TRAIL_X_OFFSET, TRAIL_Y_OFFSET), Quaternion.identity);
            }

            _sampleStep = 1f / _samplingFrequency;
            BladeMovementDataElement lastAddedData = _movementData.lastAddedData;
            Vector3 bottomPos = lastAddedData.bottomPos;
            Vector3 topPos    = lastAddedData.topPos;

            _lastTrailElementTime   = lastAddedData.time;
            _trailElementCollection = new TrailElementCollection(Mathf.CeilToInt(_samplingFrequency * _trailDuration) + 3, bottomPos, calcNewTopPos(bottomPos, topPos), _lastTrailElementTime);
            float trailWidth = GetTrailWidth(lastAddedData);

            _whiteSectionMaxDuration = Math.Min(_whiteSectionMaxDuration, _trailDuration);
            _lastZScale = transform.lossyScale.z;
            _trailRenderer.Init(trailWidth, _trailDuration, _granularity, _whiteSectionMaxDuration);
            leftClawRenderer.Init(trailWidth, _trailDuration, _granularity, _whiteSectionMaxDuration);
            rightClawRenderer.Init(trailWidth, _trailDuration, _granularity, _whiteSectionMaxDuration);
            _inited = true;
        }
Ejemplo n.º 2
0
        public void Init(SaberTrailRenderer TrailRendererPrefab, ColorManager colorManager, Transform PointStart, Transform PointEnd, Material TrailMaterial, Color TrailColor, int Length, int Granularity, Color multiplierSaberColor, ColorType colorType)
        {
            _colorManager         = colorManager;
            _multiplierSaberColor = multiplierSaberColor;
            _customColor          = TrailColor;
            _customMaterial       = TrailMaterial;
            _saberType            = colorType;

            _pointStart    = PointStart;
            _pointEnd      = PointEnd;
            _trailDuration = Length / 75f;
            if (!Settings.Configuration.DisableWhitestep)
            {
                _whiteSectionMaxDuration = 0.04f;
            }

            Logger.log.Info($"Granularity: {_granularity}");
            _granularity         = Granularity;
            _trailRendererPrefab = TrailRendererPrefab;

            SaberModelController saberModelController = Resources.FindObjectsOfTypeAll <SaberModelController>().FirstOrDefault();

            SaberModelController.InitData initData = saberModelController?.GetField <SaberModelController.InitData, SaberModelController>("_initData");
            if (initData != null)
            {
                trailTintColor = initData.trailTintColor;
            }

            _trailRenderer = Instantiate <SaberTrailRenderer>(TrailRendererPrefab, Vector3.zero, Quaternion.identity);
        }
Ejemplo n.º 3
0
 public void CreateTrail(SaberTrailRenderer rendererPrefab)
 {
     TrailHandler = new TrailHandler(GameObject);
     TrailHandler.SetPrefab(rendererPrefab);
     TrailHandler.SetTrailData(GetTrailData());
     TrailHandler.CreateTrail();
 }
Ejemplo n.º 4
0
        private IEnumerator SetVanillaTrailVisibilityCoroutine(float trailWidth)
        {
            void SetVanillaTrailVisibilityCoroutineInner()
            {
                foreach (SaberTrail trail in Resources.FindObjectsOfTypeAll <SaberTrail>())
                {
                    if (!(trail is CustomWeaponTrail))
                    {
                        SaberTrailRenderer trailRenderer = trail.GetField <SaberTrailRenderer, SaberTrail>("_trailRenderer");
                        if (trailRenderer != null)
                        {
                            trailRenderer.SetTrailWidth(trailWidth);
                        }
                    }
                }
            }

            // wait 5 frames for default trailwidth is set
            for (int i = 0; i < 5; i++)
            {
                yield return(null);
            }
            SetVanillaTrailVisibilityCoroutineInner();

            // just in case
            yield return(new WaitForSecondsRealtime(0.1f));

            SetVanillaTrailVisibilityCoroutineInner();
        }
Ejemplo n.º 5
0
        public override void Init()
        {
            if (!_trailRenderer)
            {
                _trailRenderer = Instantiate(_trailRendererPrefab, new Vector3(0, TrailYOffset), Quaternion.identity);
            }
            if (!_leftClawRenderer)
            {
                _leftClawRenderer = Instantiate(_trailRendererPrefab, new Vector3(-TrailXOffset, TrailYOffset), Quaternion.identity);
            }
            if (!_rightClawRenderer)
            {
                _rightClawRenderer = Instantiate(_trailRendererPrefab, new Vector3(TrailXOffset, TrailYOffset), Quaternion.identity);
            }

            _sampleStep = 1f / _samplingFrequency;
            var lastAddedData = _movementData.lastAddedData;
            var bottomPos     = lastAddedData.bottomPos;
            var topPos        = lastAddedData.topPos;

            _lastTrailElementTime   = lastAddedData.time;
            _trailElementCollection = new TrailElementCollection(Mathf.CeilToInt(_samplingFrequency * _trailDuration) + 3, bottomPos, CalcNewTopPos(bottomPos, topPos), _lastTrailElementTime);
            var trailWidth = GetTrailWidth(lastAddedData);

            _whiteSectionMaxDuration = Math.Min(_whiteSectionMaxDuration, _trailDuration);
            _lastZScale = transform.lossyScale.z;
            _trailRenderer.Init(trailWidth, _trailDuration, _granularity, _whiteSectionMaxDuration);
            _leftClawRenderer.Init(trailWidth, _trailDuration * 0.5f, _granularity, _whiteSectionMaxDuration * 0.5f);
            _rightClawRenderer.Init(trailWidth, _trailDuration * 0.5f, _granularity, _whiteSectionMaxDuration * 0.5f);
            _inited = true;
        }
Ejemplo n.º 6
0
 private static void Postfix(SaberTrailRenderer __instance)
 {
     if (Configuration.Trail.TweakEnabled && !Configuration.Trail.TrailEnabled)
     {
         __instance.enabled = false;
         Logger.log.Info("Successfully disabled trails!");
     }
 }
Ejemplo n.º 7
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<SaberTrailRenderer> trails = Resources.FindObjectsOfTypeAll<SaberTrailRenderer>();
            foreach (SaberTrailRenderer trail in trails)
            {
                ReflectionUtil.SetField(trail, "_trailWidth", 0f);
            }

            SaberTrail oldtrail = Resources.FindObjectsOfTypeAll<SaberModelContainer>().FirstOrDefault()
                ?.GetField<SaberModelController, SaberModelContainer>("_saberModelControllerPrefab")
                ?.GetField<SaberTrail, SaberModelController>("_saberTrail");

            if (oldtrail)
            {
                try
                {
                    oldTrailRendererPrefab = ReflectionUtil.GetField<SaberTrailRenderer, SaberTrail>(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);
            }
        }
Ejemplo n.º 8
0
        ////////////////////////////////////////////////////////////////////////////
        ////////////////////////////////////////////////////////////////////////////

        /// <summary>
        /// Prefix
        /// </summary>
        /// <param name="__instance">SaberTrailRenderer instance</param>
        internal static void Prefix(ref SaberTrailRenderer __instance, ref MeshRenderer ____meshRenderer)
        {
            if (____meshRenderer && !m_MeshRenderers.Contains(____meshRenderer))
            {
                m_MeshRenderers.Add(____meshRenderer);
                if (Config.GameTweaker.Enabled)
                {
                    ____meshRenderer.material.EnableKeyword("_ALPHAPREMULTIPLY_ON");

                    /// Apply
                    SetEnabled(Config.GameTweaker.RemoveSaberSmoothingTrail, Config.GameTweaker.SaberSmoothingTrailIntensity);
                }
            }
        }
Ejemplo n.º 9
0
        private void RescaleWeaponTrail(SaberTrail trail, float lengthMultiplier, bool usingCustomModels)
        {
            SaberTrailRenderer trailRenderer = trail.GetField <SaberTrailRenderer, SaberTrail>("_trailRenderer");

            float trailWidth = trailRenderer.GetField <float, SaberTrailRenderer>("_trailWidth");

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

            // Fix the local z position for the default trail on custom sabers
            if (usingCustomModels)
            {
                Transform pointEnd = trail.GetField <Transform, SaberTrail>("_pointEnd");
                pointEnd.localPosition = Vector3Extensions.Rescale(pointEnd.localPosition, 1.0f, 1.0f, pointEnd.localPosition.z * lengthMultiplier);
            }
        }
Ejemplo n.º 10
0
 static bool Prefix(SaberTrailRenderer ____trailRendererPrefab)
 {
     return(____trailRendererPrefab != null);
 }
Ejemplo n.º 11
0
 public void RegisterPrefab(SaberTrailRenderer prefab)
 {
     _trailRendererPrefab = prefab;
 }
Ejemplo n.º 12
0
 public void SetPrefab(SaberTrailRenderer trailRenderer)
 {
     _trailRenderer = trailRenderer;
 }
        public void GenerateHandheldSaberPreview()
        {
            if (Environment.CommandLine.Contains("fpfc"))
            {
                return;
            }
            var customSaber = SaberAssetLoader.CustomSabers[SaberAssetLoader.SelectedSaber];

            if (customSaber == null || !customSaber.Sabers || preview == null)
            {
                return;
            }
            var controllers  = Resources.FindObjectsOfTypeAll <VRController>();
            var sabers       = CreatePreviewSaber(customSaber.Sabers, preview.transform, sabersPos);
            var colorManager = Resources.FindObjectsOfTypeAll <ColorManager>().First();

            try
            {
                foreach (var collider in sabers.GetComponentsInChildren <Collider>())
                {
                    collider.enabled = false;
                }

                if (_trailRendererPrefab == null)
                {
                    foreach (var trail in Resources.FindObjectsOfTypeAll <SaberTrail>())
                    {
                        _trailRendererPrefab = trail.GetField <SaberTrailRenderer, SaberTrail>("_trailRendererPrefab");
                        if (_trailRendererPrefab != null)
                        {
                            break;
                        }
                    }
                }

                foreach (var controller in controllers)
                {
                    if (controller?.node == XRNode.LeftHand)
                    {
                        _leftController = controller;

                        leftSaber = sabers?.transform.Find("LeftSaber").gameObject;
                        if (!leftSaber)
                        {
                            continue;
                        }

                        leftSaber.transform.parent   = controller.transform;
                        leftSaber.transform.position = controller.transform.position;
                        leftSaber.transform.rotation = controller.transform.rotation;

                        leftSaber.SetActive(true);

                        var trails = leftSaber.GetComponentsInChildren <CustomTrail>();

                        if (trails == null || trails.Count() == 0)
                        {
                            SaberTrail saberTrail = leftSaber.AddComponent <SaberTrail>();
                            saberTrail.SetField("_trailRenderer", Instantiate(_trailRendererPrefab, Vector3.zero, Quaternion.identity));
                            saberTrail.Setup(colorManager.ColorForSaberType(SaberType.SaberA), _leftMovementData);

                            if (Configuration.OverrideTrailLength)
                            {
                                float length = Configuration.TrailLength * 30;
                                saberTrail.SetField("_trailDuration", length / 75f);
                            }
                            if (Configuration.DisableWhitestep)
                            {
                                saberTrail.SetField("_whiteSectionMaxDuration", 0f);
                            }
                        }
                        else
                        {
                            foreach (var trail in trails)
                            {
                                trail.Length = (Configuration.OverrideTrailLength) ? (int)(trail.Length * Configuration.TrailLength) : trail.Length;
                                if (trail.Length < 2 || !trail.PointStart || !trail.PointEnd)
                                {
                                    continue;
                                }
                                {
                                    leftSaber.AddComponent <CustomWeaponTrail>().Init(_trailRendererPrefab, colorManager, trail.PointStart, trail.PointEnd,
                                                                                      trail.TrailMaterial, trail.TrailColor, trail.Length, trail.Granularity, trail.MultiplierColor, trail.colorType);
                                }
                            }
                        }

                        leftSaber.AddComponent <DummySaber>();

                        controller.transform.Find("MenuHandle")?.gameObject.SetActive(false);
                    }
                    else if (controller?.node == XRNode.RightHand)
                    {
                        _rightController = controller;

                        rightSaber = sabers?.transform.Find("RightSaber").gameObject;
                        if (!rightSaber)
                        {
                            continue;
                        }

                        rightSaber.transform.parent   = controller.transform;
                        rightSaber.transform.position = controller.transform.position;
                        rightSaber.transform.rotation = controller.transform.rotation;

                        rightSaber.SetActive(true);

                        var trails = rightSaber.GetComponentsInChildren <CustomTrail>();

                        if (trails == null || trails.Count() == 0)
                        {
                            SaberTrail saberTrail = rightSaber.AddComponent <SaberTrail>();
                            saberTrail.SetField("_trailRenderer", Instantiate(_trailRendererPrefab, Vector3.zero, Quaternion.identity));
                            saberTrail.Setup(colorManager.ColorForSaberType(SaberType.SaberB), _rightMovementData);

                            if (Configuration.OverrideTrailLength)
                            {
                                float length = Configuration.TrailLength * 30;
                                saberTrail.SetField("_trailDuration", length / 75f);
                            }
                            if (Configuration.DisableWhitestep)
                            {
                                saberTrail.SetField("_whiteSectionMaxDuration", 0f);
                            }
                        }
                        else
                        {
                            foreach (var trail in trails)
                            {
                                trail.Length = (Configuration.OverrideTrailLength) ? (int)(trail.Length * Configuration.TrailLength) : trail.Length;
                                if (trail.Length < 2 || !trail.PointStart || !trail.PointEnd)
                                {
                                    continue;
                                }
                                rightSaber.AddComponent <CustomWeaponTrail>().Init(_trailRendererPrefab, colorManager, trail.PointStart, trail.PointEnd,
                                                                                   trail.TrailMaterial, trail.TrailColor, trail.Length, trail.Granularity, trail.MultiplierColor, trail.colorType);
                            }
                        }

                        rightSaber.AddComponent <DummySaber>();

                        controller.transform.Find("MenuHandle")?.gameObject.SetActive(false);
                    }
                    if (leftSaber && rightSaber)
                    {
                        break;
                    }
                }
                StartCoroutine(HideOrShowPointer());
            }
            catch (Exception e)
            {
                Logger.log.Error($"Error generating saber preview\n{e.Message} - {e.StackTrace}");
            }
            finally
            {
                DestroyGameObject(ref sabers);
            }
        }