Пример #1
0
        private string GetNewPrefabName <T>(string prefix) where T : Component
        {
            var dict = TableComponent.GetComponentsInChildren <T>()
                       .ToDictionary(component => component.name.ToLower(), component => component);

            var n = 0;

            do
            {
                var elementName = $"{prefix}{++n}";
                if (!dict.ContainsKey(elementName.ToLower()))
                {
                    return(elementName);
                }
            } while (true);
        }
Пример #2
0
        private IEnumerable <Texture> GetReferenced()
        {
            var referenced = new HashSet <Texture>();

            foreach (var mr in TableComponent.GetComponentsInChildren <MeshRenderer>())
            {
                if (!mr.sharedMaterial)
                {
                    continue;
                }
                var mainTex   = mr.sharedMaterial.mainTexture;
                var normalTex = mr.sharedMaterial.GetTexture(RenderPipeline.Current.MaterialConverter.NormalMapProperty);
                if (mainTex != null && !referenced.Contains(mainTex))
                {
                    referenced.Add(mainTex);
                }
                if (normalTex != null && !referenced.Contains(normalTex))
                {
                    referenced.Add(normalTex);
                }
            }
            return(referenced);
        }
Пример #3
0
        private void DevicePicker(Rect pos, SerializedProperty property, TypeRestrictionAttribute attrib, Component comp, UnityEngine.Object field, TableComponent ta)
        {
            // retrieve selected reference
            MonoBehaviour obj = null;

            if (_component == null)
            {
                if (field != null)
                {
                    obj = ta.GetComponentsInChildren(attrib.Type, true)
                          .FirstOrDefault(s => s == field) as MonoBehaviour;
                    _component = obj;
                }
            }
            else
            {
                obj = _component;
            }

            // render content
            var content = obj == null
                                ? new GUIContent(attrib.NoneLabel)
                                : new GUIContent(obj.name, Icons.ByComponent(obj, IconSize.Small, IconColor.Orange));

            // render drawer
            var id = GUIUtility.GetControlID(FocusType.Keyboard, pos);
            var objectFieldButton = GUI.skin.GetStyle("ObjectFieldButton");
            var suffixButtonPos   = new Rect(pos.xMax - 19f, pos.y + 1, 19f, pos.height - 2);

            EditorGUIUtility.SetIconSize(new Vector2(12f, 12f));

            // handle click
            if (Event.current.type == EventType.MouseDown && pos.Contains(Event.current.mousePosition))
            {
                // click on ping
                if (obj != null && !suffixButtonPos.Contains(Event.current.mousePosition))
                {
                    EditorGUIUtility.PingObject(obj.gameObject);

                    // click on picker
                }
                else
                {
                    _itemPickDropdownState ??= new AdvancedDropdownState();

                    var dropdown = new ItemSearchableDropdownUntyped(
                        attrib.Type,
                        _itemPickDropdownState,
                        ta,
                        attrib.PickerLabel,
                        item => {
                        switch (item)
                        {
                        case null:
                            _component = null;
                            property.objectReferenceValue = null;
                            break;

                        case MonoBehaviour mb:
                            _component = mb;
                            property.objectReferenceValue = mb;
                            break;
                        }
                        property.serializedObject.ApplyModifiedProperties();
                        if (comp is IMainRenderableComponent renderable)
                        {
                            if (attrib.RebuildMeshes)
                            {
                                renderable.RebuildMeshes();
                            }
                            if (attrib.UpdateTransforms)
                            {
                                renderable.UpdateTransforms();
                            }
                        }
                    }
                        );
                    dropdown.Show(pos);
                }
            }
            if (Event.current.type == EventType.Repaint)
            {
                EditorStyles.objectField.Draw(pos, content, id, DragAndDrop.activeControlID == id, pos.Contains(Event.current.mousePosition));
                objectFieldButton.Draw(suffixButtonPos, GUIContent.none, id, DragAndDrop.activeControlID == id, suffixButtonPos.Contains(Event.current.mousePosition));
            }
        }