Пример #1
0
        public static ParticleSystemSettings Load(TiXml.TiXmlElement xmlNode)
        {
            ParticleSystemSettings config = new ParticleSystemSettings();

            if (xmlNode != null)
            {
                config.particleName             = StrParser.ParseStr(xmlNode.Attribute(M.Attri_ParticleName));
                config.castKeyFrame             = StrParser.ParseStr(xmlNode.Attribute(M.Attri_CastKeyFrame));
                config.placementType            = StrParser.ParseDecInt(xmlNode.Attribute(M.Attri_PlacementType), CreateObjectPlacementType.AtSource);
                config.facingType               = StrParser.ParseDecInt(xmlNode.Attribute(M.Attri_FacingType), CreateObjectFacingType.ToTarget);
                config.placementBoneName        = StrParser.ParseStr(xmlNode.Attribute(M.Attri_BoneName));
                config.projectileTargetBoneName = StrParser.ParseStr(xmlNode.Attribute(M.Attri_ProjectileTargetBoneName));
                config.attachmentZOffset        = StrParser.ParseFloat(xmlNode.Attribute(M.Attri_AttachmentZOffset), 0);

                if (xmlNode.Attribute(M.Attri_PlacementRelativePosition) == null)
                {
                    config.placementLocalRelativePosition = Vector3.zero;
                }
                else
                {
                    config.placementLocalRelativePosition = Vector3.Parse(xmlNode.Attribute(M.Attri_PlacementRelativePosition));
                }

                if (xmlNode.Attribute(M.Attri_PlacementWroldRelativePosition) == null)
                {
                    config.placementWorldRelativePosition = Vector3.zero;
                }
                else
                {
                    config.placementWorldRelativePosition = Vector3.Parse(xmlNode.Attribute(M.Attri_PlacementWroldRelativePosition));
                }

                if (xmlNode.Attribute(M.Attri_PlacementRelativeEuler) == null)
                {
                    config.placementRelativeEuler = Vector3.zero;
                }
                else
                {
                    config.placementRelativeEuler = Vector3.Parse(xmlNode.Attribute(M.Attri_PlacementRelativeEuler));
                }

                config.inheritHostModelScalingWhenAttached = StrParser.ParseBool(xmlNode.Attribute(M.Attri_InheritHostModelScalingWhenAttached), true);
                config.maintainPosition         = StrParser.ParseBool(xmlNode.Attribute(M.Attri_MaintainPosition), false);
                config.maintainFacing           = StrParser.ParseBool(xmlNode.Attribute(M.Attri_MaintainFacing), false);
                config.removeOnUnApply          = StrParser.ParseBool(xmlNode.Attribute(M.Attri_RemoveOnUnApply), false);
                config.useLocalRelativePosition = StrParser.ParseBool(xmlNode.Attribute(M.Attri_UseLocalRelativePosition), true);

                config.isProjectileEffect      = StrParser.ParseBool(xmlNode.Attribute(M.Attri_IsProjectile));
                config.projectileSpeed         = StrParser.ParseFloat(xmlNode.Attribute(M.Attri_ProjectileSpeed));
                config.projectileStartBoneName = StrParser.ParseStr(xmlNode.Attribute(M.Attri_ProjectileStartBoneName));
                config.projectileParticleName  = StrParser.ParseStr(xmlNode.Attribute(M.Attri_ProjectileParticleName));
            }

            return(config);
        }
Пример #2
0
    public void PlayAbilityPfx(string xmlParameter, GameObject pfxParentObj)
    {
        Combat.ParticleSystemSettings settings = Combat.ParticleSystemSettings.Load(xmlParameter);

        var pfx = FxManager.Instance.PlayFX(settings.particleName, pfxParentObj, true, false, false, false);

        if (pfx == null)
        {
            return;
        }

        if (settings.maintainPosition && settings.maintainFacing)
        {
            pfx.Root.parent = null;
        }

        //缩放
        pfx.Root.parent = null;

        // 不缩放粒子,缩放了也没用,反而改变相对位置
        //pfx.Root.localScale = new Vector3(
        //pfxParentObj.transform.localScale.x == 0 ? 0 : 1 / pfxParentObj.transform.lossyScale.x,
        //pfxParentObj.transform.localScale.y == 0 ? 0 : 1 / pfxParentObj.transform.lossyScale.y,
        //pfxParentObj.transform.localScale.z == 0 ? 0 : 1 / pfxParentObj.transform.lossyScale.z);

        pfx.Root.localScale = Vector3.one;
        pfx.Root.parent     = pfxParentObj.transform;

        //朝向
        pfx.Root.forward        = pfxParentObj.transform.forward;
        pfx.Root.localPosition  = Vector3.zero;
        pfx.Root.localPosition += settings.placementLocalRelativePosition;
        pfx.Root.localPosition += (UnityEngine.Camera.main.transform.position - pfx.Root.position).normalized * settings.attachmentZOffset;

        //pfx.Root.localEulerAngles += settings.placementRelativeEuler;
        if (settings.placementRelativeEuler.IsEqual(Vector3.zero) == false)
        {
            pfx.Root.localEulerAngles = settings.placementRelativeEuler;
        }

        var pc = pfx.GetComponent <Combat.ParticleAbilityParticleController>();

        if (pc == null)
        {
            pc = pfx.gameObject.AddComponent <Combat.ParticleAbilityParticleController>();
        }

        pc.Set(pfx.Root.gameObject, settings, false);

        FxManager.Instance.StartFx(pfx);
    }
Пример #3
0
 public static string GetXml(ParticleSystemSettings settings, string customNodeName = "")
 {
     return(GetXmlNode(settings, customNodeName).ToString());
 }
Пример #4
0
        public static System.Security.SecurityElement GetXmlNode(ParticleSystemSettings settings, string customNodeName = "")
        {
            Mono.Xml.SecurityParser parser = new Mono.Xml.SecurityParser();
            Mono.Xml.SmallXmlParser.AttrListImpl attrList = new Mono.Xml.SmallXmlParser.AttrListImpl();

            if (!string.IsNullOrEmpty(settings.particleName))
            {
                attrList.Add(M.Attri_ParticleName, settings.particleName);
            }

            if (!string.IsNullOrEmpty(settings.castKeyFrame))
            {
                attrList.Add(M.Attri_CastKeyFrame, settings.castKeyFrame);
            }

            if (settings.placementType != CreateObjectPlacementType.AtSource)
            {
                attrList.Add(M.Attri_PlacementType, settings.placementType.ToString());
            }

            if (settings.facingType != CreateObjectFacingType.ToTarget)
            {
                attrList.Add(M.Attri_FacingType, settings.facingType.ToString());
            }

            if (!string.IsNullOrEmpty(settings.placementBoneName))
            {
                attrList.Add(M.Attri_BoneName, settings.placementBoneName);
            }
            if (settings.attachmentZOffset != 0)
            {
                attrList.Add(M.Attri_AttachmentZOffset, settings.attachmentZOffset.ToString());
            }

            if (settings.placementLocalRelativePosition.IsEqual(Vector3.zero) == false)
            {
                attrList.Add(M.Attri_PlacementRelativePosition, settings.placementLocalRelativePosition.ToString());
            }

            if (settings.placementWorldRelativePosition.IsEqual(Vector3.zero) == false)
            {
                attrList.Add(M.Attri_PlacementWroldRelativePosition, settings.placementWorldRelativePosition.ToString());
            }

            if (settings.placementRelativeEuler.IsEqual(Vector3.zero) == false)
            {
                attrList.Add(M.Attri_PlacementRelativeEuler, settings.placementRelativeEuler.ToString());
            }

            if (settings.inheritHostModelScalingWhenAttached == false)
            {
                attrList.Add(M.Attri_InheritHostModelScalingWhenAttached, settings.inheritHostModelScalingWhenAttached.ToString());
            }

            if (settings.maintainPosition)
            {
                attrList.Add(M.Attri_MaintainPosition, settings.maintainPosition.ToString());
            }

            if (settings.maintainFacing)
            {
                attrList.Add(M.Attri_MaintainFacing, settings.maintainFacing.ToString());
            }

            if (settings.removeOnUnApply)
            {
                attrList.Add(M.Attri_RemoveOnUnApply, settings.removeOnUnApply.ToString());
            }

            if (settings.useLocalRelativePosition == false)
            {
                attrList.Add(M.Attri_UseLocalRelativePosition, settings.useLocalRelativePosition.ToString());
            }

            if (settings.isProjectileEffect)
            {
                attrList.Add(M.Attri_IsProjectile, settings.isProjectileEffect.ToString());
            }

            if (settings.projectileSpeed != 1)
            {
                attrList.Add(M.Attri_ProjectileSpeed, settings.projectileSpeed.ToString());
            }

            if (!string.IsNullOrEmpty(settings.projectileStartBoneName))
            {
                attrList.Add(M.Attri_ProjectileStartBoneName, settings.projectileStartBoneName);
            }

            if (!string.IsNullOrEmpty(settings.projectileTargetBoneName))
            {
                attrList.Add(M.Attri_ProjectileTargetBoneName, settings.projectileTargetBoneName);
            }

            if (!string.IsNullOrEmpty(settings.projectileParticleName))
            {
                attrList.Add(M.Attri_ProjectileParticleName, settings.projectileParticleName);
            }

            if (string.IsNullOrEmpty(customNodeName))
            {
                parser.OnStartElement(M.Node, attrList);
            }
            else
            {
                parser.OnStartElement(customNodeName, attrList);
            }


            parser.OnEndElement("");

            return(parser.ToXml());
        }