public bool ValidateDrop(SceneView sceneView) { if (!sceneView) { return(false); } Reset(); if (DragAndDrop.objectReferences == null || DragAndDrop.objectReferences.Length == 0) { dragGameObjects = null; return(false); } dragGameObjects = new List <GameObject>(); containsModel = false; foreach (var obj in DragAndDrop.objectReferences) { var gameObject = obj as GameObject; if (gameObject == null) { continue; } if (gameObject.GetComponent <CSGNode>() == null) { continue; } if (gameObject.GetComponentsInChildren <CSGBrush>() == null) { continue; } if (!CSGPrefabUtility.IsPrefabAsset(gameObject)) { continue; } dragGameObjects.Add(gameObject); containsModel = containsModel || (gameObject.GetComponent <CSGModel>() != null); } if (dragGameObjects.Count != 1) { dragGameObjects = null; return(false); } var dragGameObjectBounds = new AABB(); dragGameObjectBounds.Reset(); foreach (var gameObject in dragGameObjects) { var brushes = gameObject.GetComponentsInChildren <CSGBrush>(); if (brushes.Length == 0) { continue; } dragGameObjectBounds.Add(BoundsUtilities.GetLocalBounds(brushes, gameObject.transform.worldToLocalMatrix)); } if (!dragGameObjectBounds.Valid) { dragGameObjectBounds.Extend(MathConstants.zeroVector3); } projectedBounds = new Vector3[8]; BoundsUtilities.GetBoundsCornerPoints(dragGameObjectBounds, projectedBounds); haveNoParent = false; return(true); }
public override bool ValidateDrop(bool inSceneView) { if (!inSceneView) { return(false); } Reset(); if (DragAndDrop.objectReferences == null || DragAndDrop.objectReferences.Length == 0) { dragGameObjects = null; return(false); } dragGameObjects = new List <GameObject>(); containsModel = false; foreach (var obj in DragAndDrop.objectReferences) { var gameObject = obj as GameObject; if (gameObject == null) { continue; } if (gameObject.GetComponentInChildren <CSGBrush>() == null) { continue; } if (PrefabUtility.GetPrefabType(gameObject) == PrefabType.None) { continue; } if (PrefabUtility.GetPrefabParent(gameObject) == null && PrefabUtility.GetPrefabObject(gameObject) != null) { dragGameObjects.Add(gameObject); } containsModel = containsModel || (gameObject.GetComponent <CSGModel>() != null); } if (dragGameObjects.Count != 1) { dragGameObjects = null; return(false); } var dragGameObjectBounds = new AABB(); dragGameObjectBounds.Reset(); foreach (var gameObject in dragGameObjects) { var brushes = gameObject.GetComponentsInChildren <CSGBrush>(); if (brushes.Length == 0) { continue; } dragGameObjectBounds.Add(BoundsUtilities.GetLocalBounds(brushes, gameObject.transform.worldToLocalMatrix)); } if (!dragGameObjectBounds.Valid) { dragGameObjectBounds.Extend(MathConstants.zeroVector3); } projectedBounds = new Vector3[8]; BoundsUtilities.GetBoundsCornerPoints(dragGameObjectBounds, projectedBounds); /* * var upPlane = new Plane(MathConstants.upVector3, MathConstants.zeroVector3); * for (int i = 7; i >= 0; i--) * { * projectedBounds[i] = upPlane.Project(projectedBounds[i]); * for (int j = i+1; j < projectedBounds.Length; j++) * { * if (projectedBounds[i] == projectedBounds[j]) * { * ArrayUtility.RemoveAt(ref projectedBounds, j); * break; * } * } * }*/ haveNoParent = false; return(true); }