private void ToggleLoadPrefab() { if (instanceIDProp.intValue == 0 || EditorUtility.InstanceIDToObject(instanceIDProp.intValue) == null) { ActionEditorUtility.LoadPrefab(prefabProp, instanceIDProp); } else { ActionEditorUtility.SavePrefab(instanceIDProp, true); } }
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) { _name_prop = property.FindPropertyRelative("_name"); prefab_prop = property.FindPropertyRelative("prefab"); instanceID_prop = property.FindPropertyRelative("instanceID"); var nameRect = new Rect(position.x, position.y, position.width * 0.3f, position.height); GUI.contentColor = ActionGUIUtil.NormalColor; if (!string.IsNullOrEmpty(ActionGUIUtil.searchWord)) { GUI.contentColor = _name_prop.stringValue.ToLower().Contains(ActionGUIUtil.searchWord.ToLower()) ? ActionGUIUtil.MatchColor : GUI.contentColor; } _name_prop.stringValue = EditorGUI.TextField(nameRect, _name_prop.stringValue); GUI.contentColor = Color.white; if (string.IsNullOrEmpty(_name_prop.stringValue) && prefab_prop.objectReferenceValue != null) { _name_prop.stringValue = prefab_prop.objectReferenceValue.name; } var showName = "Null"; if (prefab_prop.objectReferenceValue != null) { showName = prefab_prop.objectReferenceValue.name; } var btnRect = new Rect(position.x + position.width * 0.35f, position.y, position.width * 0.6f - buttonWidth, position.height); if (GUI.Button(btnRect, showName, EditorStyles.toolbarDropDown) && prefab_prop.objectReferenceValue) { if (instanceID_prop.intValue == 0) { ActionEditorUtility.LoadPrefab(prefab_prop, instanceID_prop); } else { var instence = EditorUtility.InstanceIDToObject(instanceID_prop.intValue); if (instence) { ActionEditorUtility.SavePrefab(instanceID_prop, true); } } } if (instanceID_prop.intValue != 0 && EditorUtility.InstanceIDToObject(instanceID_prop.intValue) != null) { var labelRect = new Rect(btnRect.x + btnRect.width - 100, btnRect.y, 100, btnRect.height); GUI.contentColor = ActionGUIUtil.WarningColor; EditorGUI.LabelField(labelRect, "开启中"); GUI.contentColor = Color.white; } else { instanceID_prop.intValue = 0; } var objRect = new Rect(position.x + position.width - buttonWidth, position.y, buttonWidth, position.height); if (prefab_prop.objectReferenceValue == null) { prefab_prop.objectReferenceValue = EditorGUI.ObjectField(objRect, prefab_prop.objectReferenceValue, typeof(GameObject), false); } else { if (GUI.Button(objRect, "", EditorStyles.objectFieldMiniThumb)) { EditorGUIUtility.PingObject(prefab_prop.objectReferenceInstanceIDValue); } } }
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); } }