/// <summary>
        /// マテリアルプリセットの適用
        /// </summary>
        public static void ApplyPreset(GameObject gameObject, ShaderPresetData preset, Material material)
        {
            if (gameObject == null)
            {
                return;
            }

            var ps = gameObject.GetComponent <ParticleSystem>();

            if (ps == null)
            {
                return;
            }

            var psr = gameObject.GetComponent <ParticleSystemRenderer>();

            if (psr == null)
            {
                return;
            }
            psr.material = material;

            bool needRestart = ps.isPlaying;

            ps.Stop();

            Undo.RegisterFullObjectHierarchyUndo(gameObject, "Apply Effect Material Preset");
            ApplyPresetCustomData(ps, preset);
            ApplyPresetVertexStream(psr, preset);

            if (needRestart)
            {
                ps.Play();
            }
        }
        private static void ApplyPresetCustomData(GameObject gameObject, ShaderPresetData preset)
        {
            var ps = gameObject.GetComponent <ParticleSystem>();

            if (ps == null)
            {
                return;
            }

            CustomDataUtility.SetCustomData(ps, preset);
        }
        private static void ApplyPresetVertexStream(GameObject gameObject, ShaderPresetData preset)
        {
            var psr = gameObject.GetComponent <ParticleSystemRenderer>();

            if (psr == null)
            {
                return;
            }

            CustomDataUtility.SetVertexStream(psr, preset);
        }
        /// <summary>
        /// CustomDataの設定
        /// </summary>
        public static void SetCustomData(ParticleSystem ps, ShaderPresetData param)
        {
            var custom = ps.customData;

            custom.enabled = true;

            if (param.Custom1Count > 0)
            {
                custom.SetMode(ParticleSystemCustomData.Custom1, ParticleSystemCustomDataMode.Vector);
                custom.SetVectorComponentCount(ParticleSystemCustomData.Custom1, param.Custom1Count);
            }
            else
            {
                custom.SetMode(ParticleSystemCustomData.Custom2, ParticleSystemCustomDataMode.Disabled);
            }

            if (param.Custom2Count > 0)
            {
                custom.SetMode(ParticleSystemCustomData.Custom2, ParticleSystemCustomDataMode.Vector);
                custom.SetVectorComponentCount(ParticleSystemCustomData.Custom2, param.Custom2Count);
            }
            else
            {
                custom.SetMode(ParticleSystemCustomData.Custom2, ParticleSystemCustomDataMode.Disabled);
            }

            var serializedObject = new SerializedObject(ps);

            for (int i = 0; i < param.Custom1Count; i++)
            {
                int floatIndex = i;
                // custom.SetVector(ParticleSystemCustomData.Custom1, i, param.GetFloatValue(floatIndex).MinMaxCurve);
                var customData = serializedObject.FindProperty(propertyName[i]);
                customData.stringValue = param.GetFloatValue(floatIndex).Name;
            }

            for (int i = 0; i < param.Custom2Count; i++)
            {
                int floatIndex = i + 4;
                // custom.SetVector(ParticleSystemCustomData.Custom2, i, param.GetFloatValue(floatIndex).MinMaxCurve);
                var customData = serializedObject.FindProperty(propertyName[floatIndex]);
                customData.stringValue = param.GetFloatValue(floatIndex).Name;
            }

            // 変更の適用
            serializedObject.ApplyModifiedProperties();
        }
Beispiel #5
0
 /// <summary>
 /// プリセットの選択
 /// </summary>
 private void SelectPreset(ShaderPresetData preset)
 {
     Selection.activeObject = preset;
 }
 private static void ApplyPresetCustomData(ParticleSystem ps, ShaderPresetData preset)
 {
     CustomDataUtility.SetCustomData(ps, preset);
 }
 private static void ApplyPresetVertexStream(ParticleSystemRenderer psr, ShaderPresetData preset)
 {
     CustomDataUtility.SetVertexStream(psr, preset);
 }
 /// <summary>
 /// VertexStreamの設定
 /// </summary>
 public static void SetVertexStream(ParticleSystemRenderer psr, ShaderPresetData param)
 {
     psr.SetActiveVertexStreams(param.VertexStreams.ToList());
 }