protected override void OnAddItem(SerializedProperty prop, UnityEngine.Object obj) { base.OnAddItem(prop, obj); var coordinate = prop.FindPropertyRelative("coordinate"); ActionEditorUtility.SaveCoordinatesInfo(coordinate, (obj as GameObject).transform); }
private void RecordPrefab(Object obj) { var path = AssetDatabase.GetAssetPath(obj); var guid = AssetDatabase.AssetPathToGUID(path); guidProp.stringValue = guid; if (string.IsNullOrEmpty(enviromentNameProp.stringValue)) { enviromentNameProp.stringValue = obj.name; } if (coordinateProp.FindPropertyRelative("localScale").vector3Value == Vector3.zero) { ActionEditorUtility.SaveCoordinatesInfo(coordinateProp, (obj as GameObject).transform); } }
public override void DoLayoutList() { base.DoLayoutList(); var rect = ActionGUIUtil.GetDragRect(); if (Event.current.type == EventType.DragUpdated && rect.Contains(Event.current.mousePosition)) { ActionGUIUtil.UpdateDragedObjects(".prefab", dragedObjects); } else if (Event.current.type == EventType.DragPerform && rect.Contains(Event.current.mousePosition)) { foreach (var item in dragedObjects) { var path = AssetDatabase.GetAssetPath(item); if (string.IsNullOrEmpty(path)) { return; } var guid = AssetDatabase.AssetPathToGUID(path); if (!ActionEditorUtility.HaveElement(property, "guid", guid)) { var prop = property.AddItem(); var guidProp = prop.FindPropertyRelative("guid"); var enviromentNameProp = prop.FindPropertyRelative("enviromentName"); var coordinateProp = prop.FindPropertyRelative("coordinate"); guidProp.stringValue = guid; enviromentNameProp.stringValue = item.name; ActionEditorUtility.SaveCoordinatesInfo(coordinateProp, (item as GameObject).transform); } else { EditorUtility.DisplayDialog("警告", "预制体重复,无法添加:" + item.name, "ok"); } } } }
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { elementNameProp = property.FindPropertyRelative("enviromentName"); guidProp = property.FindPropertyRelative("guid"); instenceIDProp = property.FindPropertyRelative("instenceID"); enviromentNameProp = property.FindPropertyRelative("enviromentName"); coordinateProp = property.FindPropertyRelative("coordinate"); var btnRect = new Rect(position.x, position.y, position.width - ActionGUIUtil.middleButtonWidth, EditorGUIUtility.singleLineHeight); if (instenceIDProp.intValue != 0 && EditorUtility.InstanceIDToObject(instenceIDProp.intValue) == null) { instenceIDProp.intValue = 0; property.isExpanded = false; } if (!string.IsNullOrEmpty(guidProp.stringValue) && string.IsNullOrEmpty(AssetDatabase.GUIDToAssetPath(guidProp.stringValue))) { guidProp.stringValue = null; } if (GUI.Button(btnRect, elementNameProp.stringValue, EditorStyles.toolbarDropDown)) { property.isExpanded = !property.isExpanded; if (property.isExpanded) { ActionEditorUtility.LoadPrefab(guidProp.stringValue, instenceIDProp, coordinateProp); } else { ActionEditorUtility.SavePrefab(instenceIDProp, coordinateProp); } } var objRect = new Rect(position.x + position.width - ActionGUIUtil.middleButtonWidth, position.y, ActionGUIUtil.middleButtonWidth, EditorGUIUtility.singleLineHeight); if (!string.IsNullOrEmpty(guidProp.stringValue)) { if (GUI.Button(objRect, "", EditorStyles.objectFieldMiniThumb)) { GameObject prefab = AssetDatabase.LoadAssetAtPath <GameObject>(AssetDatabase.GUIDToAssetPath(guidProp.stringValue)); EditorGUIUtility.PingObject(prefab); } if (Event.current.type == EventType.DragUpdated && objRect.Contains(Event.current.mousePosition)) { ActionGUIUtil.UpdateDragedObjects <GameObject>(".prefab", dragedGameObjs); } else if (Event.current.type == EventType.DragPerform && objRect.Contains(Event.current.mousePosition)) { foreach (var item in dragedGameObjs) { RecordPrefab(item); break; } } } else { var obj = EditorGUI.ObjectField(objRect, null, typeof(GameObject), false); if (obj != null) { RecordPrefab(obj); } } if (instenceIDProp.intValue != 0) { DrawInfo(position); } if (property.isExpanded) { position.y += EditorGUIUtility.singleLineHeight + 2f; EditorGUI.BeginChangeCheck(); ActionGUIUtil.DrawChildInContent(property, position, null, "ignore", -1); if (EditorGUI.EndChangeCheck()) { if (instenceTranform) { ActionEditorUtility.LoadCoordinatePropInfo(coordinateProp, instenceTranform); } } else { if (instenceTranform) { ActionEditorUtility.SaveCoordinatesInfo(coordinateProp, instenceTranform); } } } }
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { FindCommonPropertys(property); prefabProp = property.FindPropertyRelative("prefab"); if (instanceIDProp.intValue != 0 && EditorUtility.InstanceIDToObject(instanceIDProp.intValue) == null) { instanceIDProp.intValue = 0; } if (prefabProp.objectReferenceValue != null) { label = new GUIContent(prefabProp.objectReferenceValue.name); } property.isExpanded = instanceIDProp.intValue != 0; var rect = new Rect(position.x, position.y, position.width * 0.9f, EditorGUIUtility.singleLineHeight); var str = prefabProp.objectReferenceValue == null ? "" : prefabProp.objectReferenceValue.name; GUI.contentColor = ignoreProp.boolValue ? ActionGUIUtil.IgnoreColor : ActionGUIUtil.NormalColor; if (!string.IsNullOrEmpty(ActionGUIUtil.searchWord) && prefabProp.objectReferenceValue != null) { GUI.contentColor = prefabProp.objectReferenceValue.ToString().ToLower().Contains(ActionGUIUtil.searchWord.ToLower()) ? ActionGUIUtil.MatchColor : GUI.contentColor; } if (GUI.Button(rect, str, EditorStyles.toolbarDropDown)) { if (instanceIDProp.intValue == 0) { ActionEditorUtility.LoadPrefab(prefabProp, instanceIDProp, coordinateProp); } else { ActionEditorUtility.SavePrefab(instanceIDProp, coordinateProp); } } GUI.contentColor = Color.white; InformationShow(rect); rect = new Rect(position.max.x - position.width * 0.1f, position.y, 20, EditorGUIUtility.singleLineHeight); switch (Event.current.type) { case EventType.DragUpdated: if (rect.Contains(Event.current.mousePosition)) { DragAndDrop.visualMode = DragAndDropVisualMode.Move; } break; case EventType.DragPerform: if (rect.Contains(Event.current.mousePosition)) { Debug.Log(DragAndDrop.objectReferences.Length); if (DragAndDrop.objectReferences.Length > 0) { var obj = DragAndDrop.objectReferences[0]; if (obj is GameObject) { ActionEditorUtility.InsertPrefab(prefabProp, obj); var coordinate = property.FindPropertyRelative("coordinate"); ActionEditorUtility.SaveCoordinatesInfo(coordinate, (obj as GameObject).transform); } DragAndDrop.AcceptDrag(); } Event.current.Use(); } break; case EventType.DragExited: break; } if (prefabProp.objectReferenceValue != null) { if (GUI.Button(rect, "", EditorStyles.objectFieldMiniThumb)) { EditorGUIUtility.PingObject(prefabProp.objectReferenceValue); } } else { prefabProp.objectReferenceValue = EditorGUI.ObjectField(rect, null, typeof(GameObject), false); } rect = new Rect(position.x, position.y + EditorGUIUtility.singleLineHeight, position.width, EditorGUIUtility.singleLineHeight); if (property.isExpanded) { DrawOptions(rect); } }