Exemple #1
0
        internal void Add(ComponentTypeDesc desc)
        {
            var group = Groups.Find(delegate(GroupDesc groupDesc) { return(groupDesc.Name == desc.Group); });

            if (null == group)
            {
                group = new GroupDesc(desc.Group);
                Groups.Add(group);
            }
            group.Add(desc);
        }
Exemple #2
0
        /// <summary>
        /// Creates a child of the selected component descriptor
        /// </summary>
        /// <param name="desc"></param>
        /// <param name="selectCreatedControl">Should the newly created control be selected, or the selection should be as it is (container)</param>
        private static void CreateChild(ComponentTypeDesc desc, bool selectCreatedControl)
        {
            //Debug.Log("CreateChild: " + desc);
            GameObject go = new GameObject(desc.Name);

            go.transform.parent        = Selection.activeTransform;
            go.transform.localPosition = Vector3.zero;

            ComponentAdapter adapter = (ComponentAdapter)go.AddComponent(desc.Type);

            // in in play mode, start monitoring this component because we need to setup immediatelly
            if (EditorApplication.isPlaying)
            {
                PersistenceManager.Instance.Watch(adapter);
            }

            // setup default values
            SetupDefaults(Event.current.alt, adapter);

            /**
             * When not in play mode, we are adding the adapter directly to a child colection
             * (no play mode persistance)
             * */
            if (null != EditorState.Instance.GroupAdapter && !Application.isPlaying)
            {
                //Debug.Log("Adding child in edit mode: " + adapter);
                EditorState.Instance.GroupAdapter.AddChild(adapter, true);
                //ParentChildLinker.Instance.Link(EditorState.ContainerAdapter, adapter);
                //ParentChildLinker.Instance.Process(); // process immediately
            }

            // the following should definitelly be after setting the active object:
            if (selectCreatedControl)
            {
                Selection.activeGameObject = go;
            }

            // hierarchy change mechanism should do the rest
        }
Exemple #3
0
 internal void Add(ComponentTypeDesc desc)
 {
     _components.Add(desc);
 }
Exemple #4
0
 internal void Add(ComponentTypeDesc desc)
 {
     _components.Add(desc);
 }
Exemple #5
0
        /// <summary>
        /// Creates a child of the selected component descriptor
        /// </summary>
        /// <param name="desc"></param>
        /// <param name="selectCreatedControl">Should the newly created control be selected, or the selection should be as it is (container)</param>
        private static void CreateChild(ComponentTypeDesc desc, bool selectCreatedControl)
        {
            //Debug.Log("CreateChild: " + desc);
            GameObject go = new GameObject(desc.Name);

            go.transform.parent = Selection.activeTransform;
            go.transform.localPosition = Vector3.zero;

            ComponentAdapter adapter = (ComponentAdapter)go.AddComponent(desc.Type);

            // in in play mode, start monitoring this component because we need to setup immediatelly
            if (EditorApplication.isPlaying)
                PersistenceManager.Instance.Watch(adapter);

            // setup default values
            SetupDefaults(Event.current.alt, adapter);
            
            /**
            * When not in play mode, we are adding the adapter directly to a child colection
            * (no play mode persistance)
            * */
            if (null != EditorState.Instance.GroupAdapter && !Application.isPlaying)
            {
                //Debug.Log("Adding child in edit mode: " + adapter);
                EditorState.Instance.GroupAdapter.AddChild(adapter, true);
                //ParentChildLinker.Instance.Link(EditorState.ContainerAdapter, adapter);
                //ParentChildLinker.Instance.Process(); // process immediately
            }

            // the following should definitelly be after setting the active object:
            if (selectCreatedControl) {
                Selection.activeGameObject = go;
            }

            // hierarchy change mechanism should do the rest
        }
Exemple #6
0
 internal void Add(ComponentTypeDesc desc)
 {
     var group = Groups.Find(delegate(GroupDesc groupDesc) { return groupDesc.Name == desc.Group; });
     if (null == group)
     {
         group = new GroupDesc(desc.Group);
         Groups.Add(group);
     }
     group.Add(desc);
 }
        /// <summary>
        /// Looks for all descriptor classes in running assemblies via reflection
        /// </summary>
        public static void Initialize()
        {
            //Debug.Log("Initialize");

            var toolbox = Toolbox.Instance;

            toolbox.Clear();

            /**
             * 1. Get all types for all loaded assemblies
             * This is done only when componet tab expanded, so is no performance issue
             * */
            List <Type> types = GuiReflector.GetAllLoadedTypes();

            foreach (Type type in types)
            {
                if (type.IsClass)
                {
                    if (type.IsSubclassOf(typeof(ComponentAdapter)))
                    {
                        string icon      = string.Empty;
                        string label     = string.Empty;
                        string groupName = string.Empty;
                        string tooltip   = string.Empty;

                        //ToolboxAttribute[] toolboxAttributes = (ToolboxAttribute[])type.GetCustomAttributes(typeof(ToolboxAttribute), true);
                        var toolboxAttributes = Core.Reflection.CoreReflector.GetClassAttributes <ToolboxAttribute>(type);

                        if (toolboxAttributes.Count > 0)
                        {
                            var attr = toolboxAttributes[0];
                            label     = attr.Label;
                            icon      = attr.Icon;
                            tooltip   = attr.Tooltip;
                            groupName = attr.Group;
                        }

                        Texture iconTexture = null;

                        if (!string.IsNullOrEmpty(icon))
                        {
                            iconTexture = (Texture)Resources.Load(icon);
                        }

                        if (string.IsNullOrEmpty(label))
                        {
                            label = type.Name.Replace("Adapter", string.Empty);
                        }

                        var desc = new ComponentTypeDesc(label, type, iconTexture, tooltip);

                        if (type.IsAbstract)
                        {
                            continue; // skip abstract classes (SkinnableComponentAdapter etc.)
                        }

                        /**
                         * 1. Stage
                         * */
                        if (type == typeof(StageAdapter))
                        {
                            Toolbox.Instance.StageContent = desc.GetContent();
                            continue;
                        }

                        /**
                         * 2. Named group
                         * */
                        if (!string.IsNullOrEmpty(groupName))
                        {
                            desc.Group = groupName;
                            toolbox.Add(desc);
                            continue;
                        }

                        /**
                         * 3. Group
                         * */
                        //if (type == typeof (GroupAdapter) || type.IsSubclassOf(typeof (GroupAdapter)))
                        if (typeof(GroupAdapter).IsAssignableFrom(type))
                        {
                            desc.Group = "Containers";
                            toolbox.Add(desc);
                            continue;
                        }

                        /**
                         * 4. Component
                         * */
                        desc.Group = "Components";
                        toolbox.Add(desc);
                    }
                }
            }

            toolbox.Process();
        }
        /// <summary>
        /// Looks for all descriptor classes in running assemblies via reflection
        /// </summary>
        public static void Initialize()
        {
            //Debug.Log("Initialize");

            var toolbox = Toolbox.Instance;

            toolbox.Clear();

            /**
             * 1. Get all types for all loaded assemblies
             * This is done only when componet tab expanded, so is no performance issue
             * */
            List<Type> types = GuiReflector.GetAllLoadedTypes();

            foreach (Type type in types)
            {
                if (type.IsClass)
                {
                    if (type.IsSubclassOf(typeof(ComponentAdapter)))
                    {
                        string icon = string.Empty;
                        string label = string.Empty;
                        string groupName = string.Empty;
                        string tooltip = string.Empty;
                        
                        //ToolboxAttribute[] toolboxAttributes = (ToolboxAttribute[])type.GetCustomAttributes(typeof(ToolboxAttribute), true);
                        var toolboxAttributes = Core.Reflection.CoreReflector.GetClassAttributes<ToolboxAttribute>(type);

                        if (toolboxAttributes.Count > 0)
                        {
                            var attr = toolboxAttributes[0];
                            label = attr.Label;
                            icon = attr.Icon;
                            tooltip = attr.Tooltip;
                            groupName = attr.Group;
                        }

                        Texture iconTexture = null;

                        if (!string.IsNullOrEmpty(icon))
                            iconTexture = (Texture)Resources.Load(icon);

                        if (string.IsNullOrEmpty(label))
                            label = type.Name.Replace("Adapter", string.Empty);

                        var desc = new ComponentTypeDesc(label, type, iconTexture, tooltip);

                        if (type.IsAbstract)
                            continue; // skip abstract classes (SkinnableComponentAdapter etc.)

                        /**
                         * 1. Stage
                         * */
                        if (type == typeof(StageAdapter))
                        {
                            Toolbox.Instance.StageContent = desc.GetContent();
                            continue;
                        }

                        /**
                         * 2. Named group
                         * */
                        if (!string.IsNullOrEmpty(groupName))
                        {
                            desc.Group = groupName;
                            toolbox.Add(desc);
                            continue;
                        }

                        /**
                         * 3. Group
                         * */
                        //if (type == typeof (GroupAdapter) || type.IsSubclassOf(typeof (GroupAdapter)))
                        if (typeof(GroupAdapter).IsAssignableFrom(type))
                        {
                            desc.Group = "Containers";
                            toolbox.Add(desc);
                            continue;
                        }

                        /**
                         * 4. Component
                         * */
                        desc.Group = "Components";
                        toolbox.Add(desc);
                    }
                }
            }

            toolbox.Process();
        }