コード例 #1
0
        void CreateVisualObjects()
        {
            CleanUp();

            prevForcedGridCenter   = RealtimeCSG.CSGGrid.ForcedGridCenter;
            prevForcedGridRotation = RealtimeCSG.CSGGrid.ForcedGridRotation;

            sourceSurfaceAlignment      = PrefabSourceAlignment.AlignedFront;
            destinationSurfaceAlignment = PrefabDestinationAlignment.Default;


            visualDragGameObject = new List <GameObject>();

            foreach (var obj in dragGameObjects)
            {
                var copy = CSGPrefabUtility.Instantiate(obj);
                if (!copy)
                {
                    continue;
                }

                copy.name = obj.name;
                visualDragGameObject.Add(copy);
            }
        }
コード例 #2
0
        public static Quaternion FindDragOrientation(Vector3 normal, PrefabSourceAlignment sourceSurfaceAlignment, PrefabDestinationAlignment destinationSurfaceAlignment)
        {
            Quaternion srcRotation;

            switch (sourceSurfaceAlignment)
            {
            default:
            case PrefabSourceAlignment.AlignedFront: srcRotation = Quaternion.LookRotation(Vector3.forward); break;

            case PrefabSourceAlignment.AlignedBack: srcRotation = Quaternion.LookRotation(Vector3.back); break;

            case PrefabSourceAlignment.AlignedLeft: srcRotation = Quaternion.LookRotation(Vector3.right); break;

            case PrefabSourceAlignment.AlignedRight: srcRotation = Quaternion.LookRotation(Vector3.left); break;

            case PrefabSourceAlignment.AlignedTop: srcRotation = Quaternion.LookRotation(Vector3.up, Vector3.forward); break;

            case PrefabSourceAlignment.AlignedBottom: srcRotation = Quaternion.LookRotation(Vector3.down, Vector3.back); break;
            }

            switch (destinationSurfaceAlignment)
            {
            default:
            case PrefabDestinationAlignment.AlignToSurface:
            {
                var tangent = Vector3.up;                         // assume up is up in the world
                var absX    = Mathf.Abs(normal.x);
                var absY    = Mathf.Abs(normal.y);
                var absZ    = Mathf.Abs(normal.z);

                // if our surface is a floor / ceiling then assume up is the axis
                // aligned vector that is most aligned with the camera's up vector
                if (absX <= absY && absX <= absZ && absY > absZ)
                {
                    tangent = GeometryUtility.SnapToClosestAxis(Camera.current.transform.up);
                }

                return(Quaternion.LookRotation(normal, tangent) * srcRotation);
            }

            case PrefabDestinationAlignment.AlignSurfaceUp:
            {
                normal.y = 0;
                normal.Normalize();
                if (normal.sqrMagnitude == 0)
                {
                    normal = GeometryUtility.SnapToClosestAxis(Camera.current ? Camera.current.transform.forward : Vector3.forward);
                }

                var tangent = Vector3.up;                         // assume up is up in the world
                var absX    = Mathf.Abs(normal.x);
                var absY    = Mathf.Abs(normal.y);
                var absZ    = Mathf.Abs(normal.z);

                // if our surface is a floor / ceiling then assume up is the axis
                // aligned vector that is most aligned with the camera's up vector
                if (absX <= absY && absX <= absZ && absY > absZ)
                {
                    tangent = GeometryUtility.SnapToClosestAxis(Camera.current.transform.up);
                }

                return(Quaternion.LookRotation(normal, tangent) * srcRotation);
            }

            case PrefabDestinationAlignment.Default:
            {
                return(Quaternion.identity);
            }
            }
        }
コード例 #3
0
        void CreateVisualObjects(bool inSceneView = false)
        {
            CleanUp();

            prevForcedGridCenter   = RealtimeCSG.CSGGrid.ForcedGridCenter;
            prevForcedGridRotation = RealtimeCSG.CSGGrid.ForcedGridRotation;

            sourceSurfaceAlignment      = PrefabSourceAlignment.AlignedFront;
            destinationSurfaceAlignment = PrefabDestinationAlignment.AlignToSurface;


            visualDragGameObject = new List <GameObject>();

            var foundTransforms = new List <Transform>();

            foreach (var obj in dragGameObjects)
            {
                foundTransforms.AddRange(obj.GetComponentsInChildren <Transform>());
                CSGNode node = obj.GetComponent <CSGNode>();
                if (!node)
                {
                    continue;
                }
                sourceSurfaceAlignment      = node.PrefabSourceAlignment;
                destinationSurfaceAlignment = node.PrefabDestinationAlignment;

                bool createCopyInsteadOfInstance = node && node.PrefabBehaviour == PrefabInstantiateBehaviour.Copy;

                GameObject copy = CSGPrefabUtility.Instantiate(obj, createCopyInsteadOfInstance);
                if (!copy)
                {
                    continue;
                }


                copy.name = obj.name;
                visualDragGameObject.Add(copy);
            }

            ignoreTransforms = new HashSet <Transform>(foundTransforms);

            if (inSceneView)
            {
                var model = SelectionUtility.LastUsedModel;
                if (model && !containsModel)
                {
                    var parent  = model.transform;
                    int counter = 0;
                    foreach (var obj in visualDragGameObject)
                    {
                        if (!obj)
                        {
                            continue;
                        }
                        if (obj.activeSelf)
                        {
                            obj.transform.SetParent(parent, false);
                            obj.transform.SetSiblingIndex(hoverSiblingIndex + counter);
                            counter++;
                        }
                    }
                }
            }
            else
            {
                var parent  = hoverParent;
                int counter = 0;
                foreach (var obj in visualDragGameObject)
                {
                    if (!obj)
                    {
                        continue;
                    }
                    if (obj.activeSelf)
                    {
                        obj.transform.SetParent(parent, false);
                        obj.transform.SetSiblingIndex(hoverSiblingIndex + counter);
                        counter++;
                    }
                }
            }
        }
コード例 #4
0
        void CreateVisualObjects()
        {
            CleanUp();

            //Debug.Log("CreateVisualObjects");
            //prevForceGrid = RealtimeCSG.Grid.ForceGrid;
            prevForcedGridCenter   = RealtimeCSG.Grid.ForcedGridCenter;
            prevForcedGridRotation = RealtimeCSG.Grid.ForcedGridRotation;

            sourceSurfaceAlignment      = PrefabSourceAlignment.AlignedFront;
            destinationSurfaceAlignment = PrefabDestinationAlignment.Default;


            visualDragGameObject = new List <GameObject>();

            foreach (var obj in dragGameObjects)
            {                    /*
                                  *     CSGNode node = obj.GetComponent<CSGNode>();
                                  *     if (node == null)
                                  *             continue;
                                  *     sourceSurfaceAlignment = node.PrefabSourceAlignment;
                                  *     destinationSurfaceAlignment = node.PrefabDestinationAlignment;
                                  */
                GameObject copy; /*
                                  * if (node && node.PrefabBehaviour == PrefabInstantiateBehaviour.Copy)
                                  * {
                                  * copy = GameObject.Instantiate<GameObject>(obj);
                                  * } else*/
                {
                    copy = PrefabUtility.InstantiatePrefab(obj) as GameObject;
                }
                if (!copy)
                {
                    continue;
                }

                copy.name = obj.name;
                visualDragGameObject.Add(copy);
            }

            var model = SelectionUtility.LastUsedModel;

            if (model != null)
            {
                var parent  = model.transform;
                int counter = 0;
                foreach (var obj in visualDragGameObject)
                {
                    if (obj == null || !obj)
                    {
                        continue;
                    }
                    if (obj.activeSelf)
                    {
                        obj.transform.SetParent(parent, false);
                        obj.transform.SetSiblingIndex(hoverSiblingIndex + counter);
                        counter++;
                    }
                }
            }
        }