You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

51 lines
2.4 KiB

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace BuildSystem {
public static class LogicGridExtensions
{
//当定周围的grid
public static void BindLeftAndThis(this Grid self, Grid left)
{
left.right = self;
self.left = left;
}
public static void BindDownAndThis(this Grid self, Grid down)
{
down.up = self;
self.down = down;
}
/// <summary>
/// 判断是否可以放置,
/// 首先判断是不是万能,
/// 如果是再判断是否有车道,
/// 如果是再判断车道是否相同
/// </summary>
/// <param name="self"></param>
/// <param name="placeObject"></param>
/// <returns></returns>
public static bool IsCanPlace(this Grid self, PlaceObject placeObject) {
bool isCanPlace = true;
if (self.up!=null && isCanPlace) {
isCanPlace = (self.up.isHaves[2] == DirIsHaveRoad.None) || ((self.up.isHaves[2] == placeObject.isHaveRoad[0]) && (self.up.type[2] == placeObject.roadNumberType[0] || (self.up.isHaves[2] == DirIsHaveRoad.No && DirIsHaveRoad.No == placeObject.isHaveRoad[0])));
}
if (self.right != null && isCanPlace)
{
isCanPlace = (self.right.isHaves[3] == DirIsHaveRoad.None) || ((self.right.isHaves[3] == placeObject.isHaveRoad[1]) && (self.right.type[3] == placeObject.roadNumberType[1] || (self.right.isHaves[3] == DirIsHaveRoad.No && DirIsHaveRoad.No == placeObject.isHaveRoad[1])));
}
if (self.down != null && isCanPlace)
{
isCanPlace = (self.down.isHaves[0] == DirIsHaveRoad.None) || ((self.down.isHaves[0] == placeObject.isHaveRoad[2]) && (self.down.type[0] == placeObject.roadNumberType[2] || (self.down.isHaves[0] == DirIsHaveRoad.No && DirIsHaveRoad.No == placeObject.isHaveRoad[2])));
}
if (self.left != null && isCanPlace)
{
isCanPlace = (self.left.isHaves[1] == DirIsHaveRoad.None) || ((self.left.isHaves[1] == placeObject.isHaveRoad[3]) && (self.left.type[1] == placeObject.roadNumberType[3] || (self.left.isHaves[1] == DirIsHaveRoad.No && DirIsHaveRoad.No == placeObject.isHaveRoad[3])));
}
return isCanPlace;
}
}
}