public void Serialize(TrapEffectRecipe recipe)
        {
            this.Name        = recipe.Name;
            this.Description = recipe.Description;

            var items = (Item[])At.GetField(recipe, "m_compatibleItems");

            if (items != null)
            {
                this.CompatibleItemIDs = new List <int>();
                foreach (var item in items)
                {
                    // this.CompatibleItemIDs.Add(item.ItemID);
                    this.CompatibleItemIDs.Add(item.ItemID);
                }
            }

            var tags = (TagSourceSelector[])At.GetField(recipe, "m_compatibleTags");

            if (tags != null)
            {
                this.CompatibleItemTags = new List <string>();
                foreach (var tag in tags)
                {
                    this.CompatibleItemTags.Add(tag.Tag.TagName);
                }
            }

            if (recipe.TrapEffectsPrefab)
            {
                this.TrapEffects = new List <SL_Effect>();
                foreach (var effect in recipe.TrapEffectsPrefab.GetComponents <Effect>())
                {
                    this.TrapEffects.Add(SL_Effect.ParseEffect(effect));
                }
            }
            if (recipe.HiddenTrapEffectsPrefab)
            {
                this.HiddenEffects = new List <SL_Effect>();
                foreach (var effect in recipe.HiddenTrapEffectsPrefab.GetComponents <Effect>())
                {
                    this.HiddenEffects.Add(SL_Effect.ParseEffect(effect));
                }
            }
        }
Example #2
0
        public static SL_EffectTransform ParseTransform(Transform transform)
        {
            var holder = new SL_EffectTransform
            {
                TransformName = transform.name
            };

            if (transform.localPosition != Vector3.zero)
            {
                holder.Position = transform.localPosition;
            }
            if (transform.localEulerAngles != Vector3.zero)
            {
                holder.Rotation = transform.localEulerAngles;
            }
            if (transform.localScale != Vector3.one)
            {
                holder.Scale = transform.localScale;
            }

            var slEffects = new List <SL_Effect>();

            foreach (Effect effect in transform.GetComponents <Effect>())
            {
                if (!effect.enabled)
                {
                    continue;
                }

                if (SL_Effect.ParseEffect(effect) is SL_Effect slEffect)
                {
                    slEffects.Add(slEffect);
                }
            }
            holder.Effects = slEffects.ToArray();

            var slConditions = new List <SL_EffectCondition>();

            foreach (EffectCondition condition in transform.GetComponents <EffectCondition>())
            {
                if (!condition.enabled)
                {
                    continue;
                }

                if (SL_EffectCondition.ParseCondition(condition) is SL_EffectCondition slCondition)
                {
                    slConditions.Add(slCondition);
                }
            }
            holder.EffectConditions = slConditions.ToArray();

            var children = new List <SL_EffectTransform>();

            foreach (Transform child in transform)
            {
                if (child.name == "ExplosionFX" || child.name == "ProjectileFX")
                {
                    continue;
                }

                var transformHolder = ParseTransform(child);

                if (transformHolder.HasContent)
                {
                    children.Add(transformHolder);
                }
            }
            holder.ChildEffects = children.ToArray();

            return(holder);
        }