コード例 #1
0
        private void DrawElements(Rect originalRect, ComponentToCopy component)
        {
            Rect rect = new Rect(originalRect);

            bool isRectTransform = component.Component is RectTransform;
            bool isTransform     = component.Component is Transform || isRectTransform;

            if (isTransform)
            {
                rect.x += 14;
                rect.y -= 2;
            }

            //Enable/Disable Toggle Handler
            rect.x    += 5;
            rect.y    += 2;
            rect.width = rect.height = 20;
            component.IsCopyComponent = EditorGUI.Toggle(rect, component.IsCopyComponent);

            //  Component Icon
            rect.x += 20;

            Texture componentIcon = EditorGUIUtility.ObjectContent(null, component.Component.GetType()).image;

            EditorGUI.LabelField(rect, new GUIContent(componentIcon));


            //  Component name.
            rect.x += 20;
            //rect.y = originalRect.y;
            rect.width = originalRect.width - 30;
            EditorGUI.LabelField(rect, component.ComponentName);
        }
コード例 #2
0
        //  -- Setup the lists of components.
        private void InitializeList()
        {
            UpdateComponentList();
            m_SrcComponents.RemoveAt(0);
            //  -- Create the ReorderableList
            m_List = new ReorderableList(m_SrcComponents, typeof(ComponentToCopy), false, true, false, false);

            //  Draw ReorderableList Header.
            m_List.drawHeaderCallback = (Rect rect) => {
                m_SrcTransform = new ComponentToCopy(true, m_SrcObject.GetComponents <Component>()[0]);
                DrawElements(rect, m_SrcTransform);
            };

            //  Draw ReorderableList Element
            m_List.drawElementCallback = (Rect rect, int index, bool isActive, bool isFocused) => {
                DrawElements(rect, m_SrcComponents[index]);
            };

            //  What happens when the lists changes.
            m_List.onReorderCallback = (ReorderableList internalList) => {
                //Move Down
                for (int i = 0; i < m_SrcComponents.Count; i++)
                {
                    int listIndex  = internalList.list.IndexOf(m_SrcComponents[i].Component);
                    int difference = listIndex - i;
                    if (difference > 0)
                    {
                        for (int j = 0; j < Mathf.Abs(difference); j++)
                        {
                            ComponentUtility.MoveComponentDown(m_SrcComponents[i].Component);
                        }
                    }
                }
                //Move Up
                UpdateComponentList();
                m_SrcComponents.RemoveAt(0);
                for (int i = m_SrcComponents.Count - 1; i >= 0; i--)
                {
                    int listIndex  = internalList.list.IndexOf(m_SrcComponents[i].Component);
                    int difference = listIndex - i;
                    if (difference < 0)
                    {
                        for (int j = 0; j < Mathf.Abs(difference); j++)
                        {
                            ComponentUtility.MoveComponentUp(m_SrcComponents[i].Component);
                        }
                    }
                }
            };
        }
コード例 #3
0
        private void UpdateComponentList()
        {
            if (m_SrcObject != null)
            {
                //  -- Go through the source object list of components.
                for (int index = 0; index < m_SrcObject.GetComponents <Component>().Length; index++)
                {
                    //  -- Check to see if list contains the component.  Otherwise it will keep on adding.
                    Component       srcComponent       = m_SrcObject.GetComponents <Component>()[index];
                    ComponentToCopy srcComponentToCopy = new ComponentToCopy(true, srcComponent);

                    if (m_SrcComponents.Contains(srcComponentToCopy) == false)
                    {
                        m_SrcComponents.Add(srcComponentToCopy);
                    }
                }
            }
        }