少年修仙传客户端代码仓库
hch
2025-06-12 204ef05a831c9484e2abc561d27ecbff7c797453
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
//
// EditorBase.cs
//
// Dynamic Shadow Projector
//
// Copyright 2015 NYAHOON GAMES PTE. LTD. All Rights Reserved.
//
 
using UnityEngine;
using UnityEditor;
 
namespace DynamicShadowProjector.Editor {
    public class EditorBase : UnityEditor.Editor {
        protected static GUIContent[] s_textureSizeDisplayOption = new GUIContent[] {new GUIContent("16"), new GUIContent("32"), new GUIContent("64"), new GUIContent("128"), new GUIContent("256"), new GUIContent("512")};
        protected static int[] s_textureSizeOption = new int[] {16, 32, 64, 128, 256, 512};
        protected static GUIContent[] s_blurLevelDisplayOption = new GUIContent[] {new GUIContent("0"), new GUIContent("1"), new GUIContent("2 (Not Recommended)"), new GUIContent("3 (Not Recommended)")};
        protected static int[] s_blurLevelOption = new int[] {0, 1, 2, 3};
        GUIStyle m_richTextStyle;
        protected GUIStyle richTextStyle
        {
            get {
                if (m_richTextStyle == null) {
                    m_richTextStyle = new GUIStyle();
                    m_richTextStyle.richText = true;
                    m_richTextStyle.wordWrap = true;
                    m_richTextStyle.alignment = TextAnchor.MiddleCenter;
                }
                return m_richTextStyle;
            }
        }
        protected static Material FindMaterial(string shaderName)
        {
            Shader shader = Shader.Find(shaderName);
            if (shader == null) {
                Debug.LogError("Cannot find a shader named " + shaderName);
                return null;
            }
            string path = AssetDatabase.GetAssetPath(shader);
            if (path == null || path.Length < 6) {
                return null;
            }
            path = path.Substring(0, path.Length - 6); // remove "shader" extension
            path += "mat"; // add "mat" extension
            return AssetDatabase.LoadAssetAtPath(path, typeof(Material)) as Material;
        }
        public static void ClearMaterialProperties(Material mat)
        {
            if (mat == null) {
                return;
            }
            SerializedObject serialize = new SerializedObject(mat);
            SerializedProperty prop = serialize.FindProperty("m_SavedProperties");
            SerializedProperty propChild = prop.FindPropertyRelative("m_TexEnvs");
            bool modified = false;
            if (propChild != null && propChild.arraySize != 0) {
                propChild.arraySize = 0;
                modified = true;
            }
            propChild = prop.FindPropertyRelative("m_Floats");
            if (propChild != null && propChild.arraySize != 0) {
                propChild.arraySize = 0;
                modified = true;
            }
            propChild = prop.FindPropertyRelative("m_Colors");
            if (propChild != null && propChild.arraySize != 0) {
                propChild.arraySize = 0;
                modified = true;
            }
            if (modified) {
                serialize.ApplyModifiedProperties();
                EditorUtility.SetDirty(mat);
            }
        }
        private static bool RemoveUnuserMaterialPropertyData(Material mat, SerializedProperty prop, string forceRemoveProperty)
        {
            int dst = 0;
            for (int i = 0; i < prop.arraySize; ++i) {
                SerializedProperty elem = prop.GetArrayElementAtIndex(i);
                SerializedProperty firstProp = elem.FindPropertyRelative("first");
                if (firstProp != null) {
                    SerializedProperty nameProp = firstProp.FindPropertyRelative("name");
                    if (nameProp != null) {
                        string name = nameProp.stringValue;
                        if (!mat.HasProperty(name) || ((!string.IsNullOrEmpty(forceRemoveProperty) && name == forceRemoveProperty))) {
                            continue;
                        }
                    }
                }
                if (dst != i) {
                    prop.MoveArrayElement(i, dst);
                }
                ++dst;
            }
            if (dst != prop.arraySize) {
                prop.arraySize = dst;
                return true;
            }
            return false;
        }
        public static void RemoveUnusedMaterialProperties(Material mat, bool isDynamic = true)
        {
            SerializedObject serialize = new SerializedObject(mat);
            SerializedProperty prop = serialize.FindProperty("m_SavedProperties");
            SerializedProperty propChild = prop.FindPropertyRelative("m_TexEnvs");
            bool modified = false;
            if (propChild != null && propChild.arraySize != 0) {
                if (RemoveUnuserMaterialPropertyData(mat, propChild, isDynamic ? "_ShadowTex" : null)) {
                    modified = true;
                }
            }
            propChild = prop.FindPropertyRelative("m_Floats");
            if (propChild != null && propChild.arraySize != 0) {
                if (RemoveUnuserMaterialPropertyData(mat, propChild, isDynamic ? "_DSPMipLevel" : null)) {
                    modified = true;
                }
            }
            propChild = prop.FindPropertyRelative("m_Colors");
            if (propChild != null && propChild.arraySize != 0) {
                if (RemoveUnuserMaterialPropertyData(mat, propChild, null)) {
                    modified = true;
                }
            }
            if (modified) {
                serialize.ApplyModifiedProperties();
                EditorUtility.SetDirty(mat);
            }
        }
    }
}