コード例 #1
0
 void Start()
 {
     if (useother == true)
     {
         poolManager = GameObject.FindGameObjectWithTag("PoolManager").GetComponent <PropPoolManager>();
     }
     if (useother == true)
     {
         for (int i = 0; i < obstacles.Count; ++i)
         {
             obstacles[i].poolTrack.Clear();
             for (int j = 0; j < poolManager.pObstacle[obstacles[i].otherID].pools.Count; ++j)
             {
                 obstacles[i].poolTrack.Add(poolManager.pObstacle[obstacles[i].otherID].pools[j]);
             }
         }
         seedobstacle();
     }
 }
コード例 #2
0
    void Awake()
    {
        //Always reset scale of transform object to Unity to avoid bugs
        probabnotadded = false;
        if (useCustomPoints == false)
        {
            mesh = gam.GetComponent <MeshFilter>().mesh;
        }

        if (staticSeperation)
        {
            previouspoint = LevelMaker.previouspoint;
        }
        else
        {
            previouspoint = new List <Vector3>();
        }
        if (useother == false)
        {
            if (mesh)
            {
                for (int i = 0; i < obstacles.Count; ++i)
                {
                    for (int j = 0; j < PooledAmount; ++j)
                    {
                        obstacles[i].poolTrack.Add((GameObject)Instantiate(obstacles[i].obstacle, Vector3.zero, Quaternion.identity));
                        obstacles[i].poolTrack[j].transform.parent = transform;

                        obstacles[i].poolTrack[j].SetActive(false);
                    }
                }
            }
            else
            {
                Debug.LogError("Mesh Has not been assigned");
            }
        }
        if (useother == true)
        {
            poolManager = GameObject.FindGameObjectWithTag("PoolManager").GetComponent <PropPoolManager>();
        }
    }
コード例 #3
0
 public GameObject CheckPool(int randtrack)
 {
     if (useother == true)
     {
         for (int i = 0; i < poolManager.pObstacle[obstacles[randtrack].otherID].pools.Count; ++i)
         {
             if (poolManager.pObstacle[obstacles[randtrack].otherID].pools[i].activeInHierarchy == false)
             {
                 return(poolManager.pObstacle[obstacles[randtrack].otherID].pools[i]);
             }
         }
     }
     else
     {
         for (int i = 0; i < obstacles[randtrack].poolTrack.Count; ++i)
         {
             if (obstacles[randtrack].poolTrack[i].activeInHierarchy == false)
             {
                 return(obstacles[randtrack].poolTrack[i]);
             }
         }
     }
     if (useother == false)
     {
         obstacles[randtrack].poolTrack.Add((GameObject)Instantiate(obstacles[randtrack].obstacle, Vector3.zero, Quaternion.identity));
         obstacles[randtrack].poolTrack[obstacles[randtrack].poolTrack.Count - 1].transform.parent = transform;
     }
     else
     {
         poolManager = GameObject.FindGameObjectWithTag("PoolManager").GetComponent <PropPoolManager>();
         GameObject temp = (GameObject)Instantiate(poolManager.pObstacle[obstacles[randtrack].otherID].obstacle, Vector3.zero, Quaternion.identity);
         temp.transform.parent = poolManager.transform;
         poolManager.pObstacle[obstacles[randtrack].otherID].pools.Add(temp);
         temp.SetActive(false);
         return(temp);
     }
     return(obstacles[randtrack].poolTrack[obstacles[randtrack].poolTrack.Count - 1]);
 }
コード例 #4
0
 void OnEnable()
 {
     poolmanagerobject = new SerializedObject(target);
     poolmanager       = (PropPoolManager)target;
 }
コード例 #5
0
    public void seedobstacle()
    {
        if (probabnotadded == false)
        {
            if (useCustomPoints == false)
            {
                verts   = mesh.vertices;
                indices = mesh.triangles;
            }

            poolManager = GameObject.FindGameObjectWithTag("PoolManager").GetComponent <PropPoolManager>();

            temp = new GameObject();
            temp.transform.parent = transform;
            probabnotadded        = true;
            for (int i = 0; i < obstacles.Count; ++i)          //Probabilities are variables hence need to be added evrytime
            {
                probabs.Add(obstacles[i].probability);
                if (obstacles[i].ZingVariableObject)  //If it is a variable object then add its index so that next time when seedobstacle is called Probabilities are updated
                {
                    updatableIndexes.Add(i);
                }
            }
        }

        if (useCustomPoints == false)
        {
            if (Worktodo == false)
            {
                Worktodo   = true;
                currentMin = 0;
                AddValue   = mesh.triangles.Length / FramesMod;
                currentMax = mesh.triangles.Length / FramesMod;
            }
            if (currentMax > mesh.triangles.Length)
            {
                Worktodo = false;
                return;
            }
        }
        else
        {
            if (Worktodo == false)
            {
                Worktodo   = true;
                currentMin = 0;
                AddValue   = points.Count;
                currentMax = points.Count;
            }
            if (currentMax > points.Count)
            {
                Worktodo = false;
                return;
            }
        }


        for (int i = 0; i < currentMax;)
        {
            Vector3 pos, rot;
            if (useCustomPoints == false)
            {
                Vector3 P1 = verts[indices[i++]];

                Vector3 P2 = verts[indices[i++]];

                Vector3 P3 = verts[indices[i++]];

                pos = gam.transform.TransformPoint((P1 + P2 + P3) / 3);
                Vector3 n1 = verts[indices[i++]];

                Vector3 n2 = verts[indices[i++]];

                Vector3 n3 = verts[indices[i++]];
                rot = gam.transform.TransformDirection((n1 + n2 + n3) / 3);
            }
            else
            {
                pos = points[currentMin + i].position;
                rot = points[currentMin + i].position;
                i++;
            }
            int Randtrack = Probability(probabs, probabs.Count);
            if (Randtrack == -1)
            {
                Worktodo = false;
                return;
            }
            bool      b     = true;
            transenum trans = obstacles[Randtrack].trans;
            float     value = Random.value;



            temp.transform.position = pos;
            if (useCustomPoints == true)
            {
                temp.transform.rotation = points[currentMin + i - 1].rotation;
            }
            else
            {
                temp.transform.localRotation = Quaternion.identity;
            }


            switch (trans)
            {
            case transenum.X:
                temp.transform.localPosition = new Vector3(0, temp.transform.localPosition.y, temp.transform.localPosition.z);
                break;

            case transenum.Y:
                temp.transform.localPosition = new Vector3(temp.transform.localPosition.x, 0, temp.transform.localPosition.z);
                break;

            case transenum.Z:
                temp.transform.localPosition = new Vector3(temp.transform.localPosition.x, temp.transform.localPosition.y, 0);
                break;

            case transenum.None:

                break;

            default:
                break;
            }
            for (int x = 0; x < obstacles[Randtrack].procedures.Count; ++x)
            {
                doProcedure(obstacles[Randtrack].procedures[x], temp, rot);
            }
            int j = previouspoint.Count - 10;
            if (j < 0)
            {
                j = 0;
            }
            for (j = 0; j < previouspoint.Count; ++j)
            {
                bool contains    = false;
                bool canContinue = true;
                for (int x = 0; x < obstacles[Randtrack].SpecificSeperation.Count; x++)
                {
                    if (obstacles[Randtrack].SpecificSeperation[x].index == obstacleIndex[j])
                    {
                        contains = true;
                        if (Vector3.Distance(temp.transform.position, previouspoint[j]) < obstacles[Randtrack].SpecificSeperation[x].sepDist)
                        {
                            b           = false;
                            canContinue = false;
                            break;
                        }
                    }
                }
                if (contains == false && Vector3.Distance(temp.transform.position, previouspoint[j]) < obstacles[Randtrack].sepdist)
                {
                    b = false;
                    break;
                }
                if (!canContinue)
                {
                    break;
                }
            }
            if (b == true)
            {
                if (value < mainprobab)
                {
                    GameObject temp2 = CheckPool(Randtrack);
                    temp2.transform.position = temp.transform.position;
                    temp2.transform.rotation = temp.transform.rotation;
                    previouspoint.Add(temp2.transform.position);
                    obstacleIndex.Add(Randtrack);
                    temp2.SetActive(true);
                    temp2.transform.parent = transform;
                    obstacles[Randtrack].poolTrack.Add(temp2);
                }
                else
                {
                    //temp.transform.parent=GameObject.FindGameObjectWithTag("PoolManager").transform;
                    //temp.SetActive(false);
                }
            }
            else
            {
                //temp.transform.parent=GameObject.FindGameObjectWithTag("PoolManager").transform;
                //temp.SetActive(false);
            }
        }
        if (useCustomPoints == false)
        {
            currentMin += AddValue;
            if (currentMax == mesh.triangles.Length)
            {
                currentMax += 1;
            }
            else if (currentMax + AddValue > mesh.triangles.Length)
            {
                currentMax = mesh.triangles.Length;
            }
            else
            {
                currentMax += AddValue;
            }
        }
        else
        {
            Worktodo = false;
            return;
        }
    }