Пример #1
0
    private void OnRemoveWall(Vector3 pz)
    {
        WallPoint wp = new WallPoint(Mathf.RoundToInt(pz.x), Mathf.RoundToInt(pz.y));

        if (IsInsideBuilding(wp))
        {
            DeleteWall(wp);

            WallController w;
            w = GetWall(new WallPoint(wp.X + 1, wp.Y));
            if (w != null && w.PrefabIsDoor())
            {
                DeleteWall(w.Position);
            }

            w = GetWall(new WallPoint(wp.X - 1, wp.Y));
            if (w != null && w.PrefabIsDoor())
            {
                DeleteWall(w.Position);
            }

            w = GetWall(new WallPoint(wp.X, wp.Y + 1));
            if (w != null && w.PrefabIsDoor())
            {
                DeleteWall(w.Position);
            }

            w = GetWall(new WallPoint(wp.X, wp.Y - 1));
            if (w != null && w.PrefabIsDoor())
            {
                DeleteWall(w.Position);
            }
        }
    }
    IEnumerator MoveWalls()
    {
        float passedTime = 0;

        while (true)
        {
            //get the fraction of time to total time
            passedTime += Time.deltaTime * GameManager.Instance.TimeScale;
            float percentageComplete = Pulse(passedTime);
            for (int i = 0; i < wallPoints.Count; ++i)
            {
                //move the walls
                WallPoint firstWallPoint  = wallPoints[i];
                WallPoint secondWallPoint = wallPoints[(i + 1) % wallPoints.Count];
                Vector3   firstPoint      = GetCurrentLocation(firstWallPoint, percentageComplete);
                Vector3   secondPoint     = GetCurrentLocation(secondWallPoint, percentageComplete);
                UpdateWallToPoints(walls[i], firstPoint, secondPoint);

                //move the corners
                UpdateCornerToPoint(corners[i], firstPoint);
            }


            yield return(null);
        }
    }
Пример #3
0
	public bool Process (Segmentator s, ILogicObject o)
	{
		bool res = false;
	
		if(o.ObjectType == CellObjects.Heater || 
		   o.ObjectType == CellObjects.HeatingPipe || 
		   o.ObjectType == CellObjects.Sink ||
		   o.ObjectType == CellObjects.Toilet)
			return false;

		o.ObjectRect.Foreach((MapPoint p) => {

			WallPoint wp;

			wp = new WallPoint(p.X,p.Y);
			if(s.Doors.ContainsKey(wp.toInt()))
				res = true;

			wp = new WallPoint(p.X+1,p.Y);
			if(s.Doors.ContainsKey(wp.toInt()))
				res = true;

			wp = new WallPoint(p.X,p.Y+1);
			if(s.Doors.ContainsKey(wp.toInt()))
				res = true;

			wp = new WallPoint(p.X+1,p.Y+1);
			if(s.Doors.ContainsKey(wp.toInt()))
				res = true;

		});
		return res;
	}
Пример #4
0
    private void SetAdjacentWall(WallController wall, Side side)
    {
        WallPoint wp           = wall.Position;
        WallPoint adjWallPoint = null;

        switch (side)
        {
        case Side.Bottom: adjWallPoint = new WallPoint(wp.X, wp.Y - 1); break;

        case Side.Left: adjWallPoint = new WallPoint(wp.X - 1, wp.Y); break;

        case Side.Right: adjWallPoint = new WallPoint(wp.X + 1, wp.Y); break;

        case Side.Top: adjWallPoint = new WallPoint(wp.X, wp.Y + 1); break;
        }

        WallController adjWall = GetWall(adjWallPoint);

        if (adjWall == null)
        {
            if (WallPrefab.PrefabValidatePosition(M, adjWallPoint))
            {
                wall.wallSprite.SetSide(side, true);
                SetWall(adjWallPoint, WallPrefab);
            }
        }
        else if (adjWall.WallObject == null)
        {
            wall.wallSprite.SetSide(side, true);
        }
    }
Пример #5
0
	private bool PrefabGetNeighbours(Manager m, WallPoint point, out WallController w1, out WallController w2)
	{
		w1=null;w2=null;

		WallController left = m.House.GetWall(new WallPoint(point.X-1,point.Y));
		WallController right = m.House.GetWall(new WallPoint(point.X+1,point.Y));
		WallController top = m.House.GetWall(new WallPoint(point.X,point.Y+1));
		WallController bottom = m.House.GetWall(new WallPoint(point.X,point.Y-1));

		WallController cur = m.House.GetWall(point);
		if(cur!=null && cur.WallObject!=null)
		   return false;

		if(left!=null && right!=null)
		{
			if(top!=null || bottom!=null)
				return false;
			w1 = left;w2=right;
		}
		else if(top!=null && bottom!=null)
		{
			if(left!=null || right!=null)
				return false;
			w1 = bottom;w2 = top;
		}
		else
			return false;
		return true;
	}
Пример #6
0
    public void PlaceIndicators(Dictionary <int, CellController> cells,
                                Dictionary <int, WallController> walls,
                                WallController wallPrefab)
    {
        bool isDoor = wallPrefab.PrefabIsDoor();

        foreach (CellController c in cells.Values)
        {
            if (c.IsMultiCell)
            {
                MapRect rect = c.GetCurCellIndexes();
                rect.Foreach((MapPoint p) => {
                    WallPoint wp = new WallPoint(p.X, p.Y);
                    if ((isDoor || !walls.ContainsKey(wp.toInt())) && wallPrefab.PrefabValidatePosition(M, wp))
                    {
                        InstantiateIndicator(wp, isDoor);
                    }
                });
            }
            else
            {
                WallPoint wp = new WallPoint(c.Position.X, c.Position.Y);
                if ((isDoor || !walls.ContainsKey(wp.toInt())) && wallPrefab.PrefabValidatePosition(M, wp))
                {
                    InstantiateIndicator(wp, isDoor);
                }
            }
        }
    }
Пример #7
0
	public LogicWall (WallPoint point, bool top, bool bottom, bool left, bool right)
	{
		Position = point;
		Top = top;
		Bottom = bottom;
		Left = left;
		Right = right;
	}
Пример #8
0
 public void Foreach(System.Action <WallPoint, Side> action)
 {
     for (int i = 0; i < 4; i++)
     {
         WallPoint ip = new WallPoint(X + xtable[i], Y + ytable[i]);
         action(ip, sidetable[i]);
     }
 }
Пример #9
0
	public void Foreach(System.Action<WallPoint,Side> action)
	{
		for(int i=0;i<4;i++)
		{
			WallPoint ip = new WallPoint(X+xtable[i],Y+ytable[i]);
			action(ip,sidetable[i]);
		}
	}
Пример #10
0
 public LogicWall(WallPoint point, bool top, bool bottom, bool left, bool right)
 {
     Position = point;
     Top      = top;
     Bottom   = bottom;
     Left     = left;
     Right    = right;
 }
Пример #11
0
	public WallPoint GetWallPositionFromMouseLocation()
	{
		// round the numbers to the nearest whole number using 5 decimal place precision
		WallPoint pos = new WallPoint(
			(int)System.Math.Round(mouseHitPos.x+0.5f, 5, System.MidpointRounding.ToEven), 
			(int)System.Math.Round(mouseHitPos.y+0.5f, 5, System.MidpointRounding.ToEven));
		
		return pos;
	}
Пример #12
0
    public WallPoint GetWallPositionFromMouseLocation()
    {
        // round the numbers to the nearest whole number using 5 decimal place precision
        WallPoint pos = new WallPoint(
            (int)System.Math.Round(mouseHitPos.x + 0.5f, 5, System.MidpointRounding.ToEven),
            (int)System.Math.Round(mouseHitPos.y + 0.5f, 5, System.MidpointRounding.ToEven));

        return(pos);
    }
Пример #13
0
    public WallController GetWall(WallPoint point)
    {
        if (walls.ContainsKey(point.toInt()))
        {
            return(walls[point.toInt()]);
        }

        return(null);
    }
Пример #14
0
	void InstantiateIndicator(WallPoint p, bool isDoor)
	{
		if(indicators.ContainsKey(p.toInt()))
			return;

		Transform ph = Instantiate<Transform>(isDoor?DoorIndicator:PlaceIndicator);
		ph.parent = transform;
		ph.localPosition = new Vector3(p.X,p.Y,0);
		indicators.Add(p.toInt(),ph);
	}
Пример #15
0
    public void EditorRemoveWall(WallPoint point)
    {
        WallController w = null;

        if (walls.TryGetValue(point.toInt(), out w))
        {
            GameObject.DestroyImmediate(w.gameObject);
            walls.Remove(point.toInt());
        }
    }
Пример #16
0
    public bool IsInsideBuilding(WallPoint wallPoint)
    {
        bool res =
            cells.ContainsKey(wallPoint.toInt()) &&
            cells.ContainsKey(new WallPoint(wallPoint.X - 1, wallPoint.Y).toInt()) &&
            cells.ContainsKey(new WallPoint(wallPoint.X, wallPoint.Y - 1).toInt()) &&
            cells.ContainsKey(new WallPoint(wallPoint.X - 1, wallPoint.Y - 1).toInt());

        return(res);
    }
Пример #17
0
    private void DeleteWall(WallPoint wp)
    {
        WallController wall = GetWall(wp);

        if (wall != null)
        {
            Destroy(wall.gameObject);
            walls.Remove(wp.toInt());
            UpdateWallsAround(wp);
        }
    }
Пример #18
0
    //public void ForeachWall(System.Action<WallPoint,WallController> action)
    //{

    //}

    public WallController PrefabSetWall(Manager m, WallPoint point)
    {
        IWallObject    wo = GetComponentInterface <IWallObject>();
        WallController w  = m.House.ReplaceWall(point, this);

        if (wo != null)
        {
            wo.PrefabPrepareWall(m, w);
        }
        return(w);
    }
Пример #19
0
	public bool PrefabValidatePosition(Manager m, WallPoint point)
	{
		WallController w1,w2;
		if(!PrefabGetNeighbours(m,point,out w1,out w2))
			return false;

		if(w1.WallObject!=null || w2.WallObject!=null)
			return false;

		return true;
	}
Пример #20
0
    private void PlaceWall(HouseController hc, WallPoint p, WallController prefab)
    {
        if (hc.GetWall(p) == null)
        {
            return;
        }

        hc.EditorRemoveWall(p);
        WallController w = hc.SetWall(p, prefab);

        w.EditorUpdateWall();
    }
Пример #21
0
    void InstantiateIndicator(WallPoint p, bool isDoor)
    {
        if (indicators.ContainsKey(p.toInt()))
        {
            return;
        }

        Transform ph = Instantiate <Transform>(isDoor?DoorIndicator:PlaceIndicator);

        ph.parent        = transform;
        ph.localPosition = new Vector3(p.X, p.Y, 0);
        indicators.Add(p.toInt(), ph);
    }
Пример #22
0
 private void UpdateWallsAround(WallPoint wp)
 {
     for (int x = wp.X - 1; x <= wp.X + 1; x++)
     {
         for (int y = wp.Y - 1; y <= wp.Y + 1; y++)
         {
             WallController w = GetWall(new WallPoint(x, y));
             if (w != null)
             {
                 w.UpdateWall();
             }
         }
     }
 }
Пример #23
0
    public bool PrefabValidatePosition(Manager m, WallPoint point)
    {
        WallController w1, w2;

        if (!PrefabGetNeighbours(m, point, out w1, out w2))
        {
            return(false);
        }

        if (w1.WallObject != null || w2.WallObject != null)
        {
            return(false);
        }

        return(true);
    }
Пример #24
0
    public void ForEachWall(MapPoint point, Action <WallPoint, WallController, Corner> action)
    {
        WallController wc = null;
        WallPoint      wp;

        for (int i = 0; i < 4; i++)
        {
            wp = new WallPoint(point.X + i % 2, point.Y + (i > 1?1:0));

            if (wp.X < 0 || wp.Y < 0)
            {
                continue;
            }
            walls.TryGetValue(wp.toInt(), out wc);
            action(wp, wc, cornersTable[i]);
            wc = null;
        }
    }
Пример #25
0
    public void PrefabPrepareWall(Manager m, WallController wc)
    {
        WallPoint point = wc.Position;

        WallController left  = m.House.GetWall(new WallPoint(point.X - 1, point.Y));
        WallController right = m.House.GetWall(new WallPoint(point.X + 1, point.Y));


        if (left != null && right != null)
        {
            wc.wallSprite.Left  = true;
            wc.wallSprite.Right = true;
        }
        else
        {
            wc.wallSprite.Top    = true;
            wc.wallSprite.Bottom = true;
        }
    }
Пример #26
0
    public WallController ReplaceWall(WallPoint point, WallController prefab)
    {
        if (point.X < 0 || point.Y < 0 || point.X > 0xffff || point.Y > 0xffff)
        {
            return(null);
        }

        WallController res = null;
        int            key = point.toInt();

        if (walls.ContainsKey(key))
        {
            GameObject.Destroy(walls[key].gameObject);
            walls.Remove(key);
        }

        res = SetWall(point, prefab);

        return(res);
    }
Пример #27
0
    public bool Process(Segmentator s, ILogicObject o)
    {
        bool res = false;

        if (o.ObjectType == CellObjects.Heater ||
            o.ObjectType == CellObjects.HeatingPipe ||
            o.ObjectType == CellObjects.Sink ||
            o.ObjectType == CellObjects.Toilet)
        {
            return(false);
        }

        o.ObjectRect.Foreach((MapPoint p) => {
            WallPoint wp;

            wp = new WallPoint(p.X, p.Y);
            if (s.Doors.ContainsKey(wp.toInt()))
            {
                res = true;
            }

            wp = new WallPoint(p.X + 1, p.Y);
            if (s.Doors.ContainsKey(wp.toInt()))
            {
                res = true;
            }

            wp = new WallPoint(p.X, p.Y + 1);
            if (s.Doors.ContainsKey(wp.toInt()))
            {
                res = true;
            }

            wp = new WallPoint(p.X + 1, p.Y + 1);
            if (s.Doors.ContainsKey(wp.toInt()))
            {
                res = true;
            }
        });
        return(res);
    }
    private float frequency; // Frequency in Hz

    void Start()
    {
        //set the wall points to whatever is input
        List <RectTransform> startTransforms  = startPoints.GetComponentsInChildren <RectTransform>().ToList();
        List <RectTransform> finishTransfroms = endPoints.GetComponentsInChildren <RectTransform>().ToList();

        Debug.Assert(startTransforms.Count == finishTransfroms.Count);

        // -1 for the first point, which is the root
        int numPoints = startTransforms.Count - 1;

        for (int i = 1; i < startTransforms.Count; ++i)
        {
            wallPoints.Add(new WallPoint(startTransforms[i].gameObject, finishTransfroms[i].gameObject));
        }

        //set frequency
        frequency = 1 / cycleLength;

        //grab the start time
        startTime = Time.time;

        //spawn in the walls and corners
        for (int i = 0; i < wallPoints.Count; ++i)
        {
            WallPoint  firstWallPoint  = wallPoints[i];
            WallPoint  secondWallPoint = wallPoints[(i + 1) % wallPoints.Count];
            GameObject wall            = Instantiate(wallPrefab, transform);
            UpdateWallToPoints(wall, firstWallPoint.startLocation, secondWallPoint.startLocation);
            walls.Add(wall);

            //corner
            GameObject corner = Instantiate(wallPrefab, transform);
            UpdateCornerToPoint(corner, firstWallPoint.startLocation);
            corners.Add(corner);
        }

        StartCoroutine(MoveWalls());
    }
Пример #29
0
    public bool PrefabValidatePosition(Manager m, WallPoint point)
    {
        IWallObject wo = GetComponentInterface <IWallObject>();

        if (wo != null && wo.PrefabValidatePosition(m, point) == false)
        {
            return(false);
        }

        if (!m.House.IsInsideBuilding(point))
        {
            return(false);
        }
        WallController w = null;

        w = m.House.GetWall(new WallPoint(point.X - 1, point.Y));
        if (w != null && w.WallObject != null)
        {
            return(false);
        }
        w = m.House.GetWall(new WallPoint(point.X + 1, point.Y));
        if (w != null && w.WallObject != null)
        {
            return(false);
        }
        w = m.House.GetWall(new WallPoint(point.X, point.Y - 1));
        if (w != null && w.WallObject != null)
        {
            return(false);
        }
        w = m.House.GetWall(new WallPoint(point.X, point.Y + 1));
        if (w != null && w.WallObject != null)
        {
            return(false);
        }

        return(true);
    }
Пример #30
0
    private bool PrefabGetNeighbours(Manager m, WallPoint point, out WallController w1, out WallController w2)
    {
        w1 = null; w2 = null;

        WallController left   = m.House.GetWall(new WallPoint(point.X - 1, point.Y));
        WallController right  = m.House.GetWall(new WallPoint(point.X + 1, point.Y));
        WallController top    = m.House.GetWall(new WallPoint(point.X, point.Y + 1));
        WallController bottom = m.House.GetWall(new WallPoint(point.X, point.Y - 1));

        WallController cur = m.House.GetWall(point);

        if (cur != null && cur.WallObject != null)
        {
            return(false);
        }

        if (left != null && right != null)
        {
            if (top != null || bottom != null)
            {
                return(false);
            }
            w1 = left; w2 = right;
        }
        else if (top != null && bottom != null)
        {
            if (left != null || right != null)
            {
                return(false);
            }
            w1 = bottom; w2 = top;
        }
        else
        {
            return(false);
        }
        return(true);
    }
Пример #31
0
    public WallController SetWall(WallPoint point, WallController prefab)
    {
        if (point.X < 0 || point.Y < 0 || point.X > 0xffff || point.Y > 0xffff)
        {
            return(null);
        }

        WallController res = null;
        int            key = point.toInt();

        if (!walls.ContainsKey(key))
        {
            WallController newWall = Instantiate <WallController>(prefab);
            newWall.transform.parent = transform;
            newWall.Position         = point;
            walls.Add(key, newWall);
            res = newWall;
        }
        else
        {
            res = walls[key];
        }
        return(res);
    }
Пример #32
0
	public void EditorRemoveWall(WallPoint point)
	{
		WallController w = null;
		if(walls.TryGetValue(point.toInt(),out w))
		{
			GameObject.DestroyImmediate(w.gameObject);
			walls.Remove(point.toInt());
		}
	}
Пример #33
0
	public void PlaceIndicators(Dictionary<int, CellController> cells, 
	                            Dictionary<int, WallController> walls, 
	                            WallController wallPrefab)
	{
		bool isDoor =  wallPrefab.PrefabIsDoor();
		foreach(CellController c in cells.Values)
		{
			if(c.IsMultiCell)
			{
				MapRect rect = c.GetCurCellIndexes();
				rect.Foreach((MapPoint p) => {
					WallPoint wp = new WallPoint(p.X,p.Y);
					if(  (isDoor || !walls.ContainsKey(wp.toInt())) && wallPrefab.PrefabValidatePosition(M,wp))
						InstantiateIndicator(wp, isDoor);
				});
			}
			else
			{
				WallPoint wp = new WallPoint(c.Position.X,c.Position.Y);
				if(  (isDoor || !walls.ContainsKey(wp.toInt())) && wallPrefab.PrefabValidatePosition(M,wp))
					InstantiateIndicator(wp, isDoor);
			}
		}
	}
Пример #34
0
 public Door(WallPoint position)
 {
     Position = position;
 }
Пример #35
0
	//public void ForeachWall(System.Action<WallPoint,WallController> action)
	//{

	//}

	public WallController PrefabSetWall(Manager m, WallPoint point)
	{
		IWallObject wo = GetComponentInterface<IWallObject>();
		WallController w = m.House.ReplaceWall(point,this);
		if(wo!=null)
		{
			wo.PrefabPrepareWall(m,w);
		}
		return w;
	}
 Vector3 GetCurrentLocation(WallPoint wp, float percentage)
 {
     return(Vector3.Lerp(wp.startLocation, wp.endLocation, percentage));
 }
Пример #37
0
	private void DeleteWall(WallPoint wp)
	{
		WallController wall = GetWall(wp);
		if(wall!=null)
		{
			Destroy(wall.gameObject);
			walls.Remove(wp.toInt());
			UpdateWallsAround(wp);
		}
	}
Пример #38
0
	public WallController GetWall(WallPoint point)
	{

		if(walls.ContainsKey(point.toInt()))
			return walls[point.toInt()];

		return null;
	}
Пример #39
0
	public WallController ReplaceWall(WallPoint point, WallController prefab)
	{
		if(point.X<0 || point.Y<0 || point.X>0xffff || point.Y>0xffff)
			return null;

		WallController res = null;
		int key = point.toInt();

		if(walls.ContainsKey(key))
		{
			GameObject.Destroy(walls[key].gameObject);
			walls.Remove(key);
		}

		res = SetWall(point, prefab);

		return res;
	}
Пример #40
0
	public void ForEachWall(MapPoint point, Action<WallPoint,WallController,Corner> action)
	{
		WallController wc = null;
		WallPoint wp;

		for(int i=0;i<4;i++)
		{
			wp = new WallPoint(point.X+i%2,point.Y+(i>1?1:0));

			if(wp.X<0 || wp.Y<0)
				continue;
			walls.TryGetValue(wp.toInt(),out wc);
			action(wp,wc,cornersTable[i]);
			wc = null;
		}



	}
Пример #41
0
	public bool IsInsideBuilding(WallPoint wallPoint)
	{
		bool res =
				cells.ContainsKey(wallPoint.toInt()) 
			&& cells.ContainsKey(new WallPoint(wallPoint.X-1,wallPoint.Y).toInt()) 
			&& cells.ContainsKey(new WallPoint(wallPoint.X,wallPoint.Y-1).toInt()) 
			&& cells.ContainsKey(new WallPoint(wallPoint.X-1,wallPoint.Y-1).toInt()) ;
		return res;
	}
Пример #42
0
	public Door (WallPoint position)
	{
		Position = position;
	}
Пример #43
0
	public WallController SetWall(WallPoint point, WallController prefab)
	{
		if(point.X<0 || point.Y<0 || point.X>0xffff || point.Y>0xffff)
			return null;

		WallController res = null;
		int key = point.toInt();
		if(!walls.ContainsKey(key))
		{
			WallController newWall = Instantiate<WallController>(prefab);
			newWall.transform.parent = transform;
			newWall.Position = point;
			walls.Add(key,newWall);
			res = newWall;
		}
		else
			res = walls[key];
		return res;
	}
Пример #44
0
 public bool PrefabValidatePosition(Manager m, WallPoint point)
 {
     return(false);
 }
Пример #45
0
	private void OnPlaceWall(Vector3 pz, bool door)
	{
		WallController wallPrefab = selectedPrefab.GetComponent<WallController>();
		WallPoint wp = new WallPoint(Mathf.RoundToInt(pz.x),Mathf.RoundToInt(pz.y));
		
		Side side;
		if(new Rect(wp.X-0.25f,wp.Y-0.25f,0.5f,0.5f).Contains(pz))
		{
			side = Side.Middle;
		}
		else if(new Rect(wp.X-0.5f,wp.Y-0.25f,0.25f,0.5f).Contains(pz))
		{
			side = Side.Left;
		}
		else if(new Rect(wp.X-0.25f,wp.Y+0.25f,0.5f,0.25f).Contains(pz))
		{
			side = Side.Top;
		}
		else if(new Rect(wp.X+0.25f,wp.Y-0.25f,0.25f,0.5f).Contains(pz))
		{
			side = Side.Right;
		}
		else if(new Rect(wp.X-0.25f,wp.Y-0.5f,0.5f,0.25f).Contains(pz))
		{
			side = Side.Bottom;
		}
		else
		{
			side = Side.Undefined;
		}


		if(side==Side.Undefined)
			return;
		//new Rect(wp.X-0.5f,wp.Y-0.5f,wp.X+0.5f,wp.Y+0.5f).Contains(pz)
		if(IsInsideBuilding(wp))
		{
			WallController wall = null, adjWall=null;
			if(side==Side.Middle)
			{
				wall = wallPrefab.PrefabSetWall(M,wp);
			}
			else
			{
				wall = wallPrefab.PrefabSetWall(M,wp);
				SetAdjacentWall(wall,side);
			}

			UpdateWallsAround(wp);

			
		}
		else
		{
			// not inside building
			WallController wall = GetWall(wp);
			if(wall!=null && wall.WallObject==null)
			{
				wp.Foreach( (WallPoint p, Side wallSide) => {
					if(wallPrefab.PrefabValidatePosition(M,p) && side == wallSide)
						SetAdjacentWall(wall,side);
				});
				UpdateWallsAround(wp);
			}
		}
		Phantom.RemoveIndicators();
		Phantom.PlaceIndicators(cells,walls,wallPrefab);
	}
Пример #46
0
	private void UpdateWallsAround(WallPoint wp)
	{
		for(int x = wp.X-1;x<=wp.X+1;x++)
		{
			for(int y = wp.Y-1;y<=wp.Y+1;y++)
			{
				WallController w = GetWall(new WallPoint(x,y));
				if(w!=null)
					w.UpdateWall();
			}
			
		}
	}
Пример #47
0
	private void OnRemoveWall(Vector3 pz)
	{
		WallPoint wp = new WallPoint(Mathf.RoundToInt(pz.x),Mathf.RoundToInt(pz.y));

		if(IsInsideBuilding(wp))
		{
			DeleteWall(wp);

			WallController w;
			w = GetWall(new WallPoint(wp.X+1,wp.Y));
			if(w!=null && w.PrefabIsDoor())
				DeleteWall(w.Position);

			w = GetWall(new WallPoint(wp.X-1,wp.Y));
			if(w!=null && w.PrefabIsDoor())
				DeleteWall(w.Position);

			w = GetWall(new WallPoint(wp.X,wp.Y+1));
			if(w!=null && w.PrefabIsDoor())
				DeleteWall(w.Position);
			
			w = GetWall(new WallPoint(wp.X,wp.Y-1));
			if(w!=null && w.PrefabIsDoor())
				DeleteWall(w.Position);
		}
	}
Пример #48
0
    private void OnPlaceWall(Vector3 pz, bool door)
    {
        WallController wallPrefab = selectedPrefab.GetComponent <WallController>();
        WallPoint      wp         = new WallPoint(Mathf.RoundToInt(pz.x), Mathf.RoundToInt(pz.y));

        Side side;

        if (new Rect(wp.X - 0.25f, wp.Y - 0.25f, 0.5f, 0.5f).Contains(pz))
        {
            side = Side.Middle;
        }
        else if (new Rect(wp.X - 0.5f, wp.Y - 0.25f, 0.25f, 0.5f).Contains(pz))
        {
            side = Side.Left;
        }
        else if (new Rect(wp.X - 0.25f, wp.Y + 0.25f, 0.5f, 0.25f).Contains(pz))
        {
            side = Side.Top;
        }
        else if (new Rect(wp.X + 0.25f, wp.Y - 0.25f, 0.25f, 0.5f).Contains(pz))
        {
            side = Side.Right;
        }
        else if (new Rect(wp.X - 0.25f, wp.Y - 0.5f, 0.5f, 0.25f).Contains(pz))
        {
            side = Side.Bottom;
        }
        else
        {
            side = Side.Undefined;
        }


        if (side == Side.Undefined)
        {
            return;
        }
        //new Rect(wp.X-0.5f,wp.Y-0.5f,wp.X+0.5f,wp.Y+0.5f).Contains(pz)
        if (IsInsideBuilding(wp))
        {
            WallController wall = null, adjWall = null;
            if (side == Side.Middle)
            {
                wall = wallPrefab.PrefabSetWall(M, wp);
            }
            else
            {
                wall = wallPrefab.PrefabSetWall(M, wp);
                SetAdjacentWall(wall, side);
            }

            UpdateWallsAround(wp);
        }
        else
        {
            // not inside building
            WallController wall = GetWall(wp);
            if (wall != null && wall.WallObject == null)
            {
                wp.Foreach((WallPoint p, Side wallSide) => {
                    if (wallPrefab.PrefabValidatePosition(M, p) && side == wallSide)
                    {
                        SetAdjacentWall(wall, side);
                    }
                });
                UpdateWallsAround(wp);
            }
        }
        Phantom.RemoveIndicators();
        Phantom.PlaceIndicators(cells, walls, wallPrefab);
    }
Пример #49
0
	private void SetAdjacentWall(WallController wall, Side side)
	{
		WallPoint wp = wall.Position;
		WallPoint adjWallPoint = null;
		switch(side)
		{
		case Side.Bottom: adjWallPoint=new WallPoint(wp.X,wp.Y-1); break;
		case Side.Left: adjWallPoint=new WallPoint(wp.X-1,wp.Y); break;
		case Side.Right: adjWallPoint=new WallPoint(wp.X+1,wp.Y); break;
		case Side.Top: adjWallPoint=new WallPoint(wp.X,wp.Y+1); break;
		}

		WallController adjWall = GetWall(adjWallPoint);
		if(adjWall==null)
		{
			if(WallPrefab.PrefabValidatePosition(M,adjWallPoint))
			{
				wall.wallSprite.SetSide(side,true);
				SetWall(adjWallPoint, WallPrefab);
			}
		}
		else if(adjWall.WallObject==null)
		{
			wall.wallSprite.SetSide(side,true);
		}
	}
Пример #50
0
	private void PlaceWall(HouseController hc, WallPoint p, WallController prefab)
	{

		if(hc.GetWall(p)==null)
			return;

		hc.EditorRemoveWall(p);
		WallController w = hc.SetWall(p,prefab);
		w.EditorUpdateWall();

	}
	public bool PrefabValidatePosition(Manager m, WallPoint point)
	{
		return false;
	}
Пример #52
0
	public bool PrefabValidatePosition(Manager m, WallPoint point)
	{
		IWallObject wo = GetComponentInterface<IWallObject>();

		if(wo!=null && wo.PrefabValidatePosition(m,point)==false)
			return false;

		if(!m.House.IsInsideBuilding(point))
			return false;
		WallController w = null;

		w = m.House.GetWall(new WallPoint(point.X-1,point.Y));
		if(w!=null && w.WallObject!=null)
			return false;
		w = m.House.GetWall(new WallPoint(point.X+1,point.Y));
		if(w!=null && w.WallObject!=null)
			return false;
		w = m.House.GetWall(new WallPoint(point.X,point.Y-1));
		if(w!=null && w.WallObject!=null)
			return false;
		w = m.House.GetWall(new WallPoint(point.X,point.Y+1));
		if(w!=null && w.WallObject!=null)
			return false;

		return true;
	}