Skip to content

Commit

Permalink
set to disconnect with prefab instance when load an ui prefab
Browse files Browse the repository at this point in the history
  • Loading branch information
liuhaopen committed Apr 24, 2018
1 parent df52b01 commit acba315
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 49 deletions.
4 changes: 0 additions & 4 deletions Assets/UIEditor/Common/Decorate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,12 @@ public string SprPath
public void LoadSpr(string path)
{
InitComponent();
//Debug.Log("path : " + path);
if (spr_path != path)
{
spr_path = path;
_image.sprite = UIEditorHelper.LoadSpriteInLocal(path);
_image.SetNativeSize();
gameObject.name = CommonHelper.GetFileNameByPath(path);
//Debug.Log("_image.sprite :" + (_image.sprite != null).ToString());
}
}

Expand All @@ -46,8 +44,6 @@ protected void InitComponent()
if (_image == null)
_image = GetComponent<Image>();
}


}
}
#endif
16 changes: 7 additions & 9 deletions Assets/UIEditor/Common/UIEditorHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -199,12 +199,12 @@ public static void LoadLayout(object o)

Object prefab = AssetDatabase.LoadAssetAtPath(select_path, typeof(Object));
GameObject new_view = PrefabUtility.InstantiateAttachedAsset(prefab) as GameObject;
PrefabUtility.ReconnectToLastPrefab(new_view);
new_view.transform.parent = new_layout.transform;
new_view.transform.localPosition = Vector3.zero;
string just_name = System.IO.Path.GetFileNameWithoutExtension(select_path);
new_view.name = just_name;
new_layout.gameObject.name = just_name + "_Canvas";
PrefabUtility.DisconnectPrefabInstance(new_view);//链接中的话删里面的子节点时会报警告,所以还是一直失联的好,保存时直接覆盖prefab就行了
}
}

Expand Down Expand Up @@ -289,6 +289,7 @@ public static Texture2D LoadTextureInLocal(string file_path)
}

private static Vector2 HalfVec = new Vector2(0.5f, 0.5f);
//加载外部资源为Sprite
public static Sprite LoadSpriteInLocal(string file_path)
{
Texture2D texture = LoadTextureInLocal(file_path);
Expand All @@ -308,7 +309,7 @@ public static Texture GetAssetPreview(GameObject obj)
//如果是UGUI节点的话就要把它们放在Canvas下了
canvas_obj = new GameObject("render canvas", typeof(Canvas));
Canvas canvas = canvas_obj.GetComponent<Canvas>();
cloneTransform.parent = canvas_obj.transform;
cloneTransform.SetParent(canvas_obj.transform);
cloneTransform.localPosition = Vector3.zero;

canvas_obj.transform.position = new Vector3(-1000, -1000, -1000);
Expand Down Expand Up @@ -337,7 +338,7 @@ public static Texture GetAssetPreview(GameObject obj)
if (isUINode)
{
cameraObj.transform.position = new Vector3((Max.x + Min.x) / 2f, (Max.y + Min.y) / 2f, cloneTransform.position.z-100);
Vector3 center = new Vector3(cloneTransform.position.x, (Max.y + Min.y) / 2f, cloneTransform.position.z);
Vector3 center = new Vector3(cloneTransform.position.x+0.01f, (Max.y + Min.y) / 2f, cloneTransform.position.z);//+0.01f是为了去掉Unity自带的摄像机旋转角度为0的打印,太烦人了
cameraObj.transform.LookAt(center);

renderCamera.orthographic = true;
Expand Down Expand Up @@ -441,15 +442,12 @@ public static void SaveLayout(object o)

//判断选择的物体,是否为预设
PrefabType cur_prefab_type = PrefabUtility.GetPrefabType(child_obj);
if (cur_prefab_type == PrefabType.DisconnectedPrefabInstance)
{
PrefabUtility.ReconnectToLastPrefab(child_obj);
}
if (PrefabUtility.GetPrefabType(child_obj) == PrefabType.PrefabInstance)

if (PrefabUtility.GetPrefabType(child_obj) == PrefabType.PrefabInstance || cur_prefab_type == PrefabType.DisconnectedPrefabInstance)
{
UnityEngine.Object parentObject = PrefabUtility.GetPrefabParent(child_obj);
//替换预设
PrefabUtility.ReplacePrefab(child_obj, parentObject, ReplacePrefabOptions.ConnectToPrefab);
PrefabUtility.ReplacePrefab(child_obj, parentObject, ReplacePrefabOptions.Default);
//刷新
AssetDatabase.Refresh();
if (Configure.IsShowDialogWhenSaveLayout)
Expand Down
22 changes: 0 additions & 22 deletions Assets/UIEditor/Common/UISnapshotPoint.cs

This file was deleted.

12 changes: 0 additions & 12 deletions Assets/UIEditor/Common/UISnapshotPoint.cs.meta

This file was deleted.

2 changes: 1 addition & 1 deletion Assets/UIEditor/Editor/PrefabWin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ Item AddGUID (string guid, int index)
Item ent = new Item();
ent.prefab = go;
ent.guid = guid;
GeneratePreview(ent);
GeneratePreview(ent, false);
if (index < mItems.size) mItems.Insert(index, ent);
else mItems.Add(ent);
return ent;
Expand Down
2 changes: 1 addition & 1 deletion Assets/UIEditor/Editor/SceneEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ static void OnSceneGUI(SceneView sceneView)
// mouse_abs_pos = sceneView.camera.ScreenToWorldPoint(mouse_abs_pos);
// Debug.Log("mouse_abs_pos : " + mouse_abs_pos.ToString());
//}
if (Event.current != null && Event.current.button == 1 && Event.current.type <= EventType.mouseUp && Configure.IsShowSceneMenu)
if (Event.current != null && Event.current.button == 1 && Event.current.type == EventType.mouseUp && Configure.IsShowSceneMenu)
{
if (Selection.gameObjects == null || Selection.gameObjects.Length==0 || Selection.gameObjects[0].transform is RectTransform)
{
Expand Down

0 comments on commit acba315

Please sign in to comment.