Exemple #1
0
        public bool Append(ElementSource source)
        {
            if (source != null && string.IsNullOrEmpty(source.path) == false)
            {
                string[] elementNames = source.path.Split('/');
                string   elementName;
                string   path    = string.Empty;
                Element  element = null;
                Element  parent;

                for (int i0 = 0; i0 < elementNames.Length; ++i0)
                {
                    elementName = elementNames[i0];

                    if (string.IsNullOrEmpty(path) == false)
                    {
                        path += "/";
                    }
                    path  += elementName;
                    parent = element;

                    if (registered.TryGetValue(path, out element) == false)
                    {
                        if (i0 == elementNames.Length - 1)
                        {
                            element = Element.Create(source);
                        }
                        else
                        {
                            element = Element.Create(path);
                        }
                        if (element == null)
                        {
                            return(false);
                        }
                        else
                        {
                            if (parent != null)
                            {
                                parent.Add(element);
                            }
                            if (i0 == 0)
                            {
                                rootElements.Add(element);
                            }
                            registered.Add(path, element);
                        }
                    }
                }
                return(true);
            }
            return(false);
        }
Exemple #2
0
        public static Element Create(ElementSource source)
        {
            if (source is ElementComponentSource component)
            {
                var element = new Element();
                element.id        = component.path.GetHashCode();
                element.name      = component.name;
                element.extension = string.Empty;
                element.path      = component.path;
                element.guid      = string.Empty;
                element.directory = false;
                element.reference = component.reference;
                element.type      = AssetType.kComponent;
                element.localId   = component.localId;
                element.findPath  = component.findPath;

                var content = EditorGUIUtility.ObjectContent(null, component.type);
                element.icon = content.image as Texture2D;

                return(element);
            }
            return(Create(source.path, source.reference));
        }