Exemplo n.º 1
0
    private void Start()
    {
        switch (this.RandomSelection)
        {
        case GreebleSelection.RandomizeChances:
        {
            GreebleDefinition[] greebleDefinitions = this.GreebleDefinitions;
            for (int i = 0; i < greebleDefinitions.Length; i++)
            {
                GreebleDefinition greebleDefinition = greebleDefinitions[i];
                greebleDefinition.Chance = GreebleUtility.ProceduralValue(1, 100);
            }
            break;
        }

        case GreebleSelection.SelectOne:
        {
            int num = GreebleUtility.ProceduralValue(0, this.GreebleDefinitions.Length);
            for (int j = 0; j < this.GreebleDefinitions.Length; j++)
            {
                this.GreebleDefinitions[j].Chance = ((j != num) ? 0 : 1);
            }
            break;
        }
        }
    }
Exemplo n.º 2
0
    public static GreebleDefinition ProceduralGreebleType(GreebleDefinition[] greebleDefinitions, bool checkAge, float ageInMinutes = 0f)
    {
        if (greebleDefinitions == null)
        {
            return(null);
        }
        int num = 0;

        foreach (GreebleDefinition greebleDefinition in greebleDefinitions)
        {
            if (greebleDefinition.Prefab && (!checkAge || greebleDefinition.IsAgeAppropriate(ageInMinutes)))
            {
                num += greebleDefinition.Chance;
            }
        }
        int num2 = GreebleUtility.ProceduralValue(0, num);

        num = 0;
        foreach (GreebleDefinition greebleDefinition2 in greebleDefinitions)
        {
            if (greebleDefinition2.Prefab && (!checkAge || greebleDefinition2.IsAgeAppropriate(ageInMinutes)))
            {
                num += greebleDefinition2.Chance;
                if (num2 < num)
                {
                    return(greebleDefinition2);
                }
            }
        }
        return(null);
    }
Exemplo n.º 3
0
 public void SpawnAll()
 {
     this.Despawn();
     this.Start();
     UnityEngine.Random.seed = this.GetRandomSeed();
     this.InstanceCount      = GreebleUtility.ProceduralValue(this.MinInstances, this.MaxInstances + 1);
     if (this.InstanceData == null || this.InstanceData.Length != this.InstanceCount)
     {
         this.InstanceData = new GreebleZone.GreebleInstanceData[this.InstanceCount];
         for (int i = 0; i < this.InstanceData.Length; i++)
         {
             this.InstanceData[i].Spawned = false;
             if (this.Data != null && Application.isPlaying)
             {
                 this.InstanceData[i].Destroyed = (this.Data._instancesState[i] == 255);
             }
             else
             {
                 this.InstanceData[i].Destroyed = false;
             }
             this.InstanceData[i].CreationTime = 0f;
         }
     }
     if (this.instances == null || this.instances.Length != this.InstanceCount)
     {
         this.instances = new GameObject[this.InstanceCount];
     }
     this.currentlyVisible = true;
     for (int j = 0; j < this.InstanceCount; j++)
     {
         this.SpawnIndex(j);
     }
     UnityEngine.Random.seed = this.GetRandomSeed();
 }
Exemplo n.º 4
0
    private void Start()
    {
        GreebleSelection randomSelection = this.RandomSelection;

        if (randomSelection != GreebleSelection.Normal)
        {
            if (randomSelection != GreebleSelection.RandomizeChances)
            {
                if (randomSelection == GreebleSelection.SelectOne)
                {
                    UnityEngine.Random.seed = this.GetRandomSeed();
                    int num = GreebleUtility.ProceduralValue(0, this.GreebleDefinitions.Length);
                    for (int i = 0; i < this.GreebleDefinitions.Length; i++)
                    {
                        this.GreebleDefinitions[i].Chance = ((i != num) ? 0 : 1);
                    }
                }
            }
            else
            {
                foreach (GreebleDefinition greebleDefinition in this.GreebleDefinitions)
                {
                    greebleDefinition.Chance = GreebleUtility.ProceduralValue(1, 100);
                }
            }
        }
    }
Exemplo n.º 5
0
 private void Spawn()
 {
     this.Despawn();
     UnityEngine.Random.seed = this.GetRandomSeed();
     this.InstanceCount      = GreebleUtility.ProceduralValue(this.MinInstancesModified, this.MaxInstancesModified + 1);
     if (this.InstanceData == null || this.InstanceData.Length != this.InstanceCount)
     {
         this.InstanceData = new GreebleZone.GreebleInstanceData[this.InstanceCount];
         for (int i = 0; i < this.InstanceData.Length; i++)
         {
             this.InstanceData[i].Spawned = false;
             if (this.Data != null && Application.isPlaying)
             {
                 this.InstanceData[i].Destroyed = (this.Data._instancesState[i] == byte.MaxValue);
             }
             else
             {
                 this.InstanceData[i].Destroyed = false;
             }
             this.InstanceData[i].CreationTime = 0f;
         }
     }
     if (this.instances == null || this.instances.Length != this.InstanceCount)
     {
         this.instances = new GameObject[this.InstanceCount];
     }
     this.currentlyVisible    = true;
     this.scheduledSpawnIndex = 0;
     this.ScheduledSpawn();
     UnityEngine.Random.seed = this.GetRandomSeed();
 }
Exemplo n.º 6
0
    public static GreebleDefinition ProceduralGreebleType(GreebleDefinition[] greebleDefinitions, float ageInMinutes = 0f)
    {
        if (greebleDefinitions == null)
        {
            return(null);
        }
        int num = 0;

        for (int i = 0; i < greebleDefinitions.Length; i++)
        {
            GreebleDefinition greebleDefinition = greebleDefinitions[i];
            if (greebleDefinition.Prefab && greebleDefinition.IsAgeAppropriate(ageInMinutes))
            {
                num += greebleDefinition.Chance;
            }
        }
        int num2 = GreebleUtility.ProceduralValue(0, num);

        num = 0;
        for (int j = 0; j < greebleDefinitions.Length; j++)
        {
            GreebleDefinition greebleDefinition2 = greebleDefinitions[j];
            if (greebleDefinition2.Prefab && greebleDefinition2.IsAgeAppropriate(ageInMinutes))
            {
                num += greebleDefinition2.Chance;
                if (num2 < num)
                {
                    return(greebleDefinition2);
                }
            }
        }
        return(null);
    }
Exemplo n.º 7
0
 private Vector3 ProceduralPositionOffset()
 {
     return(new Vector3(GreebleUtility.ProceduralValue(-0.5f, 0.5f) * this.greebleUnit.x, GreebleUtility.ProceduralValue(-0.5f, 0.5f) * this.greebleUnit.y, GreebleUtility.ProceduralValue(-0.5f, 0.5f) * this.greebleUnit.z));
 }
Exemplo n.º 8
0
 public static Vector3 ProceduralDirectionFast()
 {
     return(new Vector3(GreebleUtility.ProceduralValue(-1f, 1f), GreebleUtility.ProceduralValue(-1f, 1f), GreebleUtility.ProceduralValue(-1f, 1f)));
 }
Exemplo n.º 9
0
 public static float ProceduralAngle()
 {
     return(GreebleUtility.ProceduralValue(0f, 360f));
 }
Exemplo n.º 10
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();
    }