/* * private static void OnHierarchyWindowItemOnGUI(int instanceID, Rect selectionRect) * { * Event e = Event.current; * if (e.type == EventType.DragExited) * { * Debug.Log(e.type); * DragAndDrop.visualMode = DragAndDropVisualMode.Copy; * * DragAndDrop.AcceptDrag(); * for (int i = 0; i < DragAndDrop.objectReferences.Length; i++) * { * UnityEngine.Object handleObj = DragAndDrop.objectReferences[i]; * if (handleObj != null) * { * * string path = UnityEditor.AssetDatabase.GetAssetPath(handleObj); * GameObject go = handleObj as GameObject; * * Debug.Log(path); * } * } * * } * * } */ /* * private static void OnSceneGUI(SceneView sceneView) * { * Event e = Event.current; * if (e.type == EventType.DragUpdated || e.type == EventType.DragPerform) * { * DragAndDrop.visualMode = DragAndDropVisualMode.Copy; * if (e.type == EventType.DragPerform) * { * DragAndDrop.AcceptDrag(); * for (int i = 0; i < DragAndDrop.objectReferences.Length; i++) * { * UnityEngine.Object handleObj = DragAndDrop.objectReferences[i]; * if (handleObj != null) * { * * string path = UnityEditor.AssetDatabase.GetAssetPath(handleObj); * Debug.Log(path); * } * } * } * * } * } */ static void OnHierarchyChanged() { STSceneGroup[] groups = FindObjectsOfType <STSceneGroup>(); for (int i = 0; i < groups.Length; ++i) { for (int j = 0; j < groups[i].transform.childCount; ++j) { Transform child = groups[i].transform.GetChild(j); STComponent component = child.GetComponent <STComponent>(); if (component == null) { var targetPrefab = PrefabUtility.GetCorrespondingObjectFromSource(child.gameObject) as GameObject; if (targetPrefab) { string path = AssetDatabase.GetAssetPath(targetPrefab); STSceneEntity entity = AddSTComponentToGroup <STSceneEntity>(groups[i]); entity.transform.position = child.position; entity.transform.localRotation = child.localRotation; entity.transform.localScale = child.localScale; child.SetParent(entity.transform); entity.path = path; child.localPosition = Vector3.zero; child.localRotation = Quaternion.identity; child.localScale = Vector3.one; string assetName = System.IO.Path.GetFileNameWithoutExtension(path); entity.name = typeof(STSceneEntity).Name + "+" + assetName; } } } } }
private void AutoCreateSceneEntity() { Vector3 size = mTarget.bounds.size * 0.5f; for (int i = 0; i < 300; i++) { float x = new System.Random(Guid.NewGuid().GetHashCode()).Next(-(int)size.x, (int)size.x); float z = new System.Random(Guid.NewGuid().GetHashCode()).Next(-(int)size.z, (int)size.z); GameObject go = new GameObject("entity-" + (mTarget.attribute.components.Count + 1)); go.transform.SetParent(mTarget.transform); go.transform.localPosition = new Vector3(x, 0, z); go.transform.localRotation = Quaternion.identity; go.transform.localScale = Vector3.one; STSceneEntity entity = go.AddComponent <STSceneEntity>(); int scale = new System.Random(Guid.NewGuid().GetHashCode()).Next(1, 4); entity.attribute.bounds.size = (new Vector3(scale, mTarget.attribute.treeType == SeparateTreeType.QuadTree?0: scale, scale)); string prefab = "Capsule"; float y = scale; if (i % 3 == 1) { prefab = "Cube"; y = scale * 0.5f; } else if (i % 3 == 2) { prefab = "Sphere"; y = scale * 0.5f; } entity.attribute.path = "Prefabs/" + prefab; entity.attribute.localScale = Vector3.one * scale; entity.attribute.localPosition = new Vector3(0, y, 0); mTarget.AddSTComponent(entity); } }
void OnEnable() { mTarget = target as STSceneEntity; }