private void OnAddLayer(ReorderableList list)
        {
            var layer = new OutlineLayer();

            Undo.RecordObject(_layers, "Add Layer");
            EditorUtility.SetDirty(_layers);

            _layers.Add(layer);
        }
Beispiel #2
0
        /// <summary>
        /// Adds the <see cref="GameObject"/> passed to the specified outline layer. Creates the layer if needed.
        /// </summary>
        /// <param name="go">The <see cref="GameObject"/> to add and render outline for.</param>
        /// <seealso cref="AddGameObject(GameObject)"/>
        public void AddGameObject(GameObject go, int layerIndex)
        {
            if (layerIndex < 0)
            {
                throw new ArgumentOutOfRangeException("layerIndex");
            }

            CreateLayersIfNeeded();

            while (_outlineLayers.Count <= layerIndex)
            {
                _outlineLayers.Add(new OutlineLayer());
            }

            _outlineLayers[layerIndex].Add(go);
        }
Beispiel #3
0
        public void Add_FiltersRenderesByLayer()
        {
            var go     = new GameObject("r1", typeof(MeshRenderer));
            var go2    = new GameObject("r2", typeof(MeshRenderer));
            var layers = new OutlineLayerCollection();

            layers.IgnoreLayerMask = 1 << LayerMask.NameToLayer("TransparentFX");
            layers.Add(_layer);

            go2.layer = LayerMask.NameToLayer("TransparentFX");
            go2.transform.SetParent(go.transform, false);

            _layer.Add(go);
            _layer.TryGetRenderers(go, out var r);

            Assert.AreEqual(1, r.Count);
            Assert.IsTrue(r.Contains(go.GetComponent <Renderer>()));
            Assert.IsFalse(r.Contains(go2.GetComponent <Renderer>()));
        }
 public void Add_ThrowsIfArgumentIsNull()
 {
     Assert.Throws <ArgumentNullException>(() => _layerCollection.Add(null));
 }
Beispiel #5
0
        public override void OnInspectorGUI()
        {
            base.OnInspectorGUI();

            EditorGUI.BeginChangeCheck();

            var removeLayer = -1;

            // 1) Layers list.
            if (_layers.Count > 0)
            {
                for (var i = 0; i < _layers.Count; i++)
                {
                    EditorGUILayout.Space();
                    var rect = EditorGUILayout.BeginHorizontal();
                    EditorGUILayout.PrefixLabel("Layer #" + i.ToString());

                    GUILayout.FlexibleSpace();

                    if (GUILayout.Button("Remove", _layerButtonStyle))
                    {
                        removeLayer = i;
                    }

                    EditorGUILayout.EndHorizontal();
                    EditorGUILayout.Space();

                    rect.xMin -= 2;
                    rect.xMax += 2;
                    rect.yMin -= 2;
                    rect.yMax += 2;

                    GUI.Box(rect, GUIContent.none);

                    OutlineEditorUtility.Render(_layers[i], _layers);
                }
            }
            else
            {
                EditorGUILayout.HelpBox("The layer collection is empty.", MessageType.Info, true);
            }

            // Add/remove processing.
            OutlineEditorUtility.RenderDivider(Color.gray);
            EditorGUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();

            if (GUILayout.Button("Add New", _layerButtonStyle))
            {
                Undo.RecordObject(_layers, "Add Layer");
                _layers.Add(new OutlineLayer());
            }

            if (GUILayout.Button("Remove All", _layerButtonStyle))
            {
                Undo.RecordObject(_layers, "Remove All Layers");
                _layers.Clear();
            }

            if (removeLayer >= 0)
            {
                Undo.RecordObject(_layers, "Remove Layer");
                _layers.RemoveAt(removeLayer);
            }

            EditorGUILayout.EndHorizontal();

            if (EditorGUI.EndChangeCheck())
            {
                EditorUtility.SetDirty(_layers);
            }
        }
Beispiel #6
0
        public override void OnInspectorGUI()
        {
            base.OnInspectorGUI();

            EditorGUI.BeginChangeCheck();

            var removeLayer = -1;

            // 1) Layers list.
            if (_layers.Count > 0)
            {
                for (var i = 0; i < _layers.Count; i++)
                {
                    EditorGUILayout.Space();

                    var rect    = EditorGUILayout.BeginHorizontal();
                    var enabled = EditorGUILayout.ToggleLeft("Layer #" + i.ToString(), _layers[i].Enabled);

                    if (enabled != _layers[i].Enabled)
                    {
                        if (enabled)
                        {
                            Undo.RecordObject(_layers, "Enable Layer");
                        }
                        else
                        {
                            Undo.RecordObject(_layers, "Disable Layer");
                        }

                        _layers[i].Enabled = enabled;
                    }

                    GUILayout.FlexibleSpace();

                    if (GUILayout.Button("Remove", _layerButtonStyle))
                    {
                        removeLayer = i;
                    }

                    EditorGUILayout.EndHorizontal();
                    EditorGUILayout.Space();

                    rect.xMin -= 2;
                    rect.xMax += 2;
                    rect.yMin -= 2;
                    rect.yMax += 2;

                    GUI.Box(rect, GUIContent.none);

                    var name = EditorGUILayout.TextField("Layer Name", _layers[i].NameTag);

                    if (name != _layers[i].NameTag)
                    {
                        Undo.RecordObject(_layers, "Set Layer Name");
                        _layers[i].NameTag = name;
                    }

                    var priority = EditorGUILayout.IntField("Layer Priority", _layers[i].Priority);

                    if (priority != _layers[i].Priority)
                    {
                        Undo.RecordObject(_layers, "Set Layer Priority");
                        _layers[i].Priority = priority;
                    }

                    OutlineEditorUtility.Render(_layers[i], _layers);
                }
            }
            else
            {
                EditorGUILayout.HelpBox("The layer collection is empty.", MessageType.Info, true);
            }

            // Add/remove processing.
            OutlineEditorUtility.RenderDivider(Color.gray);
            EditorGUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();

            if (GUILayout.Button("Add New", _layerButtonStyle))
            {
                Undo.RecordObject(_layers, "Add Layer");
                _layers.Add(new OutlineLayer());
            }

            if (GUILayout.Button("Remove All", _layerButtonStyle))
            {
                Undo.RecordObject(_layers, "Remove All Layers");
                _layers.Clear();
            }

            if (removeLayer >= 0)
            {
                Undo.RecordObject(_layers, "Remove Layer");
                _layers.RemoveAt(removeLayer);
            }

            EditorGUILayout.EndHorizontal();

            if (EditorGUI.EndChangeCheck())
            {
                EditorUtility.SetDirty(_layers);
            }
        }