public object Get(string name, System.Type type)
        {
            object obj = null;

            if (type == typeof(UnityEngine.Object) || type.IsSubclassOf(typeof(UnityEngine.Object)))
            {
                obj = objects.Get(name);
            }
            else if (type == typeof(float))
            {
                obj = floats.Get(name);
            }
            else if (type == typeof(int))
            {
                obj = ints.Get(name);
            }
            else if (type == typeof(string))
            {
                obj = strings.Get(name) ?? string.Empty;
            }
            else if (type == typeof(bool))
            {
                obj = bools.Get(name);
            }
            else if (type.IsSubclassOf(typeof(System.Enum)))
            {
                obj = enums.Get(name);
            }
            else if (type == typeof(Vector3))
            {
                obj = vector3s.Get(name);
            }
            else if (type == typeof(Vector2))
            {
                obj = vector2s.Get(name);
            }
            else if (type == typeof(Vector4))
            {
                obj = vector4s.Get(name);
            }
            else if (type == typeof(Color))
            {
                obj = colors.Get(name);
            }
            else if (type == typeof(LayerMaskMap))
            {
                obj = layerMasks.Get(name);
            }
            else
            {
                throw new NotSupportedException($"Type {type.AssemblyQualifiedName} is not supported. ({name})");
            }
            if (obj == null && type.IsValueType)
            {
                return(Activator.CreateInstance(type));
            }
            return(obj);
        }
Exemple #2
0
 public virtual bool IsSolid(BoolMap data, int x, int y, int z,bool customIsSolid)
 {
     if (IsCustom(x,y,z)) return customIsSolid;
     if (x < 0 || y < 0 || z < 0 || x >= data.Width || y >= data.Height || z >= data.Depth)
     {
         return false;
     }
     return data.Get(x,y,z);
 }
        public void Mini()
        {
            BoolMap bm = new BoolMap(16);

            for (int i = 0; i < 16; i++)
            {
                Assert.IsFalse(bm.Get(i));
            }
            for (int i = 0; i < 16; i++)
            {
                bm.Enable(i);
                Assert.IsTrue(bm.Get(i));
                bm.Disable(i);
                for (int k = 0; k < 16; k++)
                {
                    Assert.IsFalse(bm.Get(k));
                }
            }
        }
        private int[] generatePrimes(int iLimit)
        {
            // For tracking performance
            // final long lTime = System.nanoTime();
            _bmIsPrime = new BoolMap(iLimit + 1);
            int x;
            int y;
            int n;
            int i;
            int iCount = 0;
            int xSquared;
            int nSquared;
            int nMod12;
            int sqrtLimit = (int)Math.Sqrt(iLimit);

            int[]     iaPrimes;
            string    elapsedTime;
            TimeSpan  ts;
            Stopwatch stopWatch = new Stopwatch();

            stopWatch.Start();

            switch (iLimit)
            {
            case 0:
            case 1:
                iaPrimes = null;
                break;

            case 2:
                iaPrimes    = new int[1];
                iaPrimes[0] = 2;
                break;

            case 3:
                iaPrimes    = new int[2];
                iaPrimes[0] = 2;
                iaPrimes[1] = 3;
                break;

            case 4:
                iaPrimes    = new int[2];
                iaPrimes[0] = 2;
                iaPrimes[1] = 3;
                break;

            case 5:
                iaPrimes    = new int[3];
                iaPrimes[0] = 2;
                iaPrimes[1] = 3;
                iaPrimes[2] = 5;
                break;

            default:
                for (x = 1; x <= sqrtLimit; x++)
                {
                    xSquared = x * x;
                    if (4 * xSquared + 1 <= iLimit)
                    {
                        for (y = 1; y <= sqrtLimit; y++)
                        {
                            n = 4 * xSquared + y * y;
                            if (n <= iLimit)
                            {
                                nMod12 = n % 12;
                                if (nMod12 == 1 || nMod12 == 5)
                                {
                                    _bmIsPrime.Flip(n);
                                }
                            }
                            else
                            {
                                y = sqrtLimit + 1;
                            }
                        }
                    }
                    else
                    {
                        break;
                    }
                }
                for (x = 1; x <= sqrtLimit; x++)
                {
                    xSquared = x * x;
                    if (3 * xSquared + 1 <= iLimit)
                    {
                        for (y = 1; y <= sqrtLimit; y++)
                        {
                            n = 3 * xSquared + y * y;
                            if (n <= iLimit)
                            {
                                if (n % 12 == 7)
                                {
                                    _bmIsPrime.Flip(n);
                                }
                            }
                            else
                            {
                                y = sqrtLimit + 1;
                            }
                        }
                    }
                    else
                    {
                        break;
                    }
                }
                for (x = 1; x <= sqrtLimit; x++)
                {
                    xSquared = x * x;
                    if (2 * (xSquared - x) + 1 <= iLimit)
                    {
                        for (y = x - 1; y > 0; y--)
                        {
                            n = 3 * xSquared - y * y;
                            if (n <= iLimit)
                            {
                                if (n % 12 == 11)
                                {
                                    _bmIsPrime.Flip(n);
                                }
                            }
                            else
                            {
                                y = 0;
                            }
                        }
                    }
                    else
                    {
                        break;
                    }
                }
                for (n = 5; n < sqrtLimit; n += 2)
                {
                    if (_bmIsPrime.Get(n))
                    {
                        nSquared = n * n;
                        for (i = nSquared; i < iLimit; i += nSquared)
                        {
                            _bmIsPrime.Disable(i);
                        }
                    }
                }
                iCount = 3;
                for (n = 7; n < _bmIsPrime.Length(); n += 2)
                {
                    if (_bmIsPrime[n])
                    {
                        iCount++;
                    }
                }
                iaPrimes      = new int[iCount];
                iaPrimes[0]   = 2;
                iaPrimes[1]   = 3;
                _bmIsPrime[2] = true;
                _bmIsPrime[3] = true;
                i             = 2;
                for (n = 5; n < _bmIsPrime.Length(); n += 2)
                {
                    if (_bmIsPrime[n])
                    {
                        iaPrimes[i] = n;
                        i++;
                    }
                }
                break;
            }
            stopWatch.Stop();
            ts          = stopWatch.Elapsed;
            elapsedTime = String.Format("{0:00}h{1:00}m{2:00}.{3:00}s", ts.Hours, ts.Minutes, ts.Seconds, ts.Milliseconds / 10);
            System.Diagnostics.Debug.WriteLine("Atkin: " + iaPrimes.Length + " primes up to " + iaPrimes[iaPrimes.Length - 1] + " generated in " + elapsedTime);
            return(iaPrimes);
        }