Exemplo n.º 1
0
    // Use this for initialization
    void Start()
    {
        PlaneObjectPool = new List <PullableObject>();
        activePlates    = new List <PullableObject>();


        PanelSon = transform.Find("Panels").gameObject;
        var xVar = (CountInX / 2f) * Size;
        var zVar = (CountInZ / 2f) * Size;

        for (float x = -xVar; x < xVar; x += Size)
        {
            for (float z = -zVar; z < zVar; z += Size)
            {
                var xPos = x + Size / 2f;
                var zPos = z + Size / 2f;

                Vector3        center   = transform.position;
                Vector3        Position = new Vector3(center.x + xPos, center.y + 0.01f, center.z + zPos);
                PullableObject instance = GetPlaneFromPool(GrayPlane, Position);

                if (PanelSon)
                {
                    instance.transform.parent = PanelSon.transform;
                }
            }
        }
    }
Exemplo n.º 2
0
 public void CreateGreenLine(List <Node> nodes)
 {
     foreach (var node in nodes)
     {
         int            x             = (int)node.GetPosition().x + 1;
         int            z             = (int)node.GetPosition().y + 1;
         PullableObject instanceGreen = GetPlaneFromPool(GreenPlane, GetPositionByXZ(x, z, 0.02f));
     }
 }
Exemplo n.º 3
0
 void CreateCollideGrids()
 {
     DeleteActivePlates();
     CanPlace = true;
     for (int x = activeGrid.X; x < activeGrid.X + activeGrid.SizeX; ++x)
     {
         for (int z = activeGrid.Z; z < activeGrid.Z + activeGrid.SizeZ; ++z)
         {
             bool EnableToPlace = GridWithUnits[x - 1, z - 1] == 0;
             CanPlace = EnableToPlace == false ? false : CanPlace;
             PullableObject instanceGreen = GetPlaneFromPool(GreenPlane, GetPositionByXZ(x, z, 0.02f));
             PullableObject instanceRed   = GetPlaneFromPool(RedPlane, GetPositionByXZ(x, z, 0.02f));
             instanceGreen.gameObject.SetActive(EnableToPlace);
             instanceRed.gameObject.SetActive(!EnableToPlace);
             activePlates.Add(instanceGreen);
             activePlates.Add(instanceRed);
         }
     }
 }
Exemplo n.º 4
0
    //ObjectPool

    PullableObject GetPlaneFromPool(PullableObject Plane, Vector3 Position)
    {
        for (int i = 0; i < PlaneObjectPool.Count; ++i)
        {
            PullableObject obj = PlaneObjectPool[i];
            if (obj.GetID() == Plane.GetID())
            {
                obj.transform.position = Position;
                obj.transform.rotation = transform.rotation;
                obj.transform.parent   = TempStuff.transform;
                obj.gameObject.SetActive(true);
                PlaneObjectPool.RemoveAt(i);
                return(obj);
            }
        }
        PullableObject instance = Instantiate(Plane, Position, transform.rotation, TempStuff.transform);

        instance.transform.localScale = new Vector3(Size / 10.5f, Size / 10.5f, Size / 10.5f);
        return(instance);
    }
Exemplo n.º 5
0
 void ReturnToPlanePool(PullableObject Plane)
 {
     Plane.gameObject.SetActive(false);
     PlaneObjectPool.Add(Plane);
 }