예제 #1
0
        //Set up a control mapping UI section and bind references

        internal static void InitCustomSection(ControlMappingSection mapSection, ControllerMap _controllerMap, IEnumerable <KeybindInfo> keysToAdd)
        {
            if (_controllerMap == null)
            {
                return;
            }

            // Loop through the custom actions we defined
            foreach (var customKey in keysToAdd)
            {
                // add the actual keybind mapping to this controller in Rewired
                _controllerMap.CreateElementMap(customKey.actionID, Pole.Positive, KeyCode.None, ModifierKeyFlags.None);

                var alreadyKnown = At.GetField(mapSection, "m_actionAlreadyKnown") as List <int>;

                // see if the UI has already been set up for this keybind
                if (alreadyKnown.Contains(customKey.actionID))
                {
                    continue;
                }

                // set up the UI for this keybind (same as how game does it)
                alreadyKnown.Add(customKey.actionID);

                var action = ReInput.mapping.GetAction(customKey.actionID);

                var actTemplate = At.GetField(mapSection, "m_actionTemplate") as ControlMappingAction;

                actTemplate.gameObject.SetActive(true);
                if (action.type == InputActionType.Button)
                {
                    At.Invoke(mapSection, "CreateActionRow", CUSTOM_CATEGORY, action, AxisRange.Positive);
                }
                else
                {
                    if (mapSection.ControllerType == ControlMappingPanel.ControlType.Keyboard)
                    {
                        At.Invoke(mapSection, "CreateActionRow", CUSTOM_CATEGORY, action, AxisRange.Positive);
                        At.Invoke(mapSection, "CreateActionRow", CUSTOM_CATEGORY, action, AxisRange.Negative);
                    }
                    else
                    {
                        At.Invoke(mapSection, "CreateActionRow", CUSTOM_CATEGORY, action, AxisRange.Full);
                    }
                }
                actTemplate.gameObject.SetActive(false);

                // Continue the loop of custom keys...
            }
        }
예제 #2
0
        public static void ApplyHairVisuals(CharacterVisuals visuals, int _hairStyleIndex, int _hairColorIndex)
        {
            var presets = CharacterManager.CharacterVisualsPresets;
            var key     = $"Hair{_hairStyleIndex}";
            var dict    = At.GetField(visuals, "m_armorVisualPreview") as Dictionary <string, ArmorVisuals>;

            Material     material = presets.HairMaterials[_hairColorIndex];
            ArmorVisuals hairVisuals;

            if (dict.ContainsKey(key))
            {
                if (!dict[key].gameObject.activeSelf)
                {
                    dict[key].gameObject.SetActive(true);
                }

                hairVisuals = dict[key];
            }
            else
            {
                visuals.UseDefaultVisuals = true;

                hairVisuals = visuals.InstantiateVisuals(presets.Hairs[_hairStyleIndex].transform, visuals.transform).GetComponent <ArmorVisuals>();

                At.SetProperty(visuals, "DefaultHairVisuals", hairVisuals);

                if (!hairVisuals.gameObject.activeSelf)
                {
                    hairVisuals.gameObject.SetActive(true);
                }

                // Add to dict
                dict.Add(key, hairVisuals);
            }

            if (_hairStyleIndex != 0)
            {
                if (!hairVisuals.Renderer)
                {
                    var renderer = hairVisuals.GetComponent <SkinnedMeshRenderer>();
                    At.SetField(hairVisuals, "m_skinnedMeshRenderer", renderer);
                }

                hairVisuals.Renderer.material = material;
                At.Invoke(visuals, "FinalizeSkinnedRenderer", hairVisuals.Renderer);
            }

            hairVisuals.ApplyToCharacterVisuals(visuals);
        }
예제 #3
0
        private static void DoReplaceClip(GlobalAudioManager.Sounds _sound, AudioClip _newClip)
        {
            if (!_newClip)
            {
                SL.LogWarning($"The replacement clip for '{_sound}' is null");
                return;
            }

            //var path = GAMInstance.GetPrefabPath(_sound);
            var path      = (string)At.Invoke(GAMInstance, "GetPrefabPath", _sound);
            var resource  = Resources.Load <GameObject>("_Sounds/" + path);
            var component = resource.GetComponent <AudioSource>();

            component.clip = _newClip;

            resource.hideFlags |= HideFlags.DontUnloadUnusedAsset;

            if (!ReplacedClips.Contains(_sound))
            {
                ReplacedClips.Add(_sound);
            }

            SL.Log("Replaced " + _sound + " AudioSource with custom clip!");
        }
        protected override void ApplyToCharacter(Character character)
        {
            var aiRootPrefab = new GameObject("BasicMelee_AIRoot").AddComponent <AIRoot>();

            aiRootPrefab.gameObject.SetActive(false);

            aiRootPrefab.transform.parent = character.transform;

            // -- create base state objects --

            // state 1: Wander
            var wanderState = new GameObject("1_Wander").AddComponent <AISWander>();

            wanderState.transform.parent = aiRootPrefab.transform;

            // state 2: Suspicious
            var susState = new GameObject("2_Suspicious").AddComponent <AISSuspicious>();

            susState.transform.parent = aiRootPrefab.transform;

            //state 3: alert
            var alertState = new GameObject("3_Alert").AddComponent <AISSuspicious>();

            alertState.transform.parent = aiRootPrefab.transform;

            //state 4: Combat
            var combatState = new GameObject("4_Combat").AddComponent <AISCombatMelee>();

            combatState.transform.parent = aiRootPrefab.transform;

            // ---- setup actual state parameters and links ----

            // setup 1 - Wander

            wanderState.ContagionRange   = this.AIContagionRange;
            wanderState.ForceNotCombat   = this.ForceNonCombat;
            wanderState.SpeedModif       = this.Wander_Speed;
            wanderState.WanderFar        = this.CanWanderFar;
            wanderState.AutoFollowPlayer = this.Wander_FollowPlayer;

            if (this.Wander_PatrolWaypoints != null && this.Wander_Type == AISWander.WanderType.Patrol)
            {
                var wanderTrans = new GameObject($"Waypoints_{character.UID}");
                wanderState.WaypointsParent = wanderTrans.transform;

                for (int i = 0; i < this.Wander_PatrolWaypoints.Length; i++)
                {
                    var waypointObj = new GameObject("Waypoint " + i + 1);
                    var waypoint    = waypointObj.AddComponent <Waypoint>();

                    waypointObj.transform.parent = wanderTrans.transform;

                    waypointObj.transform.position = Wander_PatrolWaypoints[i].WorldPosition;
                    waypoint.RandomRadius          = Wander_PatrolWaypoints[i].RandomRadius;
                    waypoint.WaitTime = Wander_PatrolWaypoints[i].WaitTime;
                }
            }

            var wanderDetection = new GameObject("Detection").AddComponent <AICEnemyDetection>();

            wanderDetection.transform.parent = wanderState.transform;
            var wanderDetectEffects = new GameObject("DetectEffects").AddComponent <AIESwitchState>();

            wanderDetectEffects.ToState          = susState;
            wanderDetectEffects.transform.parent = wanderDetection.transform;
            wanderDetection.DetectEffectsTrans   = wanderDetectEffects.transform;

            //setup 2 - Suspicious

            susState.SpeedModif         = this.Suspicious_Speed;
            susState.SuspiciousDuration = this.Suspicious_Duration;
            susState.Range     = this.Suspicious_Range;
            susState.WanderFar = this.CanWanderFar;
            susState.TurnModif = this.Suspicious_TurnModif;

            var susEnd = new GameObject("EndSuspiciousEffects").AddComponent <AIESwitchState>();

            susEnd.ToState = wanderState;
            var sheathe = susEnd.gameObject.AddComponent <AIESheathe>();

            sheathe.Sheathed                   = true;
            susEnd.transform.parent            = susState.transform;
            susState.EndSuspiciousEffectsTrans = susEnd.transform;

            var susDetection = new GameObject("Detection").AddComponent <AICEnemyDetection>();

            susDetection.transform.parent = susState.transform;
            var susDetectEffects = new GameObject("DetectEffects").AddComponent <AIESwitchState>();

            susDetectEffects.ToState          = combatState;
            susDetectEffects.transform.parent = susDetection.transform;
            susDetection.DetectEffectsTrans   = susDetectEffects.transform;
            var susSuspiciousEffects = new GameObject("SuspiciousEffects").AddComponent <AIESwitchState>();

            susSuspiciousEffects.ToState          = alertState;
            susSuspiciousEffects.transform.parent = susDetection.transform;
            susDetection.SuspiciousEffectsTrans   = susSuspiciousEffects.transform;

            // setup 3 - alert

            alertState.SpeedModif         = this.Suspicious_Speed;
            alertState.SuspiciousDuration = this.Suspicious_Duration;
            alertState.Range     = this.Suspicious_Range;
            alertState.WanderFar = this.CanWanderFar;
            alertState.TurnModif = this.Suspicious_TurnModif;

            var alertEnd = new GameObject("EndSuspiciousEffects").AddComponent <AIESwitchState>();

            alertEnd.ToState = susState;
            var alertsheathe = alertEnd.gameObject.AddComponent <AIESheathe>();

            alertsheathe.Sheathed                = true;
            alertEnd.transform.parent            = alertState.transform;
            alertState.EndSuspiciousEffectsTrans = alertEnd.transform;

            var alertDetection = new GameObject("Detection").AddComponent <AICEnemyDetection>();

            alertDetection.transform.parent = alertState.transform;
            var alertDetectEffects = new GameObject("DetectEffects").AddComponent <AIESwitchState>();

            alertDetectEffects.ToState          = combatState;
            alertDetectEffects.transform.parent = alertDetection.transform;
            alertDetection.DetectEffectsTrans   = alertDetectEffects.transform;

            // setup 4 - Combat

            combatState.ChargeTime = this.Combat_ChargeTime;
            combatState.TargetVulnerableChargeTimeMult = this.Combat_TargetVulnerableChargeModifier;
            combatState.ChargeAttackRangeMult          = this.Combat_ChargeAttackRangeMulti;
            combatState.ChargeAttackTimeToAttack       = this.Combat_ChargeTimeToAttack;
            combatState.ChargeStartRangeMult           = this.Combat_ChargeStartRangeMult;
            combatState.AttackPatterns   = this.Combat_AttackPatterns;
            combatState.SpeedModifs      = this.Combat_SpeedModifiers;
            combatState.ChanceToAttack   = this.Combat_ChanceToAttack;
            combatState.KnowsUnblockable = this.Combat_KnowsUnblockable;
            combatState.DodgeCooldown    = this.Combat_DodgeCooldown;
            combatState.CanBlock         = this.CanBlock;
            combatState.CanDodge         = this.CanDodge;

            var combatDetect = new GameObject("Detection").AddComponent <AICEnemyDetection>();

            combatDetect.transform.parent = combatState.transform;
            var combatEnd = new GameObject("EndCombatEffects").AddComponent <AIESwitchState>();

            combatEnd.ToState          = wanderState;
            combatEnd.transform.parent = combatState.transform;

            // add required components for AIs (no setup required)
            character.gameObject.AddComponent <NavMeshAgent>();
            character.gameObject.AddComponent <AISquadMember>();
            character.gameObject.AddComponent <EditorCharacterAILoadAI>();

            if (character.GetComponent <NavMeshObstacle>() is NavMeshObstacle navObstacle)
            {
                GameObject.Destroy(navObstacle);
            }

            // add our basic AIStatesPrefab to a CharacterAI component. This is the prefab set up by SetupBasicAIPrefab(), below.
            CharacterAI charAI = character.gameObject.AddComponent <CharacterAI>();

            At.SetField(charAI, "m_character", character);
            charAI.AIStatesPrefab = aiRootPrefab;

            // initialize the AI States (not entirely necessary, but helpful if we want to do something with the AI immediately after)
            At.Invoke(charAI, "GetAIStates", null);
        }
        protected internal void LateApplyStatusEffects(StatusEffect status)
        {
            if (!string.IsNullOrEmpty(this.ComplicationStatusIdentifier))
            {
                var complicStatus = ResourcesPrefabManager.Instance.GetStatusEffectPrefab(this.ComplicationStatusIdentifier);
                if (complicStatus)
                {
                    status.ComplicationStatus = complicStatus;
                }
            }

            if (!string.IsNullOrEmpty(RequiredStatusIdentifier))
            {
                var required = ResourcesPrefabManager.Instance.GetStatusEffectPrefab(this.RequiredStatusIdentifier);
                if (required)
                {
                    status.RequiredStatus = required;
                }
            }

            if (!string.IsNullOrEmpty(this.AmplifiedStatusIdentifier))
            {
                var amp = ResourcesPrefabManager.Instance.GetStatusEffectPrefab(AmplifiedStatusIdentifier);
                if (amp)
                {
                    At.SetField(status, "m_amplifiedStatus", amp);
                }
                else
                {
                    SL.Log("StatusEffect.ApplyTemplate - could not find AmplifiedStatusIdentifier " + this.AmplifiedStatusIdentifier);
                }
            }

            // setup signature and finalize

            if (EffectBehaviour == EditBehaviours.Destroy)
            {
                UnityHelpers.DestroyChildren(status.transform);
            }

            Transform signature;

            if (status.transform.childCount < 1)
            {
                signature        = new GameObject($"SIGNATURE_{status.IdentifierName}").transform;
                signature.parent = status.transform;
                var comp = signature.gameObject.AddComponent <EffectSignature>();
                comp.SignatureUID = new UID($"{NewStatusID}_{status.IdentifierName}");
            }
            else
            {
                signature = status.transform.GetChild(0);
            }

            if (Effects != null)
            {
                if (signature)
                {
                    SL_EffectTransform.ApplyTransformList(signature, Effects, EffectBehaviour);
                }
                else
                {
                    SL.Log("Could not get effect signature!");
                }
            }

            // fix StatusData for the new effects
            CompileEffectsToData(status);

            var sigComp = signature.GetComponent <EffectSignature>();

            sigComp.enabled = true;

            var effects = signature.GetComponentsInChildren <Effect>();

            sigComp.Effects = effects.ToList();

            // Fix the effect signature for reference families
            if (status.FamilyMode == StatusEffect.FamilyModes.Reference)
            {
                signature.transform.parent = SL.CloneHolder;

                var family = status.EffectFamily;
                family.EffectSignature            = sigComp;
                status.StatusData.EffectSignature = sigComp;
            }

            // Need to reset description after changing effects.
            At.Invoke(status, "RefreshLoc");
        }