Beispiel #1
0
 public static Vector3 ProceduralDirection()
 {
     return(Vector3.Normalize(GreebleUtility.ProceduralDirectionFast()));
 }
Beispiel #2
0
    private void SpawnIndex(int index)
    {
        if (this.InstanceData[index].Destroyed)
        {
            return;
        }
        UnityEngine.Random.seed = this.GetRandomSeed() + index;
        GreebleDefinition greebleDefinition = GreebleUtility.ProceduralGreebleType(this.GreebleDefinitions, (Time.timeSinceLevelLoad - this.InstanceData[index].CreationTime) / 60f);

        if (greebleDefinition == null)
        {
            UnityEngine.Random.seed = this.GetRandomSeed();
            return;
        }
        Vector3      vector   = Vector3.zero;
        Vector3      vector2  = Vector3.down;
        float        distance = this.Radius;
        GreebleShape shape    = this.Shape;

        if (shape != GreebleShape.Sphere)
        {
            if (shape == GreebleShape.Box)
            {
                Vector3 vector3 = this.Size * 0.5f;
                Vector3 b       = new Vector3(GreebleUtility.ProceduralValue(-vector3.x, vector3.x), GreebleUtility.ProceduralValue(-vector3.y, vector3.y), GreebleUtility.ProceduralValue(-vector3.z, vector3.z));
                int     num     = 0;
                switch (this.Direction)
                {
                case GreebleRayDirection.Floor:
                    num = 4;
                    break;

                case GreebleRayDirection.Ceiling:
                    num = 5;
                    break;

                case GreebleRayDirection.Walls:
                    num = GreebleUtility.ProceduralValue(0, 4);
                    break;

                case GreebleRayDirection.AllDirections:
                    num = GreebleUtility.ProceduralValue(0, 6);
                    break;
                }
                switch (num)
                {
                case 0:
                    vector2  = Vector3.left;
                    b.x      = vector3.x;
                    distance = this.Size.x;
                    break;

                case 1:
                    vector2  = Vector3.right;
                    b.x      = -vector3.x;
                    distance = this.Size.x;
                    break;

                case 2:
                    vector2  = Vector3.back;
                    b.z      = vector3.z;
                    distance = this.Size.z;
                    break;

                case 3:
                    vector2  = Vector3.forward;
                    b.z      = -vector3.z;
                    distance = this.Size.z;
                    break;

                case 4:
                    vector2  = Vector3.down;
                    b.y      = vector3.y;
                    distance = this.Size.y;
                    break;

                case 5:
                    vector2  = Vector3.up;
                    b.y      = -vector3.y;
                    distance = this.Size.y;
                    break;
                }
                vector += b;
            }
        }
        else
        {
            distance = this.Radius;
            Vector3 zero = Vector3.zero;
            do
            {
                zero = new Vector3(GreebleUtility.ProceduralValue(-this.Radius, this.Radius), GreebleUtility.ProceduralValue(-this.Radius, this.Radius), GreebleUtility.ProceduralValue(-this.Radius, this.Radius));
            }while (zero.magnitude > this.Radius);
            switch (this.Direction)
            {
            case GreebleRayDirection.Floor:
                vector += new Vector3(zero.x, 0f, zero.y);
                vector2 = Vector3.down;
                break;

            case GreebleRayDirection.Ceiling:
                vector += new Vector3(zero.x, 0f, zero.y);
                vector2 = Vector3.up;
                break;

            case GreebleRayDirection.Walls:
                vector2   = GreebleUtility.ProceduralDirectionFast();
                vector2.y = 0f;
                vector2.Normalize();
                vector += zero - Vector3.Project(zero, vector2);
                break;

            case GreebleRayDirection.AllDirections:
                vector2 = GreebleUtility.ProceduralDirection();
                break;
            }
        }
        Quaternion rotation = Quaternion.identity;

        if (greebleDefinition.RandomizeRotation)
        {
            rotation = Quaternion.Euler((!greebleDefinition.AllowRotationX) ? 0f : GreebleUtility.ProceduralAngle(), (!greebleDefinition.AllowRotationY) ? 0f : GreebleUtility.ProceduralAngle(), (!greebleDefinition.AllowRotationZ) ? 0f : GreebleUtility.ProceduralAngle());
        }
        this.instances[index] = GreebleUtility.Spawn(greebleDefinition, new Ray(base.transform.TransformPoint(vector), base.transform.TransformDirection(vector2)), distance, rotation, 0.5f);
        if (this.Data != null && this.instances[index] != null && Application.isPlaying)
        {
            try
            {
                if (greebleDefinition.HasCustomActiveValue)
                {
                    CustomActiveValueGreeble component = this.instances[index].GetComponent <CustomActiveValueGreeble>();
                    component.Data  = this.Data;
                    component.Index = index;
                    if (this.Data._instancesState[index] > 252)
                    {
                        this.Data._instancesState[index] = 252;
                    }
                }
                else
                {
                    this.Data._instancesState[index] = 253;
                }
            }
            catch (Exception message)
            {
                Debug.Log(message);
            }
        }
        if (this.instances[index])
        {
            if (this.MpSync && BoltNetwork.isServer)
            {
                BoltNetwork.Attach(this.instances[index]);
            }
            this.InstanceData[index].Spawned = true;
            if (this.OnSpawned != null)
            {
                this.OnSpawned(index, this.instances[index]);
            }
        }
        UnityEngine.Random.seed = this.GetRandomSeed();
    }