//private ReorderableList EditorTestGOs; //private String ScriptPath = null; protected override void OnEnable() { // var tarGSR = serializedObject.targetObject as GameScrollRect_V2; // var t = typeof(GameScrollRect_V2); // var tmp = t.GetField("DataAndPosProviders", BindingFlags.NonPublic | BindingFlags.Instance); // var list = tmp.GetValue(tarGSR) as System.Collections.IList; // EditorTestGOs = new ReorderableList(list, typeof(System.Object)); // EditorTestGOs.onAddCallback = (l) => { Debug.LogError("add"); list.Add(new GameScrollRect_V2.DataPos()); }; // EditorTestGOs.onRemoveCallback = (l) => { Debug.LogError("remove"); list.RemoveAt(list.Count -1); }; if (textSytle == null) { //大红色字体,醒目 textSytle = new GUIStyle(EditorStyles.label); textSytle.normal.textColor = Color.red; textSytle.fontSize = 15; } if (warningTextSytle == null) { warningTextSytle = new GUIStyle(EditorStyles.label); warningTextSytle.normal.textColor = Color.yellow; warningTextSytle.fontSize = 15; } if (Script == null) { //脚本对应的同名文件,必须同名……否则找不到 var ss = AssetDatabase.FindAssets("t:MonoScript").Where(e => AssetDatabase.GUIDToAssetPath(e).EndsWith(typeof(GameScrollRect_V2).Name + ".cs")).First(); var path = AssetDatabase.GUIDToAssetPath(ss); Script = AssetDatabase.LoadAssetAtPath <MonoScript>(path); } SelfObj = target as GameScrollRect_V2; EmptyRoot_SP = serializedObject.FindProperty("EmptyRoot"); RealChildItem_SP = serializedObject.FindProperty("ChildItem"); FirstEdge_SP = serializedObject.FindProperty("FirstEdge"); SecondEdge_SP = serializedObject.FindProperty("SecondEdge"); LayoutMode_SP = serializedObject.FindProperty("LayoutMode"); GridConstraint_SP = serializedObject.FindProperty("GridConstraint"); ConstraintCount_SP = serializedObject.FindProperty("ConstraintCount"); CellSize_SP = serializedObject.FindProperty("CellSize"); SpacingSize_SP = serializedObject.FindProperty("SpacingSize"); ViewSizeMinExt_SP = serializedObject.FindProperty("ViewSizeMinExt"); ViewSizeMaxExt_SP = serializedObject.FindProperty("ViewSizeMaxExt"); base.OnEnable(); }
public static void Create_GameScrollRect_V2(MenuCommand menuCommand) { GameObject obj = new GameObject("ScrollView"); GameObjectUtility.SetParentAndAlign(obj, menuCommand.context as GameObject); Undo.RegisterCreatedObjectUndo(obj, "Create " + obj.name); Selection.activeObject = obj; obj.AddComponent <RectTransform>().sizeDelta = new Vector2(200.0f, 200.0f); GameObject viewPort = new GameObject("Viewport"); GameObjectUtility.SetParentAndAlign(viewPort, obj); Undo.RegisterCreatedObjectUndo(viewPort, "Create " + viewPort.name); Selection.activeObject = viewPort; RectTransform viewrect = viewPort.AddComponent <RectTransform>(); viewrect.sizeDelta = new Vector2(17.0f, 17.0f); viewPort.AddComponent <RectMask2D>(); GameObject empty = new GameObject("EmptyRecycle"); GameObjectUtility.SetParentAndAlign(empty, viewPort); Undo.RegisterCreatedObjectUndo(empty, "Create " + empty.name); Selection.activeObject = empty; RectTransform emptyrect = empty.AddComponent <RectTransform>(); emptyrect.sizeDelta = new Vector2(0f, 0f); GameObject Content = new GameObject("Content"); GameObjectUtility.SetParentAndAlign(Content, viewPort); Undo.RegisterCreatedObjectUndo(Content, "Create " + Content.name); Selection.activeObject = Content; RectTransform contentrect = Content.AddComponent <RectTransform>(); //GridLayoutGroup contentgrid= Content.AddComponent<GridLayoutGroup>(); contentrect.sizeDelta = new Vector2(0f, 300.0f); GameScrollRect_V2 scrollRect = obj.AddComponent <GameScrollRect_V2>(); scrollRect.content = contentrect; scrollRect.viewport = viewrect; scrollRect.EmptyRoot = emptyrect; }