/// <summary> /// Applies a list of SL_EffectTransforms to a transform parent, with the provided EffectBehaviour. /// </summary> /// <param name="parent">The parent to apply to, ie. the Item, StatusEffect.Signature, or Blast/Projectile, etc</param> /// <param name="transformsToApply">The list of SL_EffectTransforms to apply.</param> /// <param name="behaviour">The desired behaviour for these transoforms (remove original, overwrite, or none)</param> public static void ApplyTransformList(Transform parent, SL_EffectTransform[] transformsToApply, EditBehaviours behaviour) { if (behaviour == EditBehaviours.Destroy) { UnityHelpers.DestroyChildren(parent); } if (transformsToApply == null) { return; } foreach (var child in transformsToApply) { if (behaviour == EditBehaviours.Override && parent.Find(child.TransformName) is Transform existing) { UnityEngine.Object.DestroyImmediate(existing.gameObject); } child.ApplyToTransform(parent, behaviour); } }
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"); }
public TrapEffectRecipe Apply() { var recipe = new TrapEffectRecipe(); At.SetField(recipe, "m_name", this.Name); SetLocalization(); if (this.CompatibleItemTags != null) { var list = new List <TagSourceSelector>(); foreach (var tagName in this.CompatibleItemTags) { if (CustomTags.GetTag(tagName) is Tag tag && tag != Tag.None) { list.Add(new TagSourceSelector(tag)); } } At.SetField(recipe, "m_compatibleTags", list.ToArray()); } if (this.CompatibleItemIDs != null) { var list = new List <Item>(); foreach (var itemID in this.CompatibleItemIDs) { if (ResourcesPrefabManager.Instance.GetItemPrefab(itemID) is Item item) { list.Add(item); } } At.SetField(recipe, "m_compatibleItems", list.ToArray()); } if (this.TrapEffects != null && this.TrapEffects.Count > 0) { var prefab = recipe.TrapEffectsPrefab; if (!prefab) { prefab = new GameObject($"{this.Name}_NormalEffects").transform; GameObject.DontDestroyOnLoad(prefab.gameObject); recipe.TrapEffectsPrefab = prefab; } UnityHelpers.DestroyChildren(prefab); foreach (var effect in this.TrapEffects) { effect.ApplyToTransform(prefab); } } if (this.HiddenEffects != null && this.HiddenEffects.Count > 0) { var prefab = recipe.HiddenTrapEffectsPrefab; if (!prefab) { prefab = new GameObject($"{this.Name}_HiddenEffects").transform; GameObject.DontDestroyOnLoad(prefab.gameObject); recipe.HiddenTrapEffectsPrefab = prefab; } UnityHelpers.DestroyChildren(prefab); foreach (var effect in this.HiddenEffects) { effect.ApplyToTransform(prefab); } } return(recipe); }
public static void DestroyChildren(Transform t, bool destroyContent = false) { UnityHelpers.DestroyChildren(t, destroyContent); }