Esempio n. 1
0
        /// <summary>
        /// Initializes this instance.
        /// </summary>
        /// <returns></returns>
        public bool Init()
        {
            _initComplete = false;

            var all = this.GetComponents <MonoBehaviour>();

            foreach (var component in all)
            {
                Register(component);
            }

            var comparer = new FunctionComparer <ComponentInfo>((a, b) => a.name.CompareTo(b.name));

            foreach (var cat in _categories.Values)
            {
                cat.Sort(comparer);
            }

            _initComplete = true;

            if (_firstTime)
            {
                _firstTime = false;
                return(true);
            }

            return(false);
        }
Esempio n. 2
0
        public static IComparer <T> Create <T>(params Func <T, IComparable>[] keyFunctions)
        {
            IComparer <T> comparer = new FunctionComparer <T>(keyFunctions[0]);

            if (keyFunctions.Length == 1)
            {
                return(comparer);
            }

            for (var i = 1; i < keyFunctions.Length; i++)
            {
                comparer = comparer.ThenComparing(keyFunctions[i]);
            }

            return(comparer);
        }
Esempio n. 3
0
        /// <summary>
        /// 判断一个卦画是否由另一个卦画,通过指定的方式变换而来。
        /// Judge whether the object painting is derived from the basis painting,
        /// through the given derivation function.
        /// </summary>
        /// <param name="obj">
        /// 要判断的目标卦画。
        /// The object painting to judge.
        /// </param>
        /// <param name="basis">
        /// 作为判断基础的卦画。
        /// The paintings to be used as the comparing basis.
        /// </param>
        /// <param name="derivationFunction">
        /// 变换过程函数。
        /// The derivation function.
        /// </param>
        /// <returns>
        /// 判断结果。
        /// The result.
        /// </returns>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="basis"/> 或 <paramref name="derivationFunction"/> 或 <paramref name="obj"/> 是 <c>null</c> 。
        /// <paramref name="basis"/> or <paramref name="derivationFunction"/> or <paramref name="obj"/> is <c>null</c>.
        /// </exception>
        public static bool IsDerivedFrom(
            this Core.Painting obj, Core.Painting basis, DerivationFunc derivationFunction)
        {
            if (obj is null)
            {
                throw new ArgumentNullException(nameof(obj));
            }
            if (basis is null)
            {
                throw new ArgumentNullException(nameof(basis));
            }
            if (derivationFunction is null)
            {
                throw new ArgumentNullException(nameof(derivationFunction));
            }
            var functionComparer = new FunctionComparer(derivationFunction);

            return(functionComparer.Compare(basis, obj));
        }
        public bool Init(IEnumerable <ApexComponentMaster.ComponentCandidate> candidates)
        {
            ApexComponentMaster.ComponentInfo     componentInfo;
            ApexComponentMaster.ComponentCategory componentCategory;
            this.Cleanup();
            bool flag = false;
            int  num  = 0;

            foreach (ApexComponentMaster.ComponentCandidate candidate in candidates)
            {
                int  instanceID = candidate.component.GetInstanceID();
                bool flag1      = this._components.TryGetValue(instanceID, out componentInfo);
                if ((candidate.component.hideFlags & HideFlags.HideInInspector) == HideFlags.None && (this._hiddenComponents & 1 << (num & 31)) > 0)
                {
                    MonoBehaviour monoBehaviour = candidate.component;
                    monoBehaviour.hideFlags = monoBehaviour.hideFlags | HideFlags.HideInInspector;
                    flag = true;
                }
                if (!flag1)
                {
                    ApexComponentMaster.ComponentInfo componentInfo1 = new ApexComponentMaster.ComponentInfo()
                    {
                        component = candidate.component,
                        id        = instanceID
                    };
                    int num1 = num;
                    num = num1 + 1;
                    componentInfo1.idx       = num1;
                    componentInfo1.name      = candidate.component.GetType().Name.Replace("Component", string.Empty).ExpandFromPascal();
                    componentInfo1.isVisible = (candidate.component.hideFlags & HideFlags.HideInInspector) == HideFlags.None;
                    componentInfo            = componentInfo1;
                    this._components.Add(instanceID, componentInfo);
                    if (!this._categories.TryGetValue(candidate.categoryName, out componentCategory))
                    {
                        componentCategory = new ApexComponentMaster.ComponentCategory()
                        {
                            name = candidate.categoryName
                        };
                        this._categories.Add(candidate.categoryName, componentCategory);
                    }
                    componentCategory.Add(componentInfo);
                    componentInfo.category = componentCategory;
                }
                else
                {
                    num++;
                    componentInfo.isVisible = (candidate.component.hideFlags & HideFlags.HideInInspector) == HideFlags.None;
                }
            }
            FunctionComparer <ApexComponentMaster.ComponentInfo> functionComparer = new FunctionComparer <ApexComponentMaster.ComponentInfo>((ApexComponentMaster.ComponentInfo a, ApexComponentMaster.ComponentInfo b) => a.name.CompareTo(b.name));

            foreach (ApexComponentMaster.ComponentCategory value in this._categories.Values)
            {
                value.Sort(functionComparer);
            }
            if (!this._firstTime)
            {
                return(flag);
            }
            this.ToggleAll();
            this._firstTime = false;
            return(true);
        }
Esempio n. 5
0
 public virtual void Sort(int index, int length, FunctionComparer <T> comparer)
 {
     _members.Sort(index, length, comparer);
 }
Esempio n. 6
0
 public virtual void Sort(FunctionComparer <T> comparer)
 {
     _members.Sort(comparer);
 }
Esempio n. 7
0
        /// <summary>
        /// Initializes this instance.
        /// </summary>
        /// <returns></returns>
        public bool Init(IEnumerable <ComponentCandidate> candidates)
        {
            Cleanup();

            bool updated = false;
            int  idx     = 0;

            foreach (var cc in candidates)
            {
                var           id = cc.component.GetInstanceID();
                ComponentInfo cinfo;
                bool          alreadyRegistered = _components.TryGetValue(id, out cinfo);

                //Since hideflags are reset when applying prefab changes, we reapply them here
                if ((cc.component.hideFlags & HideFlags.HideInInspector) == 0 && (_hiddenComponents & (1 << idx)) > 0)
                {
                    cc.component.hideFlags |= HideFlags.HideInInspector;
                    updated = true;
                }

                //If already registered we still need to ensure hideflags are set correctly, again due to prefab stuff
                if (alreadyRegistered)
                {
                    idx++;
                    cinfo.isVisible = (cc.component.hideFlags & HideFlags.HideInInspector) == 0;
                    continue;
                }

                cinfo = new ComponentInfo
                {
                    component = cc.component,
                    id        = id,
                    idx       = idx++,
                    name      = cc.component.GetType().Name.Replace("Component", string.Empty).ExpandFromPascal(),
                    isVisible = (cc.component.hideFlags & HideFlags.HideInInspector) == 0
                };

                _components.Add(id, cinfo);

                ComponentCategory cat;
                if (!_categories.TryGetValue(cc.categoryName, out cat))
                {
                    cat = new ComponentCategory {
                        name = cc.categoryName
                    };
                    _categories.Add(cc.categoryName, cat);
                }

                cat.Add(cinfo);
                cinfo.category = cat;
            }

            var comparer = new FunctionComparer <ComponentInfo>((a, b) => a.name.CompareTo(b.name));

            foreach (var cat in _categories.Values)
            {
                cat.Sort(comparer);
            }

            if (_firstTime)
            {
                ToggleAll();
                _firstTime = false;
                return(true);
            }

            return(updated);
        }
Esempio n. 8
0
        static void Main(string[] args)
        {
            #region to derive from a painting
            _ = Painting.TryParse("110000", out Painting painting);
            Debug.Assert(painting is not null);

            // Traditionally:
            IDerivation derivation = new OverturningDerivation();
            Console.WriteLine($"110000 -o> {derivation.Derive(painting)}");
            Console.WriteLine();
            // Output: 110000 -o> 000011

            derivation = new ChangingDerivation(3, 4);
            Console.WriteLine($"110000 -c> {derivation.Derive(painting)}");
            Console.WriteLine();
            // Output: 110000 -c> 110110

            derivation = new FunctionDerivation((painting) =>
            {
                return(new Painting(painting.Select((_, _) => YinYang.Yang)));
            });
            // This derivation will turn all the lines to yang lines.
            Console.WriteLine($"110000 -f> {derivation.Derive(painting)}");
            Console.WriteLine();
            // Output: 110000 -f> 111111

            // With extension methods:
            Console.WriteLine($"110000 -o2> {painting.ToOverlapping()}");
            Console.WriteLine();
            // Output: 110000 -o2> 100000

            Console.WriteLine($"110000 -o2> " +
                              $"{painting.ApplyDerivation((_) => new Painting(YinYang.Yang))}");
            Console.WriteLine();
            // Output: 110000 -o2> 1
            #endregion

            #region to compare two paintings
            _ = Painting.TryParse("110000", out Painting painting1);
            _ = Painting.TryParse("000011", out Painting painting2);
            _ = Painting.TryParse("111111", out Painting painting3);
            Debug.Assert(painting1 is not null && painting2 is not null);

            // Traditionally:
            IComparer <bool> comparer = new OverlappingComparer();
            Console.WriteLine(comparer.Compare(painting1, painting2));
            Console.WriteLine();
            // Output: False

            comparer = new OverturningComparer();
            Console.WriteLine(comparer.Compare(painting1, painting2));
            Console.WriteLine();
            // Output: True

            comparer = new FunctionComparer(derivation);
            // The current derivation will turn all the lines to yang lines,
            // and now the compare will check that.
            Console.WriteLine($"{comparer.Compare(painting1, painting3)} " +
                              $"{comparer.Compare(painting3, painting1)}");
            Console.WriteLine();
            // Output: True False

            // With extension methods:
            Console.WriteLine(painting1.IsOverturnedFrom(painting2));
            Console.WriteLine();
            // Output: True

            foreach (var lineIndex in painting1.GetDifferentLinesBetween(painting2))
            {
                Console.Write(lineIndex);
            }
            Console.WriteLine();
            Console.WriteLine();
            // Output: 0145
            #endregion
        }