Пример #1
0
            public static void AddMenu(GenericMenu menu, SerializedProperty sp, AnimatedPropertiesEditor property, bool add)
            {
                if (add && s_ActiveNames.Contains(property.name))
                {
                    return;
                }

                menu.AddItem(new GUIContent(string.Format("{0} ({1})", property.name, property.type)), s_ActiveNames.Contains(property.name), () =>
                {
                    var index = s_ActiveNames.IndexOf(property.name);
                    if (0 <= index)
                    {
                        sp.DeleteArrayElementAtIndex(index);
                    }
                    else
                    {
                        sp.InsertArrayElementAtIndex(sp.arraySize);
                        var p = sp.GetArrayElementAtIndex(sp.arraySize - 1);
                        p.FindPropertyRelative("m_Name").stringValue = property.name;
                        p.FindPropertyRelative("m_Type").intValue    = (int)property.type;
                    }

                    sp.serializedObject.ApplyModifiedProperties();
                });
            }
Пример #2
0
        /// <summary>
        /// Implement this function to make a custom inspector.
        /// </summary>
        public override void OnInspectorGUI()
        {
            serializedObject.Update();

            EditorGUILayout.PropertyField(_spParticleSystem);
            EditorGUI.indentLevel++;
            var ps = _spParticleSystem.objectReferenceValue as ParticleSystem;

            if (ps)
            {
                var pr = ps.GetComponent <ParticleSystemRenderer> ();
                var sp = new SerializedObject(pr).FindProperty("m_Materials");

                EditorGUILayout.PropertyField(sp.GetArrayElementAtIndex(0), s_ContentParticleMaterial);
                EditorGUILayout.PropertyField(sp.GetArrayElementAtIndex(1), s_ContentTrailMaterial);
                sp.serializedObject.ApplyModifiedProperties();

                if (!Application.isPlaying && pr.enabled)
                {
                    EditorGUILayout.HelpBox("ParticleSystemRenderer will be disable on playing.", MessageType.Info);
                }
            }
            EditorGUI.indentLevel--;

            EditorGUI.BeginDisabledGroup(true);
            EditorGUILayout.PropertyField(_spTrailParticle);
            EditorGUI.EndDisabledGroup();

            var current = target as UIParticle;

            EditorGUILayout.PropertyField(_spIgnoreParent);

            EditorGUI.BeginDisabledGroup(!current.isRoot);
            EditorGUILayout.PropertyField(_spScale);
            EditorGUI.EndDisabledGroup();
            EditorGUILayout.PropertyField(_spDontManage);

            // AnimatableProperties
            AnimatedPropertiesEditor.DrawAnimatableProperties(_spAnimatableProperties, current.material);

            current.GetComponentsInChildren <ParticleSystem> (true, s_ParticleSystems);
            if (s_ParticleSystems.Any(x => x.GetComponent <UIParticle> () == null))
            {
                GUILayout.BeginHorizontal();
                EditorGUILayout.HelpBox("There are child ParticleSystems that does not have a UIParticle component.\nAdd UIParticle component to them.", MessageType.Warning);
                GUILayout.BeginVertical();
                if (GUILayout.Button("Fix"))
                {
                    foreach (var p in s_ParticleSystems.Where(x => !x.GetComponent <UIParticle> ()))
                    {
                        p.gameObject.AddComponent <UIParticle> ();
                    }
                }
                GUILayout.EndVertical();
                GUILayout.EndHorizontal();
            }
            s_ParticleSystems.Clear();

            if (current.maskable && current.material && current.material.shader)
            {
                var mat    = current.material;
                var shader = mat.shader;
                foreach (var propName in s_MaskablePropertyNames)
                {
                    if (!mat.HasProperty(propName))
                    {
                        EditorGUILayout.HelpBox(string.Format("Shader {0} doesn't have '{1}' property. This graphic is not maskable.", shader.name, propName), MessageType.Warning);
                        break;
                    }
                }
            }

            serializedObject.ApplyModifiedProperties();
        }
        /// <summary>
        /// Implement this function to make a custom inspector.
        /// </summary>
        public override void OnInspectorGUI()
        {
            var current = target as UIParticle;

            if (current == null)
            {
                return;
            }

            serializedObject.Update();

            // Maskable
            EditorGUILayout.PropertyField(_spMaskable);

            // IgnoreCanvasScaler
            using (var ccs = new EditorGUI.ChangeCheckScope())
            {
                EditorGUILayout.PropertyField(_spIgnoreCanvasScaler);
                if (ccs.changed)
                {
                    foreach (UIParticle p in targets)
                    {
                        p.ignoreCanvasScaler = _spIgnoreCanvasScaler.boolValue;
                    }
                }
            }

            // Scale
            _xyzMode = DrawFloatOrVector3Field(_spScale, _xyzMode);

            // AnimatableProperties
            var mats = current.particles
                       .Where(x => x)
                       .Select(x => x.GetComponent <ParticleSystemRenderer>().sharedMaterial)
                       .Where(x => x)
                       .ToArray();

            // Animated properties
            EditorGUI.BeginChangeCheck();
            AnimatedPropertiesEditor.DrawAnimatableProperties(_spAnimatableProperties, mats);
            if (EditorGUI.EndChangeCheck())
            {
                foreach (UIParticle t in targets)
                {
                    t.SetMaterialDirty();
                }
            }

            // ShrinkByMaterial
            EditorGUILayout.PropertyField(_spShrinkByMaterial);

            // Target ParticleSystems.
            _ro.DoLayoutList();

            serializedObject.ApplyModifiedProperties();

            // Does the shader support UI masks?
            if (current.maskable && current.GetComponentInParent <Mask>())
            {
                foreach (var mat in current.materials)
                {
                    if (!mat || !mat.shader)
                    {
                        continue;
                    }
                    var shader = mat.shader;
                    foreach (var propName in s_MaskablePropertyNames)
                    {
                        if (mat.HasProperty(propName))
                        {
                            continue;
                        }

                        EditorGUILayout.HelpBox(string.Format("Shader '{0}' doesn't have '{1}' property. This graphic cannot be masked.", shader.name, propName), MessageType.Warning);
                        break;
                    }
                }
            }

            // Does the shader support UI masks?

            if (FixButton(current.m_IsTrail, "This UIParticle component should be removed. The UIParticle for trails is no longer needed."))
            {
                DestroyUIParticle(current);
                return;
            }
        }