Exemplo n.º 1
0
    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);
        }
    }
Exemplo n.º 2
0
    public override void OnInspectorGUI()
    {
        var transNameProperty = serializedObject.FindProperty("m_lstTransName");
        var transProperty     = serializedObject.FindProperty("m_lstTrans");

        EditorGUILayout.BeginHorizontal();
        EditorGUILayout.LabelField("HangPoint_Transform:");
        EditorGUILayout.EndHorizontal();
        int count = transNameProperty.arraySize;

        for (int i = 0; i < count; i++)
        {
            var prop    = transNameProperty.GetArrayElementAtIndex(i);
            var objProp = transProperty.GetArrayElementAtIndex(i);
            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.ObjectField(objProp, new GUIContent(prop.stringValue));
            EditorGUILayout.EndHorizontal();
        }

        HangPointView hangPoint = (HangPointView)target;

        EditorGUILayout.BeginHorizontal();
        EditorGUILayout.LabelField("HangPoint_Position:");
        EditorGUILayout.EndHorizontal();

        PrefabType prefabType = PrefabUtility.GetPrefabType(hangPoint.gameObject);
        bool       isPrefab   = prefabType == PrefabType.Prefab || prefabType == PrefabType.PrefabInstance;

        if (isPrefab != m_bIsPrefab)
        {
            LoadData();
        }
        m_bIsPrefab = isPrefab;

        if (m_cHangPointItem == null)
        {
            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("当前对象必须是一个预制体");
            EditorGUILayout.EndHorizontal();
        }
        else
        {
            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("path:" + m_cHangPointItem.path);
            EditorGUILayout.EndHorizontal();
            int dataCount = m_cHangPointItem.mLstData.Count;
            for (int i = 0; i < dataCount; i++)
            {
                HangPointData hangPointData = m_cHangPointItem.mLstData[i];
                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.LabelField("    " + hangPointData.name);
                EditorGUILayout.EndHorizontal();
                EditorGUILayout.BeginHorizontal();
                var pos = hangPointData.position;
                EditorGUILayout.Vector3Field("\tposition", new Vector3(pos.x.AsFloat(), pos.y.AsFloat(), pos.z.AsFloat()));
                EditorGUILayout.EndHorizontal();
                EditorGUILayout.BeginHorizontal();
                var forward = hangPointData.forward;
                EditorGUILayout.Vector3Field("\tforward", new Vector3(forward.x.AsFloat(), forward.y.AsFloat(), forward.z.AsFloat()));
                EditorGUILayout.EndHorizontal();
            }
        }
        if (GUILayout.Button("查找所有挂点"))
        {
            transNameProperty.ClearArray();
            transProperty.ClearArray();
            if (m_cHangPointItem != null)
            {
                m_cHangPointItem.mLstData.Clear();
            }
            Transform trans = hangPoint.transform;
            FindHangPoint(trans, trans, transNameProperty, transProperty, m_cHangPointItem);
            if (GUI.changed)
            {
                EditorUtility.SetDirty(hangPoint.gameObject);
            }
            serializedObject.ApplyModifiedProperties();
            SaveData();
            AssetDatabase.SaveAssets();
            AssetDatabase.Refresh();
        }
    }