Ejemplo n.º 1
0
        /// <summary>
        /// Pass the desired parent Transform, this method will create 'this.TransformName' on it, then apply the Effects and Conditions.
        /// </summary>
        /// <param name="parent">The PARENT transform to apply to (the Item, StatusEffect.Signature, Blast/Projectile, etc)</param>
        /// <param name="behaviour">Desired EffectBehaviour</param>
        public Transform ApplyToTransform(Transform parent, EditBehaviours behaviour)
        {
            Transform transform = new GameObject(this.TransformName).transform;

            transform.parent = parent;

            if (this.Position != null)
            {
                transform.localPosition = (Vector3)this.Position;
            }
            if (this.Rotation != null)
            {
                transform.localRotation = Quaternion.Euler((Vector3)this.Rotation);
            }
            if (this.Scale != null)
            {
                transform.localScale = (Vector3)this.Scale;
            }

            // apply effects
            if (this.Effects != null)
            {
                foreach (var effect in this.Effects)
                {
                    effect.ApplyToTransform(transform);
                }
            }

            // apply conditions
            if (this.EffectConditions != null)
            {
                foreach (var condition in this.EffectConditions)
                {
                    condition.ApplyToTransform(transform);
                }
            }

            if (ChildEffects != null)
            {
                ApplyTransformList(transform, ChildEffects, behaviour);
            }

            return(transform);
        }
Ejemplo n.º 2
0
        /// <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);
            }
        }
Ejemplo n.º 3
0
        public static void ApplyExtensionList(Item item, SL_ItemExtension[] list, EditBehaviours editBehaviour = EditBehaviours.Override)
        {
            var dict = new Dictionary <Type, SL_ItemExtension>(); // Key: Game_type, Value: SL_ItemExtension template.

            // First, prepare the Dictionary, and add components that don't already exist.
            foreach (var slExtension in list)
            {
                var sl_type   = slExtension.GetType();
                var game_type = Serializer.GetGameType(sl_type);

                if (dict.ContainsKey(game_type))
                {
                    SL.Log("Cannot add more than one of the same ItemExtension!");
                    continue;
                }

                dict.Add(game_type, slExtension);

                if (!item.GetComponentInChildren(game_type))
                {
                    if (slExtension.AddToChild)
                    {
                        var child = item.transform.Find(slExtension.ChildToAddTo);
                        if (!child)
                        {
                            child        = new GameObject(slExtension.ChildToAddTo).transform;
                            child.parent = item.transform;
                        }
                        child.gameObject.AddComponent(game_type);
                    }
                    else
                    {
                        item.gameObject.AddComponent(game_type);
                    }
                }
            }

            // Now iterate the actual ItemExtension components, removing ones the user didn't define.
            // Also, apply SL templates to the Extensions now.
            var toRemove = new List <ItemExtension>();

            foreach (var comp in item.GetComponentsInChildren <ItemExtension>())
            {
                var game_type = comp.GetType();
                if (!dict.ContainsKey(game_type))
                {
                    if (editBehaviour == EditBehaviours.Destroy)
                    {
                        toRemove.Add(comp);
                    }
                }
                else
                {
                    var template = dict[game_type];

                    if (template.Savable != null)
                    {
                        comp.Savable = (bool)template.Savable;
                    }

                    template.ApplyToComponent(comp);
                }
            }

            if (editBehaviour == EditBehaviours.Destroy)
            {
                // Finally, remove the Extensions we don't want to use.
                var array = toRemove.ToArray();
                for (int i = 0; i < array.Length; i++)
                {
                    var comp = array[i];
                    GameObject.Destroy(comp);
                }
            }
        }