private HUDComponentDrawer GetDrawer(HUDComponent com)
        {
            HUDComponentDrawer drawer = null;

            if (!drawers.TryGetValue(com, out drawer))
            {
                if (com is HUDSprite)
                {
                    drawer = new HUDSpriteDrawer();
                    drawer.Init(new SerializedObject(com as HUDSprite));
                    drawers.Add(com, drawer);
                }
                else if (com is HUDText)
                {
                    drawer = new HUDTextDrawer();
                    drawer.Init(new SerializedObject(com as HUDText));
                    drawers.Add(com, drawer);
                }
                else if (com is HUDProgressBar)
                {
                    drawer = new HUDProgressBarDrawer();
                    drawer.Init(new SerializedObject(com as HUDProgressBar));
                    drawers.Add(com, drawer);
                }
            }

            return(drawer);
        }
        private void HandleDelete()
        {
            if (delete_component == null)
            {
                return;
            }

            var index = System.Array.IndexOf(edit_trans.hud_components, delete_component);

            delete_component.UnAttach();
            OnRemoveComponent(delete_component);
            Object.DestroyImmediate(delete_component);
            List <string>       names = new List <string>();
            List <HUDComponent> coms  = new List <HUDComponent>();

            for (int i = 0; i < edit_trans.hud_components.Length; ++i)
            {
                var c = edit_trans.hud_components[i];
                if (c != null)
                {
                    coms.Add(c);
                    names.Add(edit_trans.field_names[i]);
                }
            }

            edit_trans.field_names    = names.ToArray();
            edit_trans.hud_components = coms.ToArray();
            delete_component          = null;
            serializedObject.ApplyModifiedPropertiesWithoutUndo();
        }
        private void AddComponent(string name, HUDComponent component)
        {
            fieldnames_serialized.arraySize = fieldnames_serialized.arraySize + 1;
            components_serialized.arraySize = components_serialized.arraySize + 1;
            int index = fieldnames_serialized.arraySize - 1;

            SetFieldNames(index, name);
            SetComponent(index, component);
            serializedObject.ApplyModifiedProperties();
        }
        private void OnRemoveComponent(HUDComponent component)
        {
            if (component is HUDProgressBar)
            {
                SerializedObject obj = new SerializedObject(component);
                var bg  = obj.FindProperty("background").objectReferenceValue;
                var bar = obj.FindProperty("progressbar").objectReferenceValue;

                if (bg != null)
                {
                    Object.DestroyImmediate(bg);
                }

                if (bar != null)
                {
                    Object.DestroyImmediate(bar);
                }
            }
        }
        private bool DrawAComponents(int index, HUDComponent component)
        {
            bool l_state = component.enabled;

            component.enabled = EditorGUILayout.Toggle("显示/隐藏", component.enabled);
            if (l_state != component.enabled)
            {
                component.OnValidate();
            }

            bool is_expand = component == expand_component;
            var  old_name  = GetFieldName(index);
            var  new_name  = EditorGUILayout.TextField(old_name);

            if (new_name != old_name)
            {
                SetFieldNames(index, new_name);
            }
            string content = " type: " + component.GetType().Name;

            is_expand = EditorGUILayout.Foldout(is_expand, content, true);
            if (is_expand)
            {
                expand_component = component;
                EditorGUI.indentLevel++;
                var drawer = GetDrawer(component);
                if (drawer.Render())
                {
                }
                EditorGUI.indentLevel--;
            }
            else if (component == expand_component)
            {
                expand_component = null;
            }

            if (GUILayout.Button("delete"))
            {
                delete_component = component;
                return(true);
            }
            return(false);
        }
Example #6
0
 protected void AttachSubComponent(HUDComponent component)
 {
     component.Attach(target_group);
 }
 private void SetComponent(int index, HUDComponent component)
 {
     components_serialized.FindPropertyRelative(string.Format("Array.data[{0}]", index)).objectReferenceValue = component;
 }