コード例 #1
0
 bool checkNeighbourObjs(gridSection check)
 {
     if (check.neighbours.objsRight.Count != 0)
     {
         if (checkClimable(check.neighbours.objsRight))
         {
             return(true);
         }
     }
     if (check.neighbours.objsLeft.Count != 0)
     {
         if (checkClimable(check.neighbours.objsLeft))
         {
             return(true);
         }
     }
     if (check.neighbours.objsForward.Count != 0)
     {
         if (checkClimable(check.neighbours.objsForward))
         {
             return(true);
         }
     }
     if (check.neighbours.objsBack.Count != 0)
     {
         if (checkClimable(check.neighbours.objsBack))
         {
             return(true);
         }
     }
     return(false);
 }
コード例 #2
0
    void correctYValue(gridSection grid)
    {
        gridSection above   = (gridSection)grid.neighbours.up;
        gridSection current = grid;

        Debug.Log("Checking");
        while (above != null)
        {
            above.pos = current.pos + new Vector3(0, radius, 0);
            current   = above;

            if (above.neighbours.up != null)
            {
                above = (gridSection)above.neighbours.up;
            }
            else
            {
                return;
            }
        }
    }
コード例 #3
0
    void setNeighboursValues(gridSection grid)
    {
        if (grid.neighbours.forward != null)
        {
            ((gridSection)grid.neighbours.forward).pos = grid.pos;
        }

        if (grid.neighbours.back != null)
        {
            ((gridSection)grid.neighbours.back).pos = grid.pos;
        }

        if (grid.neighbours.left != null)
        {
            ((gridSection)grid.neighbours.left).pos = grid.pos;
        }

        if (grid.neighbours.right != null)
        {
            ((gridSection)grid.neighbours.right).pos = grid.pos;
        }
    }
コード例 #4
0
    void spawn()
    {
        RaycastHit hit;

        while (check.Count != 0)
        {
            gridSection exist = find(check [0].gridPos);
            if (exist.pos != Vector3.zero)
            {
                //Debug.Log ("Ignored");
                ignored++;
                exist.addNeighbours(check [0].neighbours);
            }
            else
            {
                Checked++;
                //Debug.Log ("Checked");
                if (Physics.Raycast(check [0].gridPos, Vector3.down, maxHeight) || check [0].floorDistance < maxHeight || check[0].neighbours.climable)
                {
                    Vector3 effect = check [0].gridPos;

                    //check if inside obj
                    if (Physics.SphereCast(check [0].gridPos, 0.1f, Vector3.forward, out hit))
                    {
                        check.RemoveAt(0);
                        //return;
                        continue;
                    }

                    //down
                    if (check [0].neighbours.down == null)
                    {
                        if (!Physics.Raycast(check [0].gridPos, Vector3.down, maxHeight))
                        {
                            if (!checkSurroundingClimable(check [0].gridPos))
                            {
                                check.RemoveAt(0);
                                //return;
                                continue;
                            }
                            else
                            {
                                tempSection = ScriptableObject.CreateInstance <gridSection> ();
                                tempSection.setup(check [0].gridPos + (Vector3.down * radius), false, check [0].floorDistance - radius);
                                tempSection.neighbours.up = check [0];
                                check.Add(tempSection);
                            }
                        }
                        else
                        {
                            Physics.Raycast(check [0].gridPos, Vector3.down, out hit, maxHeight);
                            check [0].floorDistance = hit.distance;
                            check [0].neighbours.objsDown.Add(hit.collider.gameObject);
                            if (check [0].floorDistance <= radius)
                            {
                                check [0].floor = true;
                                effect.y        = hit.point.y + radius;
                                //if (check [0].pos != new Vector3 (check [0].pos.x, hit.point.y + radius, check [0].pos.z)) {
                                //check [0].pos = new Vector3 (check [0].pos.x, hit.point.y + radius, check [0].pos.z);
                                //if (check [0].neighbours.up != null) {
                                //if (((gridSection)check [0].neighbours.up).pos.y != check[0].pos.y + radius) {
                                //setNeighboursValues (check [0]);
                                //correctYValue (check [0]);
                                //}
                                //}
                                //}
                            }
                            else if (check [0].floorDistance < maxHeight)
                            {
                                tempSection = ScriptableObject.CreateInstance <gridSection> ();
                                tempSection.setup(check [0].gridPos + (Vector3.down * radius), false, check [0].floorDistance - radius);
                                tempSection.neighbours.up = check [0];
                                check.Add(tempSection);
                            }
                        }
                    }
                    else
                    {
                        if (!((gridSection)(check [0].neighbours.down)).neighbours.up)
                        {
                            ((gridSection)(check [0].neighbours.down)).neighbours.up = check [0];
                        }
                    }

                    //forawrd
                    if (check [0].neighbours.forward == null)
                    {
                        if (!Physics.Raycast(check [0].gridPos, Vector3.forward, out hit, radius))
                        {
                            tempSection = ScriptableObject.CreateInstance <gridSection> ();
                            tempSection.setup(check [0].gridPos + (Vector3.forward * radius), false, check [0].floorDistance);
                            tempSection.neighbours.back = check [0];
                            check.Add(tempSection);
                        }
                        else
                        {
                            check [0].neighbours.objsForward.Add(hit.collider.gameObject);
                            effect.z = hit.point.z - radius;
                        }
                    }
                    else
                    {
                        if (!((gridSection)(check [0].neighbours.forward)).neighbours.back)
                        {
                            ((gridSection)(check [0].neighbours.forward)).neighbours.back = check [0];
                        }
                    }

                    //back
                    if (check [0].neighbours.back == null)
                    {
                        if (!Physics.Raycast(check [0].gridPos, Vector3.back, out hit, radius))
                        {
                            tempSection = ScriptableObject.CreateInstance <gridSection> ();
                            tempSection.setup(check [0].gridPos + (Vector3.back * radius), false, check [0].floorDistance);
                            tempSection.neighbours.forward = check [0];
                            check.Add(tempSection);
                        }
                        else
                        {
                            check [0].neighbours.objsBack.Add(hit.collider.gameObject);
                            effect.z = hit.point.z + radius;
                        }
                    }
                    else
                    {
                        if (!((gridSection)(check [0].neighbours.back)).neighbours.forward)
                        {
                            ((gridSection)(check [0].neighbours.back)).neighbours.forward = check [0];
                        }
                    }

                    //left
                    if (check [0].neighbours.left == null)
                    {
                        if (!Physics.Raycast(check [0].gridPos, Vector3.left, out hit, radius))
                        {
                            tempSection = ScriptableObject.CreateInstance <gridSection> ();
                            tempSection.setup(check [0].gridPos + (Vector3.left * radius), false, check [0].floorDistance);
                            tempSection.neighbours.right = check [0];
                            check.Add(tempSection);
                        }
                        else
                        {
                            check [0].neighbours.objsLeft.Add(hit.collider.gameObject);
                            effect.x = hit.point.x + radius;
                        }
                    }
                    else
                    {
                        if (!((gridSection)(check [0].neighbours.left)).neighbours.right)
                        {
                            ((gridSection)(check [0].neighbours.left)).neighbours.right = check [0];
                        }
                    }

                    //right
                    if (check [0].neighbours.right == null)
                    {
                        if (!Physics.Raycast(check [0].gridPos, Vector3.right, out hit, radius))
                        {
                            tempSection = ScriptableObject.CreateInstance <gridSection> ();
                            tempSection.setup(check [0].gridPos + (Vector3.right * radius), false, check [0].floorDistance);
                            tempSection.neighbours.left = check [0];
                            check.Add(tempSection);
                        }
                        else
                        {
                            check [0].neighbours.objsRight.Add(hit.collider.gameObject);
                            effect.x = hit.point.x - radius;
                        }
                    }
                    else
                    {
                        if (!((gridSection)(check [0].neighbours.right)).neighbours.left)
                        {
                            ((gridSection)(check [0].neighbours.right)).neighbours.left = check [0];
                        }
                    }

                    check[0].neighbours.climable = checkNeighbourObjs(check[0]);

                    //up
                    if (check [0].neighbours.up == null || check[0].neighbours.climable)
                    {
                        if (!Physics.Raycast(check [0].gridPos, Vector3.up, out hit, radius))
                        {
                            tempSection = ScriptableObject.CreateInstance <gridSection> ();
                            tempSection.setup(check [0].gridPos + (Vector3.up * radius), false, check [0].floorDistance + radius);
                            tempSection.neighbours.down     = check [0];
                            tempSection.neighbours.climable = check[0].neighbours.climable;
                            check.Add(tempSection);
                        }
                        else
                        {
                            check [0].neighbours.objsUp.Add(hit.collider.gameObject);
                            effect.y = hit.point.y - radius;
                        }
                    }
                    else
                    {
                        if (!((gridSection)(check [0].neighbours.up)).neighbours.down)
                        {
                            ((gridSection)(check [0].neighbours.up)).neighbours.down = check [0];
                        }
                    }

                    mapGrid[Mathf.FloorToInt(check [0].gridPos.x)][Mathf.FloorToInt(check [0].gridPos.y)][Mathf.FloorToInt(check [0].gridPos.z)].Add(check [0]);
                    check [0].pos = effect;
                    //mapGrid.Add (check [0]);
                }
            }
            check.RemoveAt(0);
        }
    }
コード例 #5
0
 public static bool within(gridSection self, gridSection other, float dist)
 {
     return((self.gridPos - other.gridPos).sqrMagnitude <= dist && (self.gridPos - other.gridPos).sqrMagnitude >= -dist);
 }