public void Add(BlockDefinition def)
 {
     this.blockDefs.Add(def);
 }
 public void Remove(BlockDefinition def)
 {
     this.blockDefs.Remove(def);
 }
Ejemplo n.º 3
0
        /// <summary>
        /// 绘制Blocks页面
        /// </summary>
        /// <param name="data"></param>
        public void DrawBlocksPanel(BlockTerrainData data)
        {
            GUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();
            MyGUITools.SetBackgroundColor(Color.green);
            if (GUILayout.Button("Add New Block Definition"))
            {
                BlockDefinition newdef = new BlockDefinition();
                newdef.id = data.blockDefinitions.Count;
                data.blockDefinitions.Add(newdef);
            }
            MyGUITools.RestoreBackgroundColor();
            GUILayout.EndHorizontal();
            //            EditorGUI.indentLevel++;
            GUILayout.Label("Block Count(" + data.blockDefinitions.Count + ")");

            var contents = new List <GUIContent>();

            for (int i = 0; i < data.blockDefinitions.Count; i++)
            {
                var def = data.blockDefinitions[i];
                if (i == selectBlockDefIndex)
                {
                    EditorGUILayout.Space();
                    EditorGUILayout.BeginVertical((GUIStyle)"MeTransitionSelect", GUILayout.Height(200));
                    GUILayout.Toggle(true, string.Format("ID:{0},Name:{1}", def.id, def.name),
                                     (GUIStyle)"MeTransitionSelectHead", GUILayout.Height(30));
                    def = data.blockDefinitions[i];
                    if (def is SpriteBlockDefinition)
                    {
                        var sprDef = def as SpriteBlockDefinition;

                        sprDef.id   = EditorGUILayout.IntField("ID", sprDef.id);
                        sprDef.name = EditorGUILayout.TextField("Name", sprDef.name);
                        //贴图设置
                        EditorGUILayout.PrefixLabel("CreateMode");
                        blockCreateModeIndex = GUILayout.Toolbar(blockCreateModeIndex, blockCreateModes);
                        if (blockCreateModeIndex == 0)
                        {
                            var temp = EditorGUILayout.ObjectField("All Face", sprDef.top, typeof(Sprite), false) as Sprite;
                            if (temp != null && temp != sprDef.top)
                            {
                                sprDef.top    = temp;
                                sprDef.bottom = sprDef.front = sprDef.back = sprDef.left = sprDef.right = sprDef.top;
                            }
                        }
                        else if (blockCreateModeIndex == 1)
                        {
                            sprDef.top = EditorGUILayout.ObjectField("Top Face", sprDef.top, typeof(Sprite), false) as Sprite;
                            var temp =
                                EditorGUILayout.ObjectField("Other Face", sprDef.bottom, typeof(Sprite), false) as Sprite;
                            if (temp != null && temp != sprDef.bottom)
                            {
                                sprDef.bottom = temp;
                                sprDef.front  = sprDef.back = sprDef.left = sprDef.right = sprDef.bottom;
                            }
                        }
                        else if (blockCreateModeIndex == 2)
                        {
                            sprDef.top    = EditorGUILayout.ObjectField("Top Face", sprDef.top, typeof(Sprite), false) as Sprite;
                            sprDef.bottom =
                                EditorGUILayout.ObjectField("Bottom Face", sprDef.bottom, typeof(Sprite), false) as Sprite;
                            var temp =
                                EditorGUILayout.ObjectField("Other Face", sprDef.front, typeof(Sprite), false) as Sprite;
                            if (temp != null && temp != sprDef.front)
                            {
                                sprDef.front = temp;
                                sprDef.back  = sprDef.left = sprDef.right = sprDef.front;
                            }
                        }
                        else if (blockCreateModeIndex == 3)
                        {
                            sprDef.top    = EditorGUILayout.ObjectField("Top Face", sprDef.top, typeof(Sprite), false) as Sprite;
                            sprDef.bottom =
                                EditorGUILayout.ObjectField("Bottom Face", sprDef.bottom, typeof(Sprite), false) as Sprite;
                            sprDef.front =
                                EditorGUILayout.ObjectField("Front Face", sprDef.front, typeof(Sprite), false) as Sprite;
                            sprDef.back =
                                EditorGUILayout.ObjectField("Back Face", sprDef.back, typeof(Sprite), false) as Sprite;
                            sprDef.left =
                                EditorGUILayout.ObjectField("Left Face", sprDef.left, typeof(Sprite), false) as Sprite;
                            sprDef.right =
                                EditorGUILayout.ObjectField("Right Face", sprDef.right, typeof(Sprite), false) as Sprite;
                        }
                    }
                    EditorGUILayout.BeginHorizontal();
                    GUILayout.FlexibleSpace();
                    MyGUITools.SetBackgroundColor(Color.red);
                    if (GUILayout.Button("Del", GUILayout.MinWidth(80)))
                    {
                        data.blockDefinitions.RemoveAt(selectBlockDefIndex);
                    }
                    MyGUITools.RestoreBackgroundColor();
                    EditorGUILayout.EndHorizontal();
                    EditorGUILayout.EndVertical();
                    EditorGUILayout.Space();
                }
                else
                {
                    var flag = GUILayout.Toggle(false, string.Format("ID:{0},Name:{1}", def.id, def.name),
                                                (GUIStyle)"OL Title");
                    if (flag == true)
                    {
                        selectBlockDefIndex = i;
                    }
                }
            }
        }