예제 #1
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
        }
예제 #2
0
        public static VisualPart Create(Transform parent, string name = "visual part")
        {
            HUtils.log();

#if UNITY_EDITOR
            GameObject go = new GameObject(name);
            UnityEditor.Undo.RegisterCreatedObjectUndo(go, "Created Floorplan GameObject");
            UnityEditor.Undo.SetTransformParent(go.transform, parent, "Parent New Floorplan GameObject");
            go.transform.localPosition = Vector3.zero;
            go.transform.localRotation = Quaternion.identity;

            BuildRPart part = go.GetComponent <BuildRPart>();
            if (part == null)
            {
                part = UnityEditor.Undo.AddComponent <BuildRPart>(go);
            }

            part.parent = parent.GetComponent <BuildRPart>();

            VisualPart output = UnityEditor.Undo.AddComponent <VisualPart>(go);

            return(output);
#else
            GameObject go = new GameObject(name);
            go.transform.parent = parent;

            BuildRPart part = go.GetComponent <BuildRPart>();
            if (part == null)
            {
                part = go.AddComponent <BuildRPart>();
            }

            part.parent = parent.GetComponent <BuildRPart>();

            VisualPart output = go.AddComponent <VisualPart>();

            return(output);
#endif
        }
예제 #3
0
        public static Floorplan Create(Transform transform)
        {
#if UNITY_EDITOR
            GameObject newFloorplanGo = new GameObject("Floorplan");
            UnityEditor.Undo.RegisterCreatedObjectUndo(newFloorplanGo, "Created Floorplan GameObject");
            UnityEditor.Undo.SetTransformParent(newFloorplanGo.transform, transform, "Parent New Floorplan GameObject");
            newFloorplanGo.transform.localPosition = Vector3.zero;
            newFloorplanGo.transform.localRotation = Quaternion.identity;

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

            return(output);
#else
            GameObject newFloorplanGo = new GameObject("Interior Floorplan");
            newFloorplanGo.transform.parent = transform;

            Floorplan output = newFloorplanGo.AddComponent <Floorplan>();
            output._visualPart = VisualPart.Create(newFloorplanGo.transform, "Interior Floorplan Visual");
            return(output);
#endif
        }
예제 #4
0
        public void GenerateFromDynamicMesh(BuildRMesh overflow = null)
        {
            Debug.Log("VisualPart.cs GenerateFromDynamicMesh :" + overflow);
            HUtils.log();

            if (_dynamicMesh == null)
            {
                _dynamicMesh = new BuildRMesh(DYNAMIC_MESH_NAME);
            }
            if (_mesh == null)
            {
                _mesh = new Mesh();
            }
            if (_filter == null)
            {
#if UNITY_EDITOR
                _filter = UnityEditor.Undo.AddComponent <MeshFilter>(gameObject);
#else
                _filter = gameObject.AddComponent <MeshFilter>();
#endif
            }
            if (_renderer == null)
            {
#if UNITY_EDITOR
                _renderer = UnityEditor.Undo.AddComponent <MeshRenderer>(gameObject);
#else
                _renderer = gameObject.AddComponent <MeshRenderer>();
#endif
            }
            if (overflow != null)
            {
                _dynamicMesh = overflow;
            }
            _dynamicMesh.Build(_mesh);
            _filter.sharedMesh        = _mesh;
            _renderer.sharedMaterials = _dynamicMesh.materials.ToArray();


            if (_dynamicMesh.hasOverflowed)
            {
                if (_sibling == null)
                {
                    _sibling = Create(transform.parent, name);
                }
                _sibling.GenerateFromDynamicMesh(_dynamicMesh.overflow);
            }
            else
            {
                if (_sibling != null)
                {
                    _sibling.DestroyVisual();
                }
                _sibling = null;
            }

            if (_colliderPart == null)
            {
                _colliderPart = ColliderPart.Create(transform.parent);
            }

            if (_colliderMesh == null)
            {
                _colliderMesh = new BuildRCollider(DYNAMIC_COLLIDER_NAME);
            }
            _colliderPart.GenerateFromColliderMesh(_colliderMesh);
        }