Exemplo n.º 1
0
    void Init(bool isGenerate)
    {
        abstractBounds = GetComponent <AbstractBounds>();
        meshFilter     = GetComponent <MeshFilter>();
        meshRenderer   = GetComponent <MeshRenderer>();

        if (meshData == null)
        {
            meshData = new RoomMeshData(abstractBounds);
        }

        if (meshFilter.sharedMesh == null || isGenerate)
        {
            meshFilter.sharedMesh = new Mesh();
        }
        mesh      = meshFilter.sharedMesh;
        mesh.name = "RoomMesh";

        roomExtends = abstractBounds.Extends;

        if (Application.isEditor)
        {
            mesh.MarkDynamic();
        }
    }
Exemplo n.º 2
0
 public void AbstractBoundsBinding()
 {
     if (AbstractBounds != null && AbstractBounds.gameObject == transform.gameObject && externBounds == null)
     {
         this.externBounds = AbstractBounds;
     }
     if (externBounds != null)
     {
         this.extends = externBounds.Extends;
     }
 }
Exemplo n.º 3
0
    private void ApplyCornerHeight(int index)
    {
        AbstractBounds ab           = doorDefinitions.AbstractBounds;
        int            targetHeight = ab.CornersHeightDegree(index);

        doorDefinitions.GlobalYCornerHeight = targetHeight;
        foreach (DoorDefinition door in doorDefinitions.doors)
        {
            int newCorner = ab.ChangeCornersHeight(door.CornerIndex, targetHeight);
            door.CornerIndex = newCorner;
            door.Position.y  = ab.Corners [newCorner].y;
            door.Offset.y    = 0f;
            doorDefinitions.AdjustWorkingPosition(door);
        }
        doorDefinitions.Preview();
    }
Exemplo n.º 4
0
    public void AdjustAbstractBounds(Mesh mesh)
    {
        AbstractBounds boundsObject = GetComponentInChildren <AbstractBounds> ();

        if (boundsObject != null)
        {
            AbstractBounds bounds = boundsObject.GetComponent <AbstractBounds> ();

            if (bounds != null)
            {
                Vector3 pos = new Vector3(mesh.bounds.center.x, 0f, mesh.bounds.center.z);
                boundsObject.transform.position = pos;
                bounds.hasFixedSize             = true;
                bounds.MinSize = mesh.bounds.size;
                bounds.Preview();
            }
        }
    }
Exemplo n.º 5
0
    //Hinders the door to be placed outside of the room
    public void ClampPosition(DoorDefinition door)
    {
        int[] cornerIndices = AbstractBounds.CornerIndicesByDirection(door.Direction);
        if (cornerIndices.Length > 0)
        {
            //Min and Max Points of the wall the door is facing
            //As to the order of the corners in AbstractBounds, these are not always the actual min and max values
            //The exceptions are handles by the clamp function below, which calculates min and max if they are unknown
            Vector3 roomBottomLeft = AbstractBounds.Corners [cornerIndices [0]];
            Vector3 roomTopRight   = AbstractBounds.Corners [cornerIndices [cornerIndices.Length - 1]];

            //Either (1,1,0) or (0,1,1). Y Axis is always the same since we always want to clamp on the Y-Axis
            Vector3 clampFilter = VectorAbs(Vector3.Cross(door.Direction, Vector3.up) + Vector3.up);
            //Clamp on all axis. Depending on the direction the door is facing, one axis' value is going to be discarded using the clampFilter
            Vector3 clampedPos;
            clampedPos.x  = Clamp(door.Position.x, roomBottomLeft.x, roomTopRight.x, DoorDefinition.GlobalSize);
            clampedPos.y  = Clamp(door.Position.y, roomBottomLeft.y, roomTopRight.y - 0.1f, DoorDefinition.GlobalSize / 2f);
            clampedPos.z  = Clamp(door.Position.z, roomBottomLeft.z, roomTopRight.z, DoorDefinition.GlobalSize);
            door.Position = Vector3.Scale(clampedPos, clampFilter) + Vector3.Scale(door.Position, VectorAbs(door.Direction));
        }
    }
Exemplo n.º 6
0
 public RoomMeshData(AbstractBounds abstractBounds)
 {
     this.abstractBounds = abstractBounds;
 }
Exemplo n.º 7
0
 void OnEnable()
 {
     abstractBounds = target as AbstractBounds;
 }