Ejemplo n.º 1
0
        /// <summary>
        /// Force the component order for the selected instance, using a ComponentOrderList as a template
        /// </summary>
        public static void ForceOrder(U.GameObject instance, ComponentOrderList col)
        {
                        #if UNITY_EDITOR
            if (instance == null)
            {
                EditorUtil.Debug("[SETUtil.CompUtil.Reorder ERROR] null reference.");
                return;
            }

            U.Component[] components = GatherComponents(instance);

            int  cycle           = 0;
            int  ANTI_LOCK_LIMIT = 45;
            bool validOrder      = false;

            do
            {
                for (uint i = 0; i < components.Length - 1; i++)
                {
                    if (components[i].FindOrderIndex(ref col) > components[i + 1].FindOrderIndex(ref col))
                    {
                        UnityEditorInternal.ComponentUtility.MoveComponentDown(components[i]);
                        components = GatherComponents(instance);
                    }
                }
                cycle++;
                validOrder = col.EvaluateOrder(components);
            }while (!validOrder && cycle < ANTI_LOCK_LIMIT);
                        #endif
        }
Ejemplo n.º 2
0
        //private:

        /// <summary>
        /// returns true if all components are in order
        /// </summary>
        private static bool EvaluateOrder(this ComponentOrderList col, U.Component[] components)
        {
            bool valid = true;

            for (uint i = 0; i < components.Length - 1; i++)
            {
                int _currentOrder = components[i].FindOrderIndex(ref col),
                    _nextOrder    = components[i + 1].FindOrderIndex(ref col);
                if (_currentOrder > _nextOrder)
                {
                    valid = false;
                }
            }

            return(valid);
        }
Ejemplo n.º 3
0
        private static int FindOrderIndex(this U.Component comp, ref ComponentOrderList col)
        {
            System.Type _comType = comp.GetType();
            int         _order   = 0;

            if (typeof(iOrderedComponent).IsAssignableFrom(_comType))
            {
                _order = ((iOrderedComponent)comp).OrderIndex();
            }
            else
            {
                _order = col.EvaluateElement(_comType);
            }

            return(_order);
        }