Esempio n. 1
0
        public WallSection GetGroundWallSection(int x, int facadeWidth)
        {
            HUtils.log();

            switch (_patternAnchors)
            {
            case PatternAnchors.Left:
                //no need to modify XY
                break;

            case PatternAnchors.Right:
                int diff = baseWidth - facadeWidth;
                x = (x + diff) % baseWidth;
                break;

            case PatternAnchors.Middle:
                int facadeMiddle  = Mathf.CeilToInt(facadeWidth / 2f);
                int patternMiddle = Mathf.CeilToInt(baseWidth / 2f);
                int midDiff       = patternMiddle - facadeMiddle;
                x = (x + midDiff) % baseWidth;
                break;
            }
            while (x < 0)
            {
                x += Mathf.Max(1, baseWidth);
            }
            return(GetGroundWallSection(x));
        }
Esempio n. 2
0
        public static Facade CreateFacade(string name = null, string directory = null)
        {
            HUtils.log();
            Debug.Log("调用了Facade.cs CreateFacade(string name = null, string directory = null) name=" + name + "  directory=" + directory);
            Facade newFacade = CreateInstance <Facade>();

            if (Application.isPlaying)
            {
                return(newFacade);
            }
            if (name != null)
            {
                newFacade.name = name;
            }
#if UNITY_EDITOR
            if (directory == null)
            {
                UnityEditor.AssetDatabase.CreateAsset(newFacade, AssetCreator.GeneratePath("newFacade.asset", "Facades"));
            }
            else
            {
                UnityEditor.AssetDatabase.CreateAsset(newFacade, Path.Combine(directory, "newFacade.asset"));
            }
#endif
            return(newFacade);
        }
Esempio n. 3
0
        public List <VolumePoint> GetMovedPoints()
        {
            HUtils.log();

            List <VolumePoint> output = new List <VolumePoint>();

            for (int i = 0; i < numberOfPoints; i++)
            {
                if (this[i].moved)
                {
                    bool canMakeMove = true;
                    for (int j = 0; j < numberOfPoints; j++)
                    {
                        if (i == j)
                        {
                            continue;
                        }
                        if (this[i].position == this[j].position)
                        {
                            canMakeMove = false;
                            break;
                        }
                    }
                    if (canMakeMove)
                    {
                        output.Add(_points[i]);
                    }
                    else
                    {
                        _points[i].MoveBack();
                    }
                }
            }
            return(output);
        }
Esempio n. 4
0
        public void RemoveAt(int index)
        {
            HUtils.log();
            Debug.Log("移动了索引第 " + index + " 个的WallSection");

            content.RemoveAt(index);
        }
Esempio n. 5
0
        public static Volume Create(Transform transform)
        {
            HUtils.log();
            Debug.Log("Create(Transform transform) transform=" + transform.name);
#if UNITY_EDITOR
            Debug.Log("这里是Volume.cs UNITY_EDITOR存在");
            GameObject newVolumeGO = new GameObject("Volume");
            UnityEditor.Undo.RegisterCreatedObjectUndo(newVolumeGO, "Created Volume GameObject");
            UnityEditor.Undo.SetTransformParent(newVolumeGO.transform, transform, "Parent New Volume GameObject");
            newVolumeGO.transform.localPosition = Vector3.zero;
            newVolumeGO.transform.localRotation = Quaternion.identity;

            Volume output = UnityEditor.Undo.AddComponent <Volume>(newVolumeGO);
            output._visualPart = VisualPart.Create(newVolumeGO.transform, "Volume Visual");

            output._prefabs = new GameObject("Prefabs");
            UnityEditor.Undo.RegisterCreatedObjectUndo(output._prefabs, "Created Volume Prefab GameObject");
            UnityEditor.Undo.SetTransformParent(output._prefabs.transform, newVolumeGO.transform, "Parent New Volume Prefab GameObject");

            output.CheckInternalFloorplans();

            return(output);
#else
            Debug.Log("这里是Volume.cs UNITY_EDITOR不存在");

            GameObject newFloorplanGo = new GameObject("Volume");
            newFloorplanGo.transform.parent = transform;

            Volume output = newFloorplanGo.AddComponent <Volume>();
            output._visualPart = VisualPart.Create(newFloorplanGo.transform, "Volume Visual");

            return(output);
#endif
        }
Esempio n. 6
0
        public void Init()
        {
            HUtils.log();

            if (_mesh == null)
            {
                _mesh = new Mesh();
            }
            if (_filter == null)
            {
                _filter = gameObject.AddComponent <MeshFilter>();
            }
            if (_renderer == null)
            {
                _renderer = gameObject.AddComponent <MeshRenderer>();
            }
            if (_dynamicMesh == null)
            {
                _dynamicMesh = new BuildRMesh(DYNAMIC_MESH_NAME);
            }
            if (_colliderMesh == null)
            {
                _colliderMesh = new BuildRCollider(DYNAMIC_COLLIDER_NAME);
            }
        }
Esempio n. 7
0
        public void GenerateRuntimeMesh()
        {
            HUtils.log();

//		    Debug.Log("GenerateRuntimeMesh");
            if (!isLegal)
            {
                Debug.LogWarning("Illegal Runtime Volume. Base points likely intersect");
                for (int p = 0; p < numberOfPoints; p++)
                {
                    Debug.Log(this[p].position.vector3XY);
                }
            }
            if (visualPart == null)
            {
                _visualPart = VisualPartRuntime.GetPoolItem();
            }
            _visualPart.GenerateFromDynamicMesh();
            for (int f = 0; f < _interiorFloorplans.Count; f++)
            {
                _interiorFloorplans[f].GenerateRuntimeMesh();
                _interiorFloorplans[f].transform.parent        = transform;
                _interiorFloorplans[f].transform.localPosition = Vector3.zero;
            }
        }
Esempio n. 8
0
        public static void VolumeSelectorInspectorGUI()
        {
            HUtils.log();
            Debug.Log("这里也能调用得到吗?");

            int floorplanCount = building.numberOfPlans;

            if (floorplanCount > 0)
            {
                EditorGUILayout.LabelField("Volumes");
            }
            if (floorplanCount > 10)
            {
                volumeScroll = EditorGUILayout.BeginScrollView(volumeScroll, false, true, GUILayout.Width(MAIN_GUI_WIDTH), GUILayout.Height(150));
            }
            EditorGUILayout.BeginHorizontal(GUILayout.Width(MAIN_GUI_WIDTH));
            string[] floorplanNames = new string[floorplanCount];
            for (int p = 0; p < floorplanCount; p++)
            {
                floorplanNames[p] = building[p].name;
            }
            int currentIndex = building.IndexOf(volume);

            int newIndex = GUILayout.SelectionGrid(currentIndex, floorplanNames, 2);

            EditorGUILayout.EndHorizontal();
            if (newIndex != currentIndex)
            {
                volume = (Volume)building[newIndex];
            }
        }
Esempio n. 9
0
        public void PointModified(List <VolumePoint> data)
        {
            HUtils.log();

            int dataCount = data.Count;

            if (data.Count == 0)
            {
                return;
            }
            int pointCount = numberOfPoints;

            for (int d = 0; d < dataCount; d++)
            {
                VolumePoint point = data[d];
                if (!point.moved)
                {
                    continue;
                }
                for (int p = 0; p < pointCount; p++)
                {
                    if (point.lastPosition == _points[p].position)
                    {
                        _points[p].position = point.position;
                        _points[p].MarkUnmodified();
                    }
                }
            }
            if (isModified)
            {
                MarkModified();
            }
        }
Esempio n. 10
0
        public virtual void MarkModified()
        {
            HUtils.log();

            if (!BuildRSettings.AUTO_UPDATE)
            {
                return;
            }
            _isModified = true;
            _regenerate = true;
            if (_rGen == null)
            {
                _rGen = new RandomGen();
            }
            _rGen.seed = seed;
            IVolume modifiedPlan = GetModifiedPlan();

            if (modifiedPlan != null)
            {
                //                CheckPlanHeights();
                CheckPointMovements(modifiedPlan);
                CheckBuildingLegality();
            }
            SaveData();
            MarkUnmodified();
        }
Esempio n. 11
0
        public int VolumeBaseFloor(IVolume vol)
        {
            HUtils.log();

            int volumeCount = _volumes.Count;
            int output      = 0;

            //            Debug.Log("VolumeBaseFloor "+vol.name);
            for (int v = 0; v < volumeCount; v++)
            {
                IVolume other = _volumes[v];
                if (other == vol)
                {
                    continue;
                }
                if (other.ContainsPlanAbove(vol))
                {//start the loop again - register the floors below current plan - use parent plan to find other parents
                    v       = -1;
                    vol     = other;
                    output += vol.floors;
                    //                    Debug.Log("above plan "+ vol.name);
                }
            }
            //            Debug.Log("VolumeBaseFloor is " + output);
            return(output);
        }
Esempio n. 12
0
        public void SetGroundWallSection(int x, WallSection newWallSection)
        {
            HUtils.log();

            x = x % _baseWidth;
            _groundFloorPattern[x] = newWallSection;
            MarkModified();
        }
Esempio n. 13
0
        public WallSection GetBaseWallSection(int x, int y, int facadeWidth, int facadeHeight)
        {
            HUtils.log();

            if (_hasGroundFloorPattern && y > 0)
            {
                y += -1;
            }
            int anchoredX = x;

            switch (_patternAnchors)
            {
            case PatternAnchors.Left:
                //no need to modify XY
                break;

            case PatternAnchors.Right:
                int diff = baseWidth - facadeWidth;
                while (diff < 0 && baseWidth > 0)
                {
                    diff += baseWidth;
                }
                anchoredX = (x + diff) % baseWidth;
                //	                Debug.Log("fAnc "+anchoredX+" "+ diff+" "+ baseWidth+" "+ facadeWidth);
                break;

            case PatternAnchors.Middle:
                int facadeMiddle  = Mathf.CeilToInt(facadeWidth / 2f);
                int patternMiddle = Mathf.CeilToInt(baseWidth / 2f);
                int midDiff       = patternMiddle - facadeMiddle;
                anchoredX += midDiff;
                break;
            }

            switch (stretchMode)
            {
            case StretchModes.Wrap:
                while (anchoredX < 0)
                {
                    anchoredX += Mathf.Max(1, baseWidth);
                }
                x = anchoredX % _baseWidth;
                y = y % _baseHeight;
                break;

            case StretchModes.Clamp:
                x = Mathf.Clamp(anchoredX, 0, _baseWidth - 1);
                y = Mathf.Clamp(y, 0, _baseHeight - 1);
                break;

            case StretchModes.Fit:
                x = Mathf.RoundToInt(_baseWidth * (x / (float)facadeWidth));
                y = Mathf.RoundToInt(_baseHeight * (y / (float)facadeHeight));
                break;
            }

            return(GetBaseWallSection(x, y));
        }
Esempio n. 14
0
        public void SetBaseWallSection(int x, int y, WallSection newWallSection)
        {
            HUtils.log();

            x = x % _baseWidth;
            y = y % _baseHeight;
            _basePattern[x][y] = newWallSection;
            MarkModified();
        }
Esempio n. 15
0
 public void MarkModified()
 {
     HUtils.log();
     //Debug.Log("Facade.cs MarkModified()");
     UpdatePreviewTexture();
     LoadPreviewTexture();
     UpdateUsedWallsectionList();
     SaveData();
 }
Esempio n. 16
0
 public void Place(Vector3 position)
 {
     transform.position = position;
     if (_sibling != null)
     {
         _sibling.Move(position);
     }
     HUtils.log();
 }
Esempio n. 17
0
        public void AddPoint(Vector2Int newPosition)
        {
            HUtils.log();
            Debug.Log("Volume.cs AddPoint(Vector2Int newPosition) newPosition=(" + newPosition.x + "," + newPosition.y + ")");
            VolumePoint newPoint = new VolumePoint(newPosition);

            _points.Add(newPoint);
            CheckVolume();
            MarkModified();
        }
Esempio n. 18
0
        public void SetFacade(int index, Facade value)
        {
            HUtils.log();

            if (_points[index].facade != value)
            {
                _points[index].facade = value;
                MarkModified();
            }
        }
Esempio n. 19
0
        public WallSection GetWallSection(int x, int y, int facadeWidth, int facadeHeight)
        {
            HUtils.log();

            if (_hasGroundFloorPattern && y == 0)
            {
                return(GetGroundWallSection(x, facadeWidth));
            }
            return(GetBaseWallSection(x, y, facadeWidth, facadeHeight));
        }
Esempio n. 20
0
        public WallSection GetWallSection(int x, int y)
        {
            HUtils.log();


            if (_hasGroundFloorPattern && y == 0)
            {
                return(GetGroundWallSection(x));
            }
            return(GetBaseWallSection(x, y));
        }
Esempio n. 21
0
        public void SetControlPointB(int index, Vector2Int value)
        {
            HUtils.log();

            if (_points[index].controlB != value)
            {
                //                _modifiedControlPointsB.Add(new PointModification(_controlPointsB[index], value));
                _points[index].controlB = value;
                MarkModified();
            }
        }
Esempio n. 22
0
        public void AddPoints(Vector3[] newPoints)
        {
            HUtils.log();

            for (int i = 0; i < newPoints.Length; i++)
            {
                AddPoint(newPoints[i]);
            }
            CheckVolume();
            MarkModified();
        }
Esempio n. 23
0
        public static Building CreateNewBuilding()
        {
            HUtils.log();

            GameObject newBuildingGO = new GameObject("NewBuilding");
            Building   newBuilding   = newBuildingGO.AddComponent <Building>();
            Visual     visual        = newBuildingGO.AddComponent <Visual>();

            visual.building = newBuilding;
            //todo Add support to create prefab here
            return(newBuilding);
        }
Esempio n. 24
0
        public void GenerateFromDynamicMesh(BuildRMesh overflow = null)
        {
            HUtils.log();

            if (_dynamicMesh.vertexCount == 0)
            {
                return;
            }
            if (_mesh == null)
            {
                _mesh = new Mesh();
            }
            if (_filter == null)
            {
                _filter = gameObject.AddComponent <MeshFilter>();
            }
            if (_renderer == null)
            {
                _renderer = gameObject.AddComponent <MeshRenderer>();
            }
            if (overflow != null)
            {
                _dynamicMesh = overflow;
            }
            _dynamicMesh.Build(_mesh);
            _filter.sharedMesh        = _mesh;
            _renderer.sharedMaterials = _dynamicMesh.materials.ToArray();


            if (_dynamicMesh.hasOverflowed)
            {
                if (_sibling == null)
                {
                    _sibling = GetPoolItem();
                }
                _sibling.GenerateFromDynamicMesh(_dynamicMesh.overflow);
            }
            else
            {
                if (_sibling != null)
                {
                    _sibling.Deactivate();
                    VisualPartRuntimePool.Instance.Push(_sibling);
                }
                _sibling = null;
            }

            if (_colliderPart == null)
            {
                _colliderPart = ColliderPartRuntime.GetPoolItem();
                _colliderPart.GenerateFromColliderMesh(_colliderMesh);
            }
        }
Esempio n. 25
0
        public void Activate()
        {
            HUtils.log();

            if (_renderer == null)
            {
                _renderer = gameObject.AddComponent <MeshRenderer>();
            }
            _renderer.enabled = true;
            if (_sibling != null)
            {
                _sibling.Activate();
            }
        }
Esempio n. 26
0
        public List <VolumePoint> GetModifiedPoints()
        {
            HUtils.log();
            List <VolumePoint> output = new List <VolumePoint>();

            for (int i = 0; i < numberOfPoints; i++)
            {
                if (this[i].modified)
                {
                    output.Add(_points[i]);
                }
            }
            return(output);
        }
Esempio n. 27
0
        public void HeightModified(IVolume subject)
        {
            HUtils.log();

            if (subject == this)
            {
                int linkedPlanCount = linkedPlans.Count;
                for (int l = 0; l < linkedPlanCount; l++)
                {
                    IVolume volume = linkedPlans[l];
                    if (volume == null)
                    {
                        linkedPlans.RemoveAt(l);
                        linkedPlanCount--;
                        l--;
                        continue;
                    }
                    volume.HeightModified(this);
                }
            }
            else
            {
                if (linkedPlans.Contains(subject))
                {
                    _floorHeight = subject.floorHeight;
                    _floors      = subject.floors;
                }
                else
                {
                    baseHeight = subject.planTotalHeight;
                }
            }

            int abovePlanCount = abovePlans.Count;

            for (int a = 0; a < abovePlanCount; a++)
            {
                IVolume volume = abovePlans[a];
                if (volume == null)
                {
                    abovePlans.RemoveAt(a);
                    abovePlanCount--;
                    a--;
                    continue;
                }
                volume.HeightModified(this);
            }
            MarkModified();
        }
Esempio n. 28
0
        public Matrix4x4 ShutterMeshPositionRight(Vector2 size, float wallThickness)
        {
            HUtils.log();

            Matrix4x4 output           = new Matrix4x4();
            float     useOpeningWidth  = openingWidth;
            float     useOpeningHeight = openingHeight;
            float     wallThicknessRat = wallThickness / size.y;

            size.y += -wallThickness;
            if (dimensionType == DimensionTypes.Relative)
            {
                useOpeningWidth  = useOpeningWidth * size.x;
                useOpeningHeight = useOpeningHeight * size.y;
            }
            float width  = useOpeningWidth * 0.5f;
            float height = useOpeningHeight;

            float widthOffset  = 0;
            float heightOffset = 0;

            widthOffset += -width * (shutterModel.modelBounds.center.x / shutterModel.modelBounds.size.x);
            widthOffset += (size.x - useOpeningWidth) * (_openingWidthRatio - 0.5f);

            heightOffset += -height * (shutterModel.modelBounds.center.y / shutterModel.modelBounds.size.y);
            heightOffset += -size.y * wallThicknessRat * 0.5f;
            heightOffset += (size.y - useOpeningHeight) * (_openingHeightRatio - 0.5f);

            Vector3 center = new Vector3(useOpeningWidth * 0.75f + widthOffset, heightOffset, 0);

            float depth = shutterModel.modelBounds.size.z;

            depth *= width / Mathf.Min(shutterModel.modelBounds.size.x, shutterModel.modelBounds.size.y);

            Vector3 balPos = Vector3.zero;//new Vector3(placeModelBounds.max.z);

            balPos.x = center.x;
            balPos.y = center.y;
            balPos.z = 0;
            Quaternion balRot = Quaternion.Euler(0, 180, 0) * shutterModel.userRotationQuat;
            Vector3    balScl = new Vector3(-1, 1, 1);

            balScl.x = width / shutterModel.modelBounds.size.x;
            balScl.y = height / shutterModel.modelBounds.size.y;
            balScl.z = depth / shutterModel.modelBounds.size.z;

            output.SetTRS(balPos, balRot, balScl);
            return(output);
        }
Esempio n. 29
0
        public Matrix4x4 BalconyMeshPosition(Vector2 size, float wallThickness)
        {
            HUtils.log();

            Matrix4x4 output           = new Matrix4x4();
            float     useOpeningWidth  = openingWidth;
            float     useOpeningHeight = openingHeight;
            float     wallThicknessRat = wallThickness / size.y;

            size.y += -wallThickness;
            if (dimensionType == DimensionTypes.Relative)
            {
                useOpeningWidth  = useOpeningWidth * size.x;
                useOpeningHeight = useOpeningHeight * size.y;
            }
            float width  = useOpeningWidth + balconySideOverhang * 2;
            float height = useOpeningHeight * balconyHeight;

            float widthOffset  = 0;
            float heightOffset = 0;

            widthOffset += -width * (balconyModel.modelBounds.center.x / balconyModel.modelBounds.size.x);
            widthOffset += (size.x - useOpeningWidth) * (_openingWidthRatio - 0.5f);

            heightOffset += -height * (balconyModel.modelBounds.center.y / balconyModel.modelBounds.size.y);
            heightOffset += -size.y * wallThicknessRat * 0.5f;
            heightOffset += (size.y - useOpeningHeight) * (_openingHeightRatio - 0.5f);

            Vector3 center = new Vector3(widthOffset, (-useOpeningHeight + height) * 0.5f + heightOffset, 0);

            float depth = balconyModel.modelBounds.size.z;

            depth *= width / balconyModel.modelBounds.size.x;

            Vector3 balPos = Vector3.zero;//new Vector3(placeModelBounds.max.z);

            balPos.x = center.x;
            balPos.y = center.y;
            balPos.z = -depth * 0.5f;
            Quaternion balRot = Quaternion.Euler(0, 180, 0) * balconyModel.userRotationQuat;
            Vector3    balScl = Vector3.one;

            balScl.x = width / balconyModel.modelBounds.size.x;
            balScl.y = height / balconyModel.modelBounds.size.y;
            balScl.z = depth / balconyModel.modelBounds.size.z;

            output.SetTRS(balPos, balRot, balScl);
            return(output);
        }
Esempio n. 30
0
        public Matrix4x4 OpeningMeshPosition(Vector2 size, float wallThickness)
        {
            HUtils.log();

            Matrix4x4 output           = new Matrix4x4();
            float     useOpeningWidth  = openingWidth;
            float     useOpeningHeight = openingHeight;
            float     wallThicknessRat = wallThickness / size.y;

            size.y += -wallThickness;
            if (dimensionType == DimensionTypes.Relative)
            {
                useOpeningWidth  = useOpeningWidth * size.x;
                useOpeningHeight = useOpeningHeight * size.y;
            }
            float width  = useOpeningWidth;
            float height = useOpeningHeight;

            float widthOffset  = 0;
            float heightOffset = 0;

            widthOffset += -width * (openingModel.userBounds.center.x / openingModel.userBounds.size.x);
            widthOffset += (size.x - useOpeningWidth) * (_openingWidthRatio - 0.5f);

            heightOffset += -height * (openingModel.userBounds.center.y / openingModel.userBounds.size.y);
            heightOffset += -size.y * wallThicknessRat * 0.5f;
            heightOffset += (size.y - useOpeningHeight) * (_openingHeightRatio - 0.5f);

            Vector3 center = new Vector3(widthOffset, heightOffset, 0);

            float depth = openingModel.userBounds.size.z;

            depth *= width / Mathf.Min(openingModel.userBounds.size.x, openingModel.userBounds.size.y);

            Vector3 balPos = Vector3.zero;

            balPos.x = center.x;
            balPos.y = center.y;
            balPos.z = openingDepth;
            Quaternion balRot = Quaternion.Euler(0, 0, 0) * openingModel.userRotationQuat;
            Vector3    balScl = Vector3.one;

            balScl.x = width / openingModel.userBounds.size.x;
            balScl.y = height / openingModel.userBounds.size.y;
            balScl.z = depth / openingModel.userBounds.size.z;

            output.SetTRS(balPos, balRot, balScl);
            return(output);
        }