public static void ResetAllHangPoint() { HangPointSet hangPointSet = new HangPointSet(); var guids = AssetDatabase.FindAssets("t:GameObject", new string[] { "Assets/ResourceEx/Prefab" }); int count = guids.Length; for (int i = 0; i < count; i++) { EditorUtility.DisplayProgressBar("更新挂点数据", "正在更新挂点数据(" + i + "/" + count + ")", i / (float)count); string goPath = AssetDatabase.GUIDToAssetPath(guids[i]); GameObject gameObject = AssetDatabase.LoadAssetAtPath <GameObject>(goPath); HangPointView hangPointView = gameObject.GetComponent <HangPointView>(); if (hangPointView != null) { HangPointItem hangPointItem = new HangPointItem(); hangPointItem.path = goPath; FindHangPoint(gameObject.transform, gameObject.transform, null, null, hangPointItem); hangPointSet.mLstHangPointItem.Add(hangPointItem); } } NEUtil.SerializerObject(HangPointCfgSys.HangPointPath, hangPointSet); EditorUtility.ClearProgressBar(); AssetDatabase.SaveAssets(); AssetDatabase.Refresh(); }
private void LoadData() { TextAsset textAsset = AssetDatabase.LoadAssetAtPath <TextAsset>(HangPointCfgSys.HangPointPath); m_cHangPointSet = null; if (textAsset != null) { var bytes = textAsset.bytes; m_cHangPointSet = NEUtil.DeSerializerObjectFromBuff(bytes, typeof(HangPointSet)) as HangPointSet; } if (m_cHangPointSet == null) { m_cHangPointSet = new HangPointSet(); } HangPointView hangPoint = (HangPointView)target; PrefabType prefabType = PrefabUtility.GetPrefabType(hangPoint.gameObject); Debug.Log(prefabType); m_bIsPrefab = (prefabType == PrefabType.Prefab || prefabType == PrefabType.PrefabInstance); if (m_bIsPrefab) { UnityEngine.Object prefab = null; if (prefabType == PrefabType.PrefabInstance) { prefab = PrefabUtility.GetPrefabParent(hangPoint.gameObject); } else { prefab = hangPoint.gameObject; } Debug.Log(prefab); if (m_cHangPointSet != null && prefab != null) { string path = AssetDatabase.GetAssetPath(prefab); Debug.Log("path:" + path); m_cHangPointItem = m_cHangPointSet.GetHangPointItem(path); if (m_cHangPointItem == null) { m_cHangPointItem = new HangPointItem(); m_cHangPointItem.path = path; m_cHangPointSet.mLstHangPointItem.Add(m_cHangPointItem); } } } }
private static void FindHangPoint(Transform root, Transform trans, SerializedProperty transNameProperty, SerializedProperty transProperty, HangPointItem hangPointItem) { int count = trans.childCount; for (int i = 0; i < count; i++) { var child = trans.GetChild(i); if (child.tag == "HangPoint_Transform" && transNameProperty != null && transProperty != null) { transNameProperty.InsertArrayElementAtIndex(transNameProperty.arraySize); transProperty.InsertArrayElementAtIndex(transProperty.arraySize); var prop = transNameProperty.GetArrayElementAtIndex(transNameProperty.arraySize - 1); var objPorp = transProperty.GetArrayElementAtIndex(transProperty.arraySize - 1); prop.stringValue = child.name; objPorp.objectReferenceValue = child; } else if (child.tag == "HangPoint_Position" && hangPointItem != null) { HangPointData hangPointData = new HangPointData(); hangPointData.name = child.name; var pos = child.position; var localPos = root.InverseTransformPoint(pos); hangPointData.position = new TSVector(FP.FromFloat(localPos.x), FP.FromFloat(localPos.y), FP.FromFloat(localPos.z)); var forward = child.forward; var localForward = root.InverseTransformDirection(forward); hangPointData.forward = new TSVector(FP.FromFloat(localForward.x), FP.FromFloat(localForward.y), FP.FromFloat(localForward.z)); hangPointItem.mLstData.Add(hangPointData); } FindHangPoint(root, child, transNameProperty, transProperty, hangPointItem); } }